| |
1 /* purple |
| |
2 * |
| |
3 * Purple is the legal property of its developers, whose names are too numerous |
| |
4 * to list here. Please refer to the COPYRIGHT file distributed with this |
| |
5 * source distribution. |
| |
6 * |
| |
7 * This program is free software; you can redistribute it and/or modify |
| |
8 * it under the terms of the GNU General Public License as published by |
| |
9 * the Free Software Foundation; either version 2 of the License, or |
| |
10 * (at your option) any later version. |
| |
11 * |
| |
12 * This program is distributed in the hope that it will be useful, |
| |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| |
15 * GNU General Public License for more details. |
| |
16 * |
| |
17 * You should have received a copy of the GNU General Public License |
| |
18 * along with this program; if not, write to the Free Software |
| |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| |
20 */ |
| |
21 |
| |
22 #ifndef _FACEBOOK_API_H_ |
| |
23 #define _FACEBOOK_API_H_ |
| |
24 |
| |
25 #include "internal.h" |
| |
26 |
| |
27 #include <glib.h> |
| |
28 |
| |
29 #include "http.h" |
| |
30 #include "id.h" |
| |
31 #include "mqtt.h" |
| |
32 |
| |
33 #define FB_API_HOST "https://api.facebook.com" |
| |
34 #define FB_API_BHOST "https://b-api.facebook.com" |
| |
35 #define FB_API_GHOST "https://graph.facebook.com" |
| |
36 #define FB_API_AGENT "Facebook App / " PACKAGE " / " VERSION |
| |
37 #define FB_API_KEY "256002347743983" |
| |
38 #define FB_API_SECRET "374e60f8b9bb6b8cbb30f78030438895" |
| |
39 |
| |
40 #define FB_API_URL_AUTH FB_API_BHOST "/method/auth.login" |
| |
41 #define FB_API_URL_FQL FB_API_GHOST "/fql" |
| |
42 #define FB_API_URL_GQL FB_API_GHOST "/graphql" |
| |
43 #define FB_API_URL_PARTS FB_API_GHOST "/participants" |
| |
44 #define FB_API_URL_THRDS FB_API_GHOST "/me/threads" |
| |
45 #define FB_API_URL_TOPIC FB_API_HOST "/method/messaging.setthreadname" |
| |
46 |
| |
47 #define FB_API_QRYID_CONTACTS "10153122424521729" |
| |
48 |
| |
49 #define FB_TYPE_API (fb_api_get_type()) |
| |
50 #define FB_API(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), FB_TYPE_API, FbApi)) |
| |
51 #define FB_API(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), FB_TYPE_API, FbApi)) |
| |
52 #define FB_API_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), FB_TYPE_API, FbApiClass)) |
| |
53 #define FB_IS_API(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), FB_TYPE_API)) |
| |
54 #define FB_IS_API_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), FB_TYPE_API)) |
| |
55 #define FB_API_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), FB_TYPE_API, FbApiClass)) |
| |
56 |
| |
57 #define FB_API_MSGID(m, i) ((guint64) ( \ |
| |
58 (((guint32) i) & 0x3FFFFF) | \ |
| |
59 (((guint64) m) << 22) \ |
| |
60 )) |
| |
61 |
| |
62 #define FB_API_ERROR_CHK(a, e, c) \ |
| |
63 G_STMT_START { \ |
| |
64 if (G_UNLIKELY((e) != NULL)) { \ |
| |
65 g_signal_emit_by_name(a, "error", e); \ |
| |
66 g_error_free(e); \ |
| |
67 {c;} \ |
| |
68 } \ |
| |
69 } G_STMT_END |
| |
70 |
| |
71 #define FB_API_ERROR fb_api_error_quark() |
| |
72 |
| |
73 typedef enum _FbApiError FbApiError; |
| |
74 typedef struct _FbApi FbApi; |
| |
75 typedef struct _FbApiClass FbApiClass; |
| |
76 typedef struct _FbApiPrivate FbApiPrivate; |
| |
77 typedef struct _FbApiMessage FbApiMessage; |
| |
78 typedef struct _FbApiPresence FbApiPresence; |
| |
79 typedef struct _FbApiThread FbApiThread; |
| |
80 typedef struct _FbApiTyping FbApiTyping; |
| |
81 typedef struct _FbApiUser FbApiUser; |
| |
82 typedef struct _FbApiHttpInfo FbApiHttpInfo; |
| |
83 |
| |
84 |
| |
85 enum _FbApiError |
| |
86 { |
| |
87 FB_API_ERROR_GENERAL |
| |
88 }; |
| |
89 |
| |
90 struct _FbApi |
| |
91 { |
| |
92 GObject parent; |
| |
93 FbApiPrivate *priv; |
| |
94 }; |
| |
95 |
| |
96 struct _FbApiClass |
| |
97 { |
| |
98 GObjectClass parent_class; |
| |
99 }; |
| |
100 |
| |
101 struct _FbApiMessage |
| |
102 { |
| |
103 FbId uid; |
| |
104 FbId tid; |
| |
105 const gchar *text; |
| |
106 }; |
| |
107 |
| |
108 struct _FbApiPresence |
| |
109 { |
| |
110 FbId uid; |
| |
111 gboolean active; |
| |
112 }; |
| |
113 |
| |
114 struct _FbApiThread |
| |
115 { |
| |
116 FbId tid; |
| |
117 const gchar *topic; |
| |
118 GSList *users; |
| |
119 }; |
| |
120 |
| |
121 struct _FbApiTyping |
| |
122 { |
| |
123 FbId uid; |
| |
124 gboolean state; |
| |
125 }; |
| |
126 |
| |
127 struct _FbApiUser |
| |
128 { |
| |
129 FbId uid; |
| |
130 const gchar *name; |
| |
131 }; |
| |
132 |
| |
133 struct _FbApiHttpInfo |
| |
134 { |
| |
135 PurpleHttpCallback callback; |
| |
136 const gchar *klass; |
| |
137 const gchar *name; |
| |
138 const gchar *method; |
| |
139 }; |
| |
140 |
| |
141 |
| |
142 GType |
| |
143 fb_api_get_type(void); |
| |
144 |
| |
145 GQuark |
| |
146 fb_api_error_quark(void); |
| |
147 |
| |
148 FbApi * |
| |
149 fb_api_new(PurpleConnection *gc); |
| |
150 |
| |
151 void |
| |
152 fb_api_rehash(FbApi *api); |
| |
153 |
| |
154 void |
| |
155 fb_api_free(FbApi *api); |
| |
156 |
| |
157 void |
| |
158 fb_api_error(FbApi *api, FbApiError err, const gchar *fmt, ...) |
| |
159 G_GNUC_PRINTF(3, 4); |
| |
160 |
| |
161 void |
| |
162 fb_api_auth(FbApi *api, const gchar *user, const gchar *pass); |
| |
163 |
| |
164 void |
| |
165 fb_api_contacts(FbApi *api); |
| |
166 |
| |
167 void |
| |
168 fb_api_connect(FbApi *api); |
| |
169 |
| |
170 void |
| |
171 fb_api_disconnect(FbApi *api); |
| |
172 |
| |
173 void |
| |
174 fb_api_message(FbApi *api, FbId id, gboolean thread, const gchar *msg); |
| |
175 |
| |
176 void |
| |
177 fb_api_publish(FbApi *api, const gchar *topic, const gchar *fmt, ...) |
| |
178 G_GNUC_PRINTF(3, 4); |
| |
179 |
| |
180 void |
| |
181 fb_api_thread_create(FbApi *api, GSList *uids); |
| |
182 |
| |
183 void |
| |
184 fb_api_thread_info(FbApi *api, FbId tid); |
| |
185 |
| |
186 void |
| |
187 fb_api_thread_invite(FbApi *api, FbId tid, FbId uid); |
| |
188 |
| |
189 void |
| |
190 fb_api_thread_list(FbApi *api, guint limit); |
| |
191 |
| |
192 void |
| |
193 fb_api_thread_topic(FbApi *api, FbId tid, const gchar *topic); |
| |
194 |
| |
195 void |
| |
196 fb_api_typing(FbApi *api, FbId uid, gboolean state); |
| |
197 |
| |
198 #endif /* _FACEBOOK_API_H_ */ |