| 165 gklass->set_property = fb_api_set_property; |
165 gklass->set_property = fb_api_set_property; |
| 166 gklass->get_property = fb_api_get_property; |
166 gklass->get_property = fb_api_get_property; |
| 167 gklass->dispose = fb_api_dispose; |
167 gklass->dispose = fb_api_dispose; |
| 168 g_type_class_add_private(klass, sizeof (FbApiPrivate)); |
168 g_type_class_add_private(klass, sizeof (FbApiPrivate)); |
| 169 |
169 |
| |
170 /** |
| |
171 * FbApi:cid: |
| |
172 * |
| |
173 * The client identifier for MQTT. This value should be saved |
| |
174 * and loaded for persistence. |
| |
175 */ |
| 170 props[PROP_CID] = g_param_spec_string( |
176 props[PROP_CID] = g_param_spec_string( |
| 171 "cid", |
177 "cid", |
| 172 "Client ID", |
178 "Client ID", |
| 173 "Client identifier for MQTT", |
179 "Client identifier for MQTT", |
| 174 NULL, |
180 NULL, |
| 175 G_PARAM_READWRITE); |
181 G_PARAM_READWRITE); |
| |
182 |
| |
183 /** |
| |
184 * FbApi:did: |
| |
185 * |
| |
186 * The device identifier for the MQTT message queue. This value |
| |
187 * should be saved and loaded for persistence. |
| |
188 */ |
| 176 props[PROP_DID] = g_param_spec_string( |
189 props[PROP_DID] = g_param_spec_string( |
| 177 "did", |
190 "did", |
| 178 "Device ID", |
191 "Device ID", |
| 179 "Device identifier", |
192 "Device identifier for the MQTT message queue", |
| 180 NULL, |
193 NULL, |
| 181 G_PARAM_READWRITE); |
194 G_PARAM_READWRITE); |
| |
195 |
| |
196 /** |
| |
197 * FbApi:mid: |
| |
198 * |
| |
199 * The MQTT identifier. This value should be saved and loaded |
| |
200 * for persistence. |
| |
201 */ |
| 182 props[PROP_MID] = g_param_spec_uint64( |
202 props[PROP_MID] = g_param_spec_uint64( |
| 183 "mid", |
203 "mid", |
| 184 "MQTT ID", |
204 "MQTT ID", |
| 185 "MQTT identifier for the MQTT queuer", |
205 "MQTT identifier", |
| 186 0, G_MAXUINT64, 0, |
206 0, G_MAXUINT64, 0, |
| 187 G_PARAM_READWRITE); |
207 G_PARAM_READWRITE); |
| |
208 |
| |
209 /** |
| |
210 * FbApi:stoken: |
| |
211 * |
| |
212 * The synchronization token for the MQTT message queue. This |
| |
213 * value should be saved and loaded for persistence. |
| |
214 */ |
| 188 props[PROP_STOKEN] = g_param_spec_string( |
215 props[PROP_STOKEN] = g_param_spec_string( |
| 189 "stoken", |
216 "stoken", |
| 190 "Sync Token", |
217 "Sync Token", |
| 191 "Synchronization token for the MQTT queue", |
218 "Synchronization token for the MQTT message queue", |
| 192 NULL, |
219 NULL, |
| 193 G_PARAM_READWRITE); |
220 G_PARAM_READWRITE); |
| |
221 |
| |
222 /** |
| |
223 * FbApi:token: |
| |
224 * |
| |
225 * The access token for authentication. This value should be |
| |
226 * saved and loaded for persistence. |
| |
227 */ |
| 194 props[PROP_TOKEN] = g_param_spec_string( |
228 props[PROP_TOKEN] = g_param_spec_string( |
| 195 "token", |
229 "token", |
| 196 "Access Token", |
230 "Access Token", |
| 197 "Access token from authenticating", |
231 "Access token for authentication", |
| 198 NULL, |
232 NULL, |
| 199 G_PARAM_READWRITE); |
233 G_PARAM_READWRITE); |
| |
234 |
| |
235 /** |
| |
236 * FbApi:uid: |
| |
237 * |
| |
238 * The #FbId of the user of the #FbApi. |
| |
239 */ |
| 200 props[PROP_UID] = g_param_spec_int64( |
240 props[PROP_UID] = g_param_spec_int64( |
| 201 "uid", |
241 "uid", |
| 202 "User ID", |
242 "User ID", |
| 203 "User identifier", |
243 "User identifier", |
| 204 0, G_MAXINT64, 0, |
244 0, G_MAXINT64, 0, |
| 205 G_PARAM_READWRITE); |
245 G_PARAM_READWRITE); |
| 206 g_object_class_install_properties(gklass, PROP_N, props); |
246 g_object_class_install_properties(gklass, PROP_N, props); |
| 207 |
247 |
| |
248 /** |
| |
249 * FbApi::auth: |
| |
250 * @api: The #FbApi. |
| |
251 * |
| |
252 * Emitted upon the successful completion of the authentication |
| |
253 * process. This is emitted as a result of #fb_api_auth(). |
| |
254 */ |
| 208 g_signal_new("auth", |
255 g_signal_new("auth", |
| 209 G_TYPE_FROM_CLASS(klass), |
256 G_TYPE_FROM_CLASS(klass), |
| 210 G_SIGNAL_ACTION, |
257 G_SIGNAL_ACTION, |
| 211 0, |
258 0, |
| 212 NULL, NULL, |
259 NULL, NULL, |
| 213 fb_marshal_VOID__VOID, |
260 fb_marshal_VOID__VOID, |
| 214 G_TYPE_NONE, |
261 G_TYPE_NONE, |
| 215 0); |
262 0); |
| |
263 |
| |
264 /** |
| |
265 * FbApi::connect: |
| |
266 * @api: The #FbApi. |
| |
267 * |
| |
268 * Emitted upon the successful completion of the connection |
| |
269 * process. This is emitted as a result of #fb_api_connect(). |
| |
270 */ |
| 216 g_signal_new("connect", |
271 g_signal_new("connect", |
| 217 G_TYPE_FROM_CLASS(klass), |
272 G_TYPE_FROM_CLASS(klass), |
| 218 G_SIGNAL_ACTION, |
273 G_SIGNAL_ACTION, |
| 219 0, |
274 0, |
| 220 NULL, NULL, |
275 NULL, NULL, |
| 221 fb_marshal_VOID__VOID, |
276 fb_marshal_VOID__VOID, |
| 222 G_TYPE_NONE, |
277 G_TYPE_NONE, |
| 223 0); |
278 0); |
| |
279 |
| |
280 /** |
| |
281 * FbApi::contact: |
| |
282 * @api: The #FbApi. |
| |
283 * @user: The #FbApiUser. |
| |
284 * |
| |
285 * Emitted upon the successful reply of a contact request. This |
| |
286 * is emitted as a result of #fb_api_contact(). |
| |
287 */ |
| 224 g_signal_new("contact", |
288 g_signal_new("contact", |
| 225 G_TYPE_FROM_CLASS(klass), |
289 G_TYPE_FROM_CLASS(klass), |
| 226 G_SIGNAL_ACTION, |
290 G_SIGNAL_ACTION, |
| 227 0, |
291 0, |
| 228 NULL, NULL, |
292 NULL, NULL, |
| 229 fb_marshal_VOID__POINTER, |
293 fb_marshal_VOID__POINTER, |
| 230 G_TYPE_NONE, |
294 G_TYPE_NONE, |
| 231 1, G_TYPE_POINTER); |
295 1, G_TYPE_POINTER); |
| |
296 |
| |
297 /** |
| |
298 * FbApi::contacts: |
| |
299 * @api: The #FbApi. |
| |
300 * @users: The #GSList of #FbApiUser's. |
| |
301 * @complete: #TRUE if the list is fetched, otherwise #FALSE. |
| |
302 * |
| |
303 * Emitted upon the successful reply of a contacts request. |
| |
304 * This is emitted as a result of #fb_api_contacts(). This can |
| |
305 * be emitted multiple times before the entire contacts list |
| |
306 * has been fetched. Use @complete for detecting the completion |
| |
307 * status of the list fetch. |
| |
308 */ |
| 232 g_signal_new("contacts", |
309 g_signal_new("contacts", |
| 233 G_TYPE_FROM_CLASS(klass), |
310 G_TYPE_FROM_CLASS(klass), |
| 234 G_SIGNAL_ACTION, |
311 G_SIGNAL_ACTION, |
| 235 0, |
312 0, |
| 236 NULL, NULL, |
313 NULL, NULL, |
| 237 fb_marshal_VOID__POINTER_BOOLEAN, |
314 fb_marshal_VOID__POINTER_BOOLEAN, |
| 238 G_TYPE_NONE, |
315 G_TYPE_NONE, |
| 239 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
316 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
| |
317 |
| |
318 /** |
| |
319 * FbApi::error: |
| |
320 * @api: The #FbApi. |
| |
321 * @error: The #GError. |
| |
322 * |
| |
323 * Emitted whenever an error is hit within the #FbApi. This |
| |
324 * should disconnect #FbApi with #fb_api_disconnect(). |
| |
325 */ |
| 240 g_signal_new("error", |
326 g_signal_new("error", |
| 241 G_TYPE_FROM_CLASS(klass), |
327 G_TYPE_FROM_CLASS(klass), |
| 242 G_SIGNAL_ACTION, |
328 G_SIGNAL_ACTION, |
| 243 0, |
329 0, |
| 244 NULL, NULL, |
330 NULL, NULL, |
| 245 fb_marshal_VOID__OBJECT, |
331 fb_marshal_VOID__OBJECT, |
| 246 G_TYPE_NONE, |
332 G_TYPE_NONE, |
| 247 1, G_TYPE_ERROR); |
333 1, G_TYPE_ERROR); |
| |
334 |
| |
335 /** |
| |
336 * FbApi::events: |
| |
337 * @api: The #FbApi. |
| |
338 * @events: The #GSList of #FbApiEvent's. |
| |
339 * |
| |
340 * Emitted upon incoming events from the stream. |
| |
341 */ |
| 248 g_signal_new("events", |
342 g_signal_new("events", |
| 249 G_TYPE_FROM_CLASS(klass), |
343 G_TYPE_FROM_CLASS(klass), |
| 250 G_SIGNAL_ACTION, |
344 G_SIGNAL_ACTION, |
| 251 0, |
345 0, |
| 252 NULL, NULL, |
346 NULL, NULL, |
| 253 fb_marshal_VOID__POINTER, |
347 fb_marshal_VOID__POINTER, |
| 254 G_TYPE_NONE, |
348 G_TYPE_NONE, |
| 255 1, G_TYPE_POINTER); |
349 1, G_TYPE_POINTER); |
| |
350 |
| |
351 /** |
| |
352 * FbApi::messages: |
| |
353 * @api: The #FbApi. |
| |
354 * @msgs: The #GSList of #FbApiMessage's. |
| |
355 * |
| |
356 * Emitted upon incoming messages from the stream. |
| |
357 */ |
| 256 g_signal_new("messages", |
358 g_signal_new("messages", |
| 257 G_TYPE_FROM_CLASS(klass), |
359 G_TYPE_FROM_CLASS(klass), |
| 258 G_SIGNAL_ACTION, |
360 G_SIGNAL_ACTION, |
| 259 0, |
361 0, |
| 260 NULL, NULL, |
362 NULL, NULL, |
| 261 fb_marshal_VOID__POINTER, |
363 fb_marshal_VOID__POINTER, |
| 262 G_TYPE_NONE, |
364 G_TYPE_NONE, |
| 263 1, G_TYPE_POINTER); |
365 1, G_TYPE_POINTER); |
| |
366 |
| |
367 /** |
| |
368 * FbApi::presences: |
| |
369 * @api: The #FbApi. |
| |
370 * @press: The #GSList of #FbApiPresence's. |
| |
371 * |
| |
372 * Emitted upon incoming presences from the stream. |
| |
373 */ |
| 264 g_signal_new("presences", |
374 g_signal_new("presences", |
| 265 G_TYPE_FROM_CLASS(klass), |
375 G_TYPE_FROM_CLASS(klass), |
| 266 G_SIGNAL_ACTION, |
376 G_SIGNAL_ACTION, |
| 267 0, |
377 0, |
| 268 NULL, NULL, |
378 NULL, NULL, |
| 269 fb_marshal_VOID__POINTER, |
379 fb_marshal_VOID__POINTER, |
| 270 G_TYPE_NONE, |
380 G_TYPE_NONE, |
| 271 1, G_TYPE_POINTER); |
381 1, G_TYPE_POINTER); |
| |
382 |
| |
383 /** |
| |
384 * FbApi::thread: |
| |
385 * @api: The #FbApi. |
| |
386 * @thrd: The #FbApiThread. |
| |
387 * |
| |
388 * Emitted upon the successful reply of a thread request. This |
| |
389 * is emitted as a result of #fb_api_thread(). |
| |
390 */ |
| 272 g_signal_new("thread", |
391 g_signal_new("thread", |
| 273 G_TYPE_FROM_CLASS(klass), |
392 G_TYPE_FROM_CLASS(klass), |
| 274 G_SIGNAL_ACTION, |
393 G_SIGNAL_ACTION, |
| 275 0, |
394 0, |
| 276 NULL, NULL, |
395 NULL, NULL, |
| 277 fb_marshal_VOID__POINTER, |
396 fb_marshal_VOID__POINTER, |
| 278 G_TYPE_NONE, |
397 G_TYPE_NONE, |
| 279 1, G_TYPE_POINTER); |
398 1, G_TYPE_POINTER); |
| |
399 |
| |
400 /** |
| |
401 * FbApi::thread-create: |
| |
402 * @api: The #FbApi. |
| |
403 * @tid: The thread #FbId. |
| |
404 * |
| |
405 * Emitted upon the successful reply of a thread creation |
| |
406 * request. This is emitted as a result of |
| |
407 * #fb_api_thread_create(). |
| |
408 */ |
| 280 g_signal_new("thread-create", |
409 g_signal_new("thread-create", |
| 281 G_TYPE_FROM_CLASS(klass), |
410 G_TYPE_FROM_CLASS(klass), |
| 282 G_SIGNAL_ACTION, |
411 G_SIGNAL_ACTION, |
| 283 0, |
412 0, |
| 284 NULL, NULL, |
413 NULL, NULL, |
| 285 fb_marshal_VOID__INT64, |
414 fb_marshal_VOID__INT64, |
| 286 G_TYPE_NONE, |
415 G_TYPE_NONE, |
| 287 1, FB_TYPE_ID); |
416 1, FB_TYPE_ID); |
| |
417 |
| |
418 /** |
| |
419 * FbApi::threads: |
| |
420 * @api: The #FbApi. |
| |
421 * @thrds: The #GSList of #FbApiThread's. |
| |
422 * |
| |
423 * Emitted upon the successful reply of a threads request. This |
| |
424 * is emitted as a result of #fb_api_threads(). |
| |
425 */ |
| 288 g_signal_new("threads", |
426 g_signal_new("threads", |
| 289 G_TYPE_FROM_CLASS(klass), |
427 G_TYPE_FROM_CLASS(klass), |
| 290 G_SIGNAL_ACTION, |
428 G_SIGNAL_ACTION, |
| 291 0, |
429 0, |
| 292 NULL, NULL, |
430 NULL, NULL, |
| 293 fb_marshal_VOID__POINTER, |
431 fb_marshal_VOID__POINTER, |
| 294 G_TYPE_NONE, |
432 G_TYPE_NONE, |
| 295 1, G_TYPE_POINTER); |
433 1, G_TYPE_POINTER); |
| |
434 |
| |
435 /** |
| |
436 * FbApi::typing: |
| |
437 * @api: The #FbApi. |
| |
438 * @typg: The #FbApiTyping. |
| |
439 * |
| |
440 * Emitted upon an incoming typing state from the stream. |
| |
441 */ |
| 296 g_signal_new("typing", |
442 g_signal_new("typing", |
| 297 G_TYPE_FROM_CLASS(klass), |
443 G_TYPE_FROM_CLASS(klass), |
| 298 G_SIGNAL_ACTION, |
444 G_SIGNAL_ACTION, |
| 299 0, |
445 0, |
| 300 NULL, NULL, |
446 NULL, NULL, |
| 1820 purple_http_conn_cancel_all(priv->gc); |
1966 purple_http_conn_cancel_all(priv->gc); |
| 1821 fb_mqtt_disconnect(priv->mqtt); |
1967 fb_mqtt_disconnect(priv->mqtt); |
| 1822 } |
1968 } |
| 1823 |
1969 |
| 1824 void |
1970 void |
| 1825 fb_api_message(FbApi *api, FbId id, gboolean thread, const gchar *msg) |
1971 fb_api_message(FbApi *api, FbId id, gboolean thread, const gchar *text) |
| 1826 { |
1972 { |
| 1827 const gchar *tpfx; |
1973 const gchar *tpfx; |
| 1828 FbApiPrivate *priv; |
1974 FbApiPrivate *priv; |
| 1829 gchar *json; |
1975 gchar *json; |
| 1830 gpointer mptr; |
1976 gpointer mptr; |
| 1831 guint64 msgid; |
1977 guint64 msgid; |
| 1832 JsonBuilder *bldr; |
1978 JsonBuilder *bldr; |
| 1833 |
1979 |
| 1834 g_return_if_fail(FB_IS_API(api)); |
1980 g_return_if_fail(FB_IS_API(api)); |
| 1835 g_return_if_fail(msg != NULL); |
1981 g_return_if_fail(text != NULL); |
| 1836 priv = api->priv; |
1982 priv = api->priv; |
| 1837 |
1983 |
| 1838 msgid = FB_API_MSGID(g_get_real_time() / 1000, g_random_int()); |
1984 msgid = FB_API_MSGID(g_get_real_time() / 1000, g_random_int()); |
| 1839 tpfx = thread ? "tfbid_" : ""; |
1985 tpfx = thread ? "tfbid_" : ""; |
| 1840 |
1986 |
| 1841 mptr = g_memdup(&msgid, sizeof msgid); |
1987 mptr = g_memdup(&msgid, sizeof msgid); |
| 1842 g_hash_table_replace(priv->msgids, mptr, mptr); |
1988 g_hash_table_replace(priv->msgids, mptr, mptr); |
| 1843 |
1989 |
| 1844 bldr = fb_json_bldr_new(JSON_NODE_OBJECT); |
1990 bldr = fb_json_bldr_new(JSON_NODE_OBJECT); |
| 1845 fb_json_bldr_add_int(bldr, "msgid", msgid); |
1991 fb_json_bldr_add_int(bldr, "msgid", msgid); |
| 1846 fb_json_bldr_add_str(bldr, "body", msg); |
1992 fb_json_bldr_add_str(bldr, "body", text); |
| 1847 fb_json_bldr_add_strf(bldr, "sender_fbid", "%" FB_ID_FORMAT, priv->uid); |
1993 fb_json_bldr_add_strf(bldr, "sender_fbid", "%" FB_ID_FORMAT, priv->uid); |
| 1848 fb_json_bldr_add_strf(bldr, "to", "%s%" FB_ID_FORMAT, tpfx, id); |
1994 fb_json_bldr_add_strf(bldr, "to", "%s%" FB_ID_FORMAT, tpfx, id); |
| 1849 |
1995 |
| 1850 json = fb_json_bldr_close(bldr, JSON_NODE_OBJECT, NULL); |
1996 json = fb_json_bldr_close(bldr, JSON_NODE_OBJECT, NULL); |
| 1851 fb_api_publish(api, "/send_message2", "%s", json); |
1997 fb_api_publish(api, "/send_message2", "%s", json); |
| 1852 g_free(json); |
1998 g_free(json); |
| 1853 } |
1999 } |
| 1854 |
2000 |
| 1855 void |
2001 void |
| 1856 fb_api_publish(FbApi *api, const gchar *topic, const gchar *fmt, ...) |
2002 fb_api_publish(FbApi *api, const gchar *topic, const gchar *format, ...) |
| 1857 { |
2003 { |
| 1858 FbApiPrivate *priv; |
2004 FbApiPrivate *priv; |
| 1859 GByteArray *bytes; |
2005 GByteArray *bytes; |
| 1860 GByteArray *cytes; |
2006 GByteArray *cytes; |
| 1861 gchar *msg; |
2007 gchar *msg; |
| 1862 va_list ap; |
2008 va_list ap; |
| 1863 |
2009 |
| 1864 g_return_if_fail(FB_IS_API(api)); |
2010 g_return_if_fail(FB_IS_API(api)); |
| 1865 g_return_if_fail(topic != NULL); |
2011 g_return_if_fail(topic != NULL); |
| 1866 g_return_if_fail(fmt != NULL); |
2012 g_return_if_fail(format != NULL); |
| 1867 priv = api->priv; |
2013 priv = api->priv; |
| 1868 |
2014 |
| 1869 va_start(ap, fmt); |
2015 va_start(ap, format); |
| 1870 msg = g_strdup_vprintf(fmt, ap); |
2016 msg = g_strdup_vprintf(format, ap); |
| 1871 va_end(ap); |
2017 va_end(ap); |
| 1872 |
2018 |
| 1873 bytes = g_byte_array_new_take((guint8*) msg, strlen(msg)); |
2019 bytes = g_byte_array_new_take((guint8*) msg, strlen(msg)); |
| 1874 cytes = fb_util_zcompress(bytes); |
2020 cytes = fb_util_zcompress(bytes); |
| 1875 |
2021 |