libpurple/purple-client-example.c

Wed, 30 Aug 2017 20:33:01 -0300

author
dx <dx@dxzone.com.ar>
date
Wed, 30 Aug 2017 20:33:01 -0300
changeset 38648
9ff9acf9fa14
parent 38057
41f47eb1aa19
permissions
-rw-r--r--

facebook: Fix "Failed to read thrift" with unknown fields in /t_p payload

>Login error: Failed to read thrift: facebook-api.c:1815
>fb_api_cb_publish_pt: assertion 'FALSE' failed

38057
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
1 /*
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
2 * purple
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
3 *
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
6 * source distribution.
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
7 *
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
8 * This program is free software; you can redistribute it and/or modify
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
9 * it under the terms of the GNU General Public License as published by
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
11 * (at your option) any later version.
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
12 *
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
13 * This program is distributed in the hope that it will be useful,
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
16 * GNU General Public License for more details.
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
17 *
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
18 * You should have received a copy of the GNU General Public License
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
19 * along with this program; if not, write to the Free Software
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
21 *
41f47eb1aa19 Add our license spiel to a bunch of files
Gary Kramlich <grim@reaperworld.com>
parents: 22582
diff changeset
22 */
22582
838faa931042 Avoid a compile warning when building with NetworkManager support because
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15987
diff changeset
23 #ifndef DBUS_API_SUBJECT_TO_CHANGE
11241
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
24 #define DBUS_API_SUBJECT_TO_CHANGE
22582
838faa931042 Avoid a compile warning when building with NetworkManager support because
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 15987
diff changeset
25 #endif
11241
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
26
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
27 #include <stdio.h>
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
28 #include <stdlib.h>
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
29
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
30 #include "purple-client.h"
11241
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
31
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
32 /*
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
33 This example demonstrates how to use libpurple-client to communicate
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
34 with purple. The names and signatures of functions provided by
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
35 libpurple-client are the same as those in purple. However, all
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
36 structures (such as PurpleAccount) are opaque, that is, you can only
11241
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
37 use pointer to them. In fact, these pointers DO NOT actually point
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
38 to anything, they are just integer identifiers of assigned to these
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
39 structures by purple. So NEVER try to dereference these pointers.
11241
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
40 Integer ids as disguised as pointers to provide type checking and
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
41 prevent mistakes such as passing an id of PurpleAccount when an id of
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
42 PurpleBuddy is expected. According to glib manual, this technique is
11241
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
43 portable.
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
44 */
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
45
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
46 int main (int argc, char **argv)
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
47 {
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
48 GList *alist, *node;
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
49
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
50 purple_init();
11277
ab3c0b6c5ca5 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents: 11241
diff changeset
51
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
52 alist = purple_accounts_get_all();
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
53 for (node = alist; node != NULL; node = node->next)
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
54 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
55 PurpleAccount *account = (PurpleAccount*) node->data;
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
56 char *name = purple_account_get_username(account);
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
57 g_print("Name: %s\n", name);
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
58 g_free(name);
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
59 }
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
60 g_list_free(alist);
11277
ab3c0b6c5ca5 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents: 11241
diff changeset
61
14097
0c340861ab79 [gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents: 11903
diff changeset
62 return 0;
11241
f62a71823fc3 [gaim-migrate @ 13404]
Piotr Zielinski <zielaj@users.sourceforge.net>
parents:
diff changeset
63 }

mercurial