libpurple/protocols/gg/libgaduw.c

Tue, 10 Sep 2019 00:06:36 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Tue, 10 Sep 2019 00:06:36 -0400
changeset 39819
3554dac2991b
parent 36295
d17aebf2a4ce
child 40358
e6fe6fc1f516
permissions
-rw-r--r--

Standardize all protocol header guard macros.

These are all basically standardized replacements on the file path,
removing 'lib' and '/protocols/', replacing invalid characters by
underscore, and then converting to upper case.

This avoids a lot of reserved identifier usage.

33348
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
1 /* purple
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
2 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
5 * source distribution.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
6 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
7 * Rewritten from scratch during Google Summer of Code 2012
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
8 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
9 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
10 * Previously implemented by:
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
11 * - Arkadiusz Miskiewicz <misiek@pld.org.pl> - first implementation (2001);
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
12 * - Bartosz Oler <bartosz@bzimage.us> - reimplemented during GSoC 2005;
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
13 * - Krzysztof Klinikowski <grommasher@gmail.com> - some parts (2009-2011).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
14 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
15 * This program is free software; you can redistribute it and/or modify
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
16 * it under the terms of the GNU General Public License as published by
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
17 * the Free Software Foundation; either version 2 of the License, or
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
18 * (at your option) any later version.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
19 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
20 * This program is distributed in the hope that it will be useful,
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
23 * GNU General Public License for more details.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
24 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
25 * You should have received a copy of the GNU General Public License
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
26 * along with this program; if not, write to the Free Software
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
28 */
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33309
diff changeset
29
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
30 #include "libgaduw.h"
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
31
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
32 #include <debug.h>
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
33
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
34 #include "purplew.h"
34373
169db6aa5e08 Gadu-Gadu: very initial GGDrive authentication support
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33351
diff changeset
35 #include "gg.h"
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
36
34408
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
37 static void ggp_libgaduw_debug_handler(int level, const char * format,
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
38 va_list args);
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
39
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
40 /*******************************************************************************
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
41 * Setup/cleanup.
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
42 ******************************************************************************/
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
43
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
44 void ggp_libgaduw_setup(void)
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
45 {
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
46 gg_debug_handler = ggp_libgaduw_debug_handler;
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
47 }
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
48
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
49 void ggp_libgaduw_cleanup(void)
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
50 {
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
51 gg_debug_handler = NULL;
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
52 }
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
53
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
54 /*******************************************************************************
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
55 * General.
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
56 ******************************************************************************/
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
57
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
58 const gchar * ggp_libgaduw_version(PurpleConnection *gc)
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
59 {
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
60 GGPInfo *accdata = purple_connection_get_protocol_data(gc);
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
61 const gchar *ver = accdata->session->client_version;
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
62
34408
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
63 if (ver != NULL && isdigit(ver[0]))
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
64 return ver;
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
65 return GG_DEFAULT_CLIENT_VERSION;
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
66 }
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
67
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
68 static void ggp_libgaduw_debug_handler(int level, const char * format,
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
69 va_list args)
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
70 {
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
71 PurpleDebugLevel purple_level;
36293
6af7f9a6859f Merge with release-2.x.y with a few manual conflict resolutions
Daniel Atallah <datallah@pidgin.im>
parents: 36281
diff changeset
72 char msgbuff[1000];
6af7f9a6859f Merge with release-2.x.y with a few manual conflict resolutions
Daniel Atallah <datallah@pidgin.im>
parents: 36281
diff changeset
73 int ret;
34408
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
74
36124
3dcb9b9b7c11 Drop libgadu legacy API compatibility code
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
75 if ((level & GG_DEBUG_NET) || (level & GG_DEBUG_FUNCTION) ||
3dcb9b9b7c11 Drop libgadu legacy API compatibility code
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
76 (level & GG_DEBUG_VERBOSE))
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
77 {
34408
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
78 if (!purple_debug_is_verbose())
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
79 return;
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
80 }
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
81
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
82 if ((level & GG_DEBUG_DUMP) || /* GG session protocol packets */
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
83 (level & GG_DEBUG_TRAFFIC)) /* HTTP traffic */
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
84 {
34408
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
85 if (!purple_debug_is_verbose() || !purple_debug_is_unsafe())
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
86 return;
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
87 }
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
88
36293
6af7f9a6859f Merge with release-2.x.y with a few manual conflict resolutions
Daniel Atallah <datallah@pidgin.im>
parents: 36281
diff changeset
89 /* Don't use glib's printf family, since it might not support
6af7f9a6859f Merge with release-2.x.y with a few manual conflict resolutions
Daniel Atallah <datallah@pidgin.im>
parents: 36281
diff changeset
90 * system-specific formatting modifiers (like %Iu for size on win32). */
6af7f9a6859f Merge with release-2.x.y with a few manual conflict resolutions
Daniel Atallah <datallah@pidgin.im>
parents: 36281
diff changeset
91 ret = vsnprintf(msgbuff, sizeof(msgbuff) / sizeof(char), format, args);
34408
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
92
36293
6af7f9a6859f Merge with release-2.x.y with a few manual conflict resolutions
Daniel Atallah <datallah@pidgin.im>
parents: 36281
diff changeset
93 if (ret <= 0) {
36281
017310ea69c0 Merge with release-2.x.y (with a number of conflicts)
Daniel Atallah <datallah@pidgin.im>
parents: 36124
diff changeset
94 purple_debug_fatal("gg",
36293
6af7f9a6859f Merge with release-2.x.y with a few manual conflict resolutions
Daniel Atallah <datallah@pidgin.im>
parents: 36281
diff changeset
95 "failed to printf the following message: %s",
36281
017310ea69c0 Merge with release-2.x.y (with a number of conflicts)
Daniel Atallah <datallah@pidgin.im>
parents: 36124
diff changeset
96 format ? format : "(null)\n");
017310ea69c0 Merge with release-2.x.y (with a number of conflicts)
Daniel Atallah <datallah@pidgin.im>
parents: 36124
diff changeset
97
017310ea69c0 Merge with release-2.x.y (with a number of conflicts)
Daniel Atallah <datallah@pidgin.im>
parents: 36124
diff changeset
98 return;
017310ea69c0 Merge with release-2.x.y (with a number of conflicts)
Daniel Atallah <datallah@pidgin.im>
parents: 36124
diff changeset
99 }
017310ea69c0 Merge with release-2.x.y (with a number of conflicts)
Daniel Atallah <datallah@pidgin.im>
parents: 36124
diff changeset
100
34408
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
101 if (level & GG_DEBUG_ERROR)
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
102 purple_level = PURPLE_DEBUG_ERROR;
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
103 else if (level & GG_DEBUG_WARNING)
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
104 purple_level = PURPLE_DEBUG_WARNING;
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
105 else
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
106 purple_level = PURPLE_DEBUG_MISC;
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
107
36293
6af7f9a6859f Merge with release-2.x.y with a few manual conflict resolutions
Daniel Atallah <datallah@pidgin.im>
parents: 36281
diff changeset
108 purple_debug(purple_level, "gg", "%s", msgbuff);
34408
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
109 }
ee5663c0ffe8 Gadu-Gadu: new libgadu debug handler
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34373
diff changeset
110
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
111 /*******************************************************************************
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
112 * HTTP requests.
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
113 ******************************************************************************/
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
114
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
115 static void ggp_libgaduw_http_processing_cancel(PurpleConnection *gc,
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
116 void *_req);
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
117
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
118 static void ggp_libgaduw_http_handler(gpointer _req, gint fd,
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
119 PurpleInputCondition cond);
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
120
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
121 static void ggp_libgaduw_http_finish(ggp_libgaduw_http_req *req,
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
122 gboolean success);
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
123
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
124 /******************************************************************************/
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
125
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
126 ggp_libgaduw_http_req * ggp_libgaduw_http_watch(PurpleConnection *gc,
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
127 struct gg_http *h, ggp_libgaduw_http_cb cb,
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
128 gpointer user_data, gboolean show_processing)
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
129 {
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
130 ggp_libgaduw_http_req *req;
33351
bd15903d0d89 Gadu-Gadu: fix compilation on 64bit targets
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33348
diff changeset
131 purple_debug_misc("gg", "ggp_libgaduw_http_watch(h=%p, "
bd15903d0d89 Gadu-Gadu: fix compilation on 64bit targets
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33348
diff changeset
132 "show_processing=%d)\n", h, show_processing);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
133
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
134 req = g_new(ggp_libgaduw_http_req, 1);
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
135 req->user_data = user_data;
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
136 req->cb = cb;
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
137 req->cancelled = FALSE;
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
138 req->h = h;
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
139 req->processing = NULL;
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
140 if (show_processing)
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
141 req->processing = ggp_purplew_request_processing(gc, NULL,
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
142 req, ggp_libgaduw_http_processing_cancel);
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
143 req->inpa = ggp_purplew_http_input_add(h, ggp_libgaduw_http_handler,
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
144 req);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
145
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
146 return req;
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
147 }
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
148
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
149 static void ggp_libgaduw_http_processing_cancel(PurpleConnection *gc,
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
150 void *_req)
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
151 {
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
152 ggp_libgaduw_http_req *req = _req;
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
153 req->processing = NULL;
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
154 ggp_libgaduw_http_cancel(req);
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
155 }
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
156
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
157 static void ggp_libgaduw_http_handler(gpointer _req, gint fd,
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
158 PurpleInputCondition cond)
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
159 {
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
160 ggp_libgaduw_http_req *req = _req;
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
161
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
162 if (req->h->callback(req->h) == -1 || req->h->state == GG_STATE_ERROR) {
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
163 purple_debug_error("gg", "ggp_libgaduw_http_handler: failed to "
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
164 "make http request: %d\n", req->h->error);
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
165 ggp_libgaduw_http_finish(req, FALSE);
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
166 return;
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
167 }
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
168
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
169 if (purple_debug_is_verbose()) {
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
170 purple_debug_misc("gg", "ggp_libgaduw_http_handler: got fd "
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
171 "update [check=%d, state=%d]\n", req->h->check,
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
172 req->h->state);
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
173 }
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
174
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
175 if (req->h->state != GG_STATE_DONE) {
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
176 purple_input_remove(req->inpa);
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
177 req->inpa = ggp_purplew_http_input_add(req->h,
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
178 ggp_libgaduw_http_handler, req);
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
179 return;
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
180 }
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34437
diff changeset
181
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
182 if (!req->h->data || !req->h->body) {
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
183 purple_debug_error("gg", "ggp_libgaduw_http_handler: got empty "
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
184 "http response: %d\n", req->h->error);
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
185 ggp_libgaduw_http_finish(req, FALSE);
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
186 return;
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
187 }
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
188
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
189 ggp_libgaduw_http_finish(req, TRUE);
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
190 }
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
191
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
192 void ggp_libgaduw_http_cancel(ggp_libgaduw_http_req *req)
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
193 {
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
194 purple_debug_misc("gg", "ggp_libgaduw_http_cancel\n");
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
195 req->cancelled = TRUE;
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
196 gg_http_stop(req->h);
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
197 ggp_libgaduw_http_finish(req, FALSE);
33307
45147502ceab Gadu-Gadu: refactoring - gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
198 }
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
199
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
200 static void ggp_libgaduw_http_finish(ggp_libgaduw_http_req *req,
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
201 gboolean success)
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
202 {
33351
bd15903d0d89 Gadu-Gadu: fix compilation on 64bit targets
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33348
diff changeset
203 purple_debug_misc("gg", "ggp_libgaduw_http_finish(h=%p, processing=%p):"
bd15903d0d89 Gadu-Gadu: fix compilation on 64bit targets
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33348
diff changeset
204 " success=%d\n", req->h, req->processing, success);
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
205 if (req->processing) {
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
206 ggp_purplew_request_processing_done(req->processing);
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
207 req->processing = NULL;
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
208 }
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
209 purple_input_remove(req->inpa);
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
210 req->cb(req->h, success, req->cancelled, req->user_data);
33309
bc2f2ea7b5ab Gadu-Gadu: refactoring of account registration done
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33308
diff changeset
211 req->h->destroy(req->h);
33308
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
212 g_free(req);
140aa3ad4cae Gadu-Gadu: cancellable gg_http watcher
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33307
diff changeset
213 }

mercurial