Wed, 25 May 2022 23:52:45 -0500
Remove prpl-gtalk from XMPP console
It no longer exists, and complicates the code a bit.
| 8675 | 1 | /* |
| 2 | * nmconn.c | |
| 3 | * | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
4 | * Copyright (c) 2004 Novell, Inc. All Rights Reserved. |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
5 | * |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
6 | * This program is free software; you can redistribute it and/or modify |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
7 | * it under the terms of the GNU General Public License as published by |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
8 | * the Free Software Foundation; version 2 of the License. |
| 8675 | 9 | * |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
13 | * GNU General Public License for more details. |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
14 | * |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
16 | * along with this program; if not, write to the Free Software |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15435
diff
changeset
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8675 | 18 | * |
| 19 | */ | |
| 20 | ||
| 21 | #include <glib.h> | |
|
40669
48dfed6f4f1f
Fix Windows builds and tests
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40474
diff
changeset
|
22 | #ifdef HAVE_UNISTD_H |
| 8675 | 23 | #include <unistd.h> |
|
40669
48dfed6f4f1f
Fix Windows builds and tests
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents:
40474
diff
changeset
|
24 | #endif |
| 8675 | 25 | #include <string.h> |
| 26 | #include <ctype.h> | |
|
40118
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
27 | |
|
40358
e6fe6fc1f516
move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually
Gary Kramlich <grim@reaperworld.com>
parents:
40120
diff
changeset
|
28 | #include <purple.h> |
|
40118
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
29 | |
| 8675 | 30 | #include "nmconn.h" |
| 31 | ||
| 32 | #ifdef _WIN32 | |
| 33 | #include <windows.h> | |
| 34 | #endif | |
| 35 | ||
| 36 | #define NO_ESCAPE(ch) ((ch == 0x20) || (ch >= 0x30 && ch <= 0x39) || \ | |
| 37 | (ch >= 0x41 && ch <= 0x5a) || (ch >= 0x61 && ch <= 0x7a)) | |
| 38 | ||
| 39 | static char * | |
| 40 | url_escape_string(char *src) | |
| 41 | { | |
| 42 | guint32 escape = 0; | |
| 43 | char *p; | |
| 44 | char *q; | |
| 45 | char *encoded = NULL; | |
| 46 | int ch; | |
| 47 | ||
| 48 | static const char hex_table[16] = "0123456789abcdef"; | |
| 49 | ||
| 50 | if (src == NULL) { | |
| 51 | return NULL; | |
| 52 | } | |
| 53 | ||
| 54 | /* Find number of chars to escape */ | |
| 55 | for (p = src; *p != '\0'; p++) { | |
| 56 | ch = (guchar) *p; | |
| 57 | if (!NO_ESCAPE(ch)) { | |
| 58 | escape++; | |
| 59 | } | |
| 60 | } | |
| 61 | ||
| 62 | encoded = g_malloc((p - src) + (escape * 2) + 1); | |
| 63 | ||
| 64 | /* Escape the string */ | |
| 65 | for (p = src, q = encoded; *p != '\0'; p++) { | |
| 66 | ch = (guchar) * p; | |
| 67 | if (NO_ESCAPE(ch)) { | |
| 68 | if (ch != 0x20) { | |
| 69 | *q = ch; | |
| 70 | q++; | |
| 71 | } else { | |
| 72 | *q = '+'; | |
| 73 | q++; | |
| 74 | } | |
| 75 | } else { | |
| 76 | *q = '%'; | |
| 77 | q++; | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
78 | |
| 8675 | 79 | *q = hex_table[ch >> 4]; |
| 80 | q++; | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
81 | |
| 8675 | 82 | *q = hex_table[ch & 15]; |
| 83 | q++; | |
| 84 | } | |
| 85 | } | |
| 86 | *q = '\0'; | |
| 87 | ||
| 88 | return encoded; | |
| 89 | } | |
| 90 | ||
| 91 | static char * | |
| 92 | encode_method(guint8 method) | |
| 93 | { | |
| 94 | char *str; | |
| 95 | ||
| 96 | switch (method) { | |
| 97 | case NMFIELD_METHOD_EQUAL: | |
| 98 | str = "G"; | |
| 99 | break; | |
| 100 | case NMFIELD_METHOD_UPDATE: | |
| 101 | str = "F"; | |
| 102 | break; | |
| 103 | case NMFIELD_METHOD_GTE: | |
| 104 | str = "E"; | |
| 105 | break; | |
| 106 | case NMFIELD_METHOD_LTE: | |
| 107 | str = "D"; | |
| 108 | break; | |
| 109 | case NMFIELD_METHOD_NE: | |
| 110 | str = "C"; | |
| 111 | break; | |
| 112 | case NMFIELD_METHOD_EXIST: | |
| 113 | str = "B"; | |
| 114 | break; | |
| 115 | case NMFIELD_METHOD_NOTEXIST: | |
| 116 | str = "A"; | |
| 117 | break; | |
| 118 | case NMFIELD_METHOD_SEARCH: | |
| 119 | str = "9"; | |
| 120 | break; | |
| 121 | case NMFIELD_METHOD_MATCHBEGIN: | |
| 122 | str = "8"; | |
| 123 | break; | |
| 124 | case NMFIELD_METHOD_MATCHEND: | |
| 125 | str = "7"; | |
| 126 | break; | |
| 127 | case NMFIELD_METHOD_NOT_ARRAY: | |
| 128 | str = "6"; | |
| 129 | break; | |
| 130 | case NMFIELD_METHOD_OR_ARRAY: | |
| 131 | str = "5"; | |
| 132 | break; | |
| 133 | case NMFIELD_METHOD_AND_ARRAY: | |
| 134 | str = "4"; | |
| 135 | break; | |
| 136 | case NMFIELD_METHOD_DELETE_ALL: | |
| 137 | str = "3"; | |
| 138 | break; | |
| 139 | case NMFIELD_METHOD_DELETE: | |
| 140 | str = "2"; | |
| 141 | break; | |
| 142 | case NMFIELD_METHOD_ADD: | |
| 143 | str = "1"; | |
| 144 | break; | |
| 145 | default: /* NMFIELD_METHOD_VALID */ | |
| 146 | str = "0"; | |
| 147 | break; | |
| 148 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
149 | |
| 8675 | 150 | return str; |
| 151 | } | |
| 152 | ||
|
9360
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
153 | NMConn * |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
154 | nm_create_conn(const char *addr, int port) |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
155 | { |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
156 | NMConn *conn = g_new0(NMConn, 1); |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
157 | conn->addr = g_strdup(addr); |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
158 | conn->port = port; |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
159 | return conn; |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
160 | } |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
161 | |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
162 | void nm_release_conn(NMConn *conn) |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
163 | { |
|
40118
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
164 | g_return_if_fail(conn != NULL); |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
165 | |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
166 | g_slist_free_full(conn->requests, (GDestroyNotify)nm_release_request); |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
167 | conn->requests = NULL; |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
168 | |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
169 | if (conn->input) { |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
170 | purple_gio_graceful_close(conn->stream, G_INPUT_STREAM(conn->input), |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
171 | conn->output); |
|
9360
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
172 | } |
|
40118
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
173 | g_clear_object(&conn->input); |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
174 | g_clear_object(&conn->output); |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
175 | g_clear_object(&conn->stream); |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
176 | |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
177 | g_clear_pointer(&conn->addr, g_free); |
|
621987e8e765
Convert novell to GIO.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40099
diff
changeset
|
178 | g_free(conn); |
|
9360
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
179 | } |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
180 | |
| 8675 | 181 | NMERR_T |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
182 | nm_write_fields(NMUser *user, NMField *fields) |
| 8675 | 183 | { |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
184 | NMConn *conn; |
| 8675 | 185 | NMERR_T rc = NM_OK; |
| 186 | NMField *field; | |
| 187 | char *value = NULL; | |
| 188 | char *method = NULL; | |
|
8874
6dda85680808
[gaim-migrate @ 9643]
Mike Stoddard <mistoddard@novell.com>
parents:
8753
diff
changeset
|
189 | char buffer[4096]; |
| 8675 | 190 | int ret; |
| 191 | int bytes_to_send; | |
| 192 | int val = 0; | |
| 193 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
194 | g_return_val_if_fail(user != NULL, NMERR_BAD_PARM); |
|
40120
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
195 | g_return_val_if_fail(user->conn != NULL, NMERR_BAD_PARM); |
|
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
196 | g_return_val_if_fail(fields != NULL, NMERR_BAD_PARM); |
|
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
197 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
198 | conn = user->conn; |
| 8675 | 199 | |
| 200 | /* Format each field as valid "post" data and write it out */ | |
| 201 | for (field = fields; (rc == NM_OK) && (field->tag); field++) { | |
| 202 | ||
| 203 | /* We don't currently handle binary types */ | |
| 204 | if (field->method == NMFIELD_METHOD_IGNORE || | |
| 205 | field->type == NMFIELD_TYPE_BINARY) { | |
| 206 | continue; | |
| 207 | } | |
| 208 | ||
| 209 | /* Write the field tag */ | |
| 210 | bytes_to_send = g_snprintf(buffer, sizeof(buffer), "&tag=%s", field->tag); | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
211 | ret = g_output_stream_write(conn->output, buffer, bytes_to_send, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
212 | user->cancellable, NULL); |
| 8675 | 213 | if (ret < 0) { |
| 214 | rc = NMERR_TCP_WRITE; | |
| 215 | } | |
| 216 | ||
| 217 | /* Write the field method */ | |
| 218 | if (rc == NM_OK) { | |
| 219 | method = encode_method(field->method); | |
| 220 | bytes_to_send = g_snprintf(buffer, sizeof(buffer), "&cmd=%s", method); | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
221 | ret = g_output_stream_write(conn->output, buffer, bytes_to_send, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
222 | user->cancellable, NULL); |
| 8675 | 223 | if (ret < 0) { |
| 224 | rc = NMERR_TCP_WRITE; | |
| 225 | } | |
| 226 | } | |
| 227 | ||
| 228 | /* Write the field value */ | |
| 229 | if (rc == NM_OK) { | |
| 230 | switch (field->type) { | |
| 231 | case NMFIELD_TYPE_UTF8: | |
| 232 | case NMFIELD_TYPE_DN: | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
233 | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
234 | value = url_escape_string((char *) field->ptr_value); |
| 8675 | 235 | bytes_to_send = g_snprintf(buffer, sizeof(buffer), |
| 236 | "&val=%s", value); | |
|
8874
6dda85680808
[gaim-migrate @ 9643]
Mike Stoddard <mistoddard@novell.com>
parents:
8753
diff
changeset
|
237 | if (bytes_to_send > (int)sizeof(buffer)) { |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
238 | ret = g_output_stream_write(conn->output, buffer, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
239 | sizeof(buffer), |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
240 | user->cancellable, NULL); |
|
8874
6dda85680808
[gaim-migrate @ 9643]
Mike Stoddard <mistoddard@novell.com>
parents:
8753
diff
changeset
|
241 | } else { |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
242 | ret = g_output_stream_write(conn->output, buffer, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
243 | bytes_to_send, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
244 | user->cancellable, NULL); |
|
8874
6dda85680808
[gaim-migrate @ 9643]
Mike Stoddard <mistoddard@novell.com>
parents:
8753
diff
changeset
|
245 | } |
|
6dda85680808
[gaim-migrate @ 9643]
Mike Stoddard <mistoddard@novell.com>
parents:
8753
diff
changeset
|
246 | |
| 8675 | 247 | if (ret < 0) { |
| 248 | rc = NMERR_TCP_WRITE; | |
| 249 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
250 | |
| 8675 | 251 | g_free(value); |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
252 | |
| 8675 | 253 | break; |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
254 | |
| 8675 | 255 | case NMFIELD_TYPE_ARRAY: |
| 256 | case NMFIELD_TYPE_MV: | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
257 | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
258 | val = nm_count_fields((NMField *) field->ptr_value); |
| 8675 | 259 | bytes_to_send = g_snprintf(buffer, sizeof(buffer), |
| 260 | "&val=%u", val); | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
261 | ret = g_output_stream_write(conn->output, buffer, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
262 | bytes_to_send, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
263 | user->cancellable, NULL); |
| 8675 | 264 | if (ret < 0) { |
| 265 | rc = NMERR_TCP_WRITE; | |
| 266 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
267 | |
| 8675 | 268 | break; |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
269 | |
| 8675 | 270 | default: |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
271 | |
| 8675 | 272 | bytes_to_send = g_snprintf(buffer, sizeof(buffer), |
| 273 | "&val=%u", field->value); | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
274 | ret = g_output_stream_write(conn->output, buffer, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
275 | bytes_to_send, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
276 | user->cancellable, NULL); |
| 8675 | 277 | if (ret < 0) { |
| 278 | rc = NMERR_TCP_WRITE; | |
| 279 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
280 | |
| 8675 | 281 | break; |
| 282 | } | |
| 283 | } | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
284 | |
| 8675 | 285 | /* Write the field type */ |
| 286 | if (rc == NM_OK) { | |
| 287 | bytes_to_send = g_snprintf(buffer, sizeof(buffer), | |
| 288 | "&type=%u", field->type); | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
289 | ret = g_output_stream_write(conn->output, buffer, bytes_to_send, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
290 | user->cancellable, NULL); |
| 8675 | 291 | if (ret < 0) { |
| 292 | rc = NMERR_TCP_WRITE; | |
| 293 | } | |
| 294 | } | |
| 295 | ||
| 296 | /* If the field is a sub array then post its fields */ | |
| 297 | if (rc == NM_OK && val > 0) { | |
| 298 | if (field->type == NMFIELD_TYPE_ARRAY || | |
| 299 | field->type == NMFIELD_TYPE_MV) { | |
| 300 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
301 | rc = nm_write_fields(user, (NMField *)field->ptr_value); |
| 8675 | 302 | } |
| 303 | } | |
| 304 | } | |
| 305 | ||
| 306 | return rc; | |
| 307 | } | |
| 308 | ||
| 309 | NMERR_T | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
310 | nm_send_request(NMUser *user, char *cmd, NMField *fields, nm_response_cb cb, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
311 | gpointer data, NMRequest **request) |
| 8675 | 312 | { |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
313 | NMConn *conn; |
| 8675 | 314 | NMERR_T rc = NM_OK; |
| 315 | char buffer[512]; | |
| 316 | int bytes_to_send; | |
| 317 | int ret; | |
|
9360
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
318 | NMField *request_fields = NULL; |
|
9268
196cbf2cae4c
[gaim-migrate @ 10069]
Mike Stoddard <mistoddard@novell.com>
parents:
8933
diff
changeset
|
319 | char *str = NULL; |
| 8675 | 320 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
321 | g_return_val_if_fail(user != NULL, NMERR_BAD_PARM); |
|
40120
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
322 | g_return_val_if_fail(user->conn != NULL, NMERR_BAD_PARM); |
|
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
323 | g_return_val_if_fail(cmd != NULL, NMERR_BAD_PARM); |
|
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
324 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
325 | conn = user->conn; |
| 8675 | 326 | |
| 327 | /* Write the post */ | |
| 328 | bytes_to_send = g_snprintf(buffer, sizeof(buffer), | |
| 329 | "POST /%s HTTP/1.0\r\n", cmd); | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
330 | ret = g_output_stream_write(conn->output, buffer, bytes_to_send, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
331 | user->cancellable, NULL); |
| 8675 | 332 | if (ret < 0) { |
| 333 | rc = NMERR_TCP_WRITE; | |
| 334 | } | |
| 335 | ||
| 336 | /* Write headers */ | |
| 337 | if (rc == NM_OK) { | |
|
38259
c593fc9f5438
Replace strcmp() with purple_strequal()
qarkai <qarkai@gmail.com>
parents:
19859
diff
changeset
|
338 | if (purple_strequal("login", cmd)) { |
| 8675 | 339 | bytes_to_send = g_snprintf(buffer, sizeof(buffer), |
| 340 | "Host: %s:%d\r\n\r\n", conn->addr, conn->port); | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
341 | ret = g_output_stream_write(conn->output, buffer, bytes_to_send, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
342 | user->cancellable, NULL); |
| 8675 | 343 | if (ret < 0) { |
| 344 | rc = NMERR_TCP_WRITE; | |
| 345 | } | |
| 346 | } else { | |
| 347 | bytes_to_send = g_snprintf(buffer, sizeof(buffer), "\r\n"); | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
348 | ret = g_output_stream_write(conn->output, buffer, bytes_to_send, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
349 | user->cancellable, NULL); |
| 8675 | 350 | if (ret < 0) { |
| 351 | rc = NMERR_TCP_WRITE; | |
| 352 | } | |
| 353 | } | |
| 354 | } | |
| 355 | ||
| 356 | /* Add the transaction id to the request fields */ | |
| 357 | if (rc == NM_OK) { | |
|
9268
196cbf2cae4c
[gaim-migrate @ 10069]
Mike Stoddard <mistoddard@novell.com>
parents:
8933
diff
changeset
|
358 | if (fields) |
|
9360
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
359 | request_fields = nm_copy_field_array(fields); |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
360 | |
|
9268
196cbf2cae4c
[gaim-migrate @ 10069]
Mike Stoddard <mistoddard@novell.com>
parents:
8933
diff
changeset
|
361 | str = g_strdup_printf("%d", ++(conn->trans_id)); |
|
9360
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
362 | request_fields = nm_field_add_pointer(request_fields, NM_A_SZ_TRANSACTION_ID, 0, |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
363 | NMFIELD_METHOD_VALID, 0, |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
364 | str, NMFIELD_TYPE_UTF8); |
| 8675 | 365 | } |
| 366 | ||
| 367 | /* Send the request to the server */ | |
| 368 | if (rc == NM_OK) { | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
369 | rc = nm_write_fields(user, request_fields); |
| 8675 | 370 | } |
| 371 | ||
| 372 | /* Write the CRLF to terminate the data */ | |
| 373 | if (rc == NM_OK) { | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
374 | ret = g_output_stream_write(conn->output, "\r\n", strlen("\r\n"), |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
375 | user->cancellable, NULL); |
| 8675 | 376 | if (ret < 0) { |
| 377 | rc = NMERR_TCP_WRITE; | |
| 378 | } | |
| 379 | } | |
| 380 | ||
|
9360
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
381 | /* Create a request struct, add it to our queue, and return it */ |
| 8675 | 382 | if (rc == NM_OK) { |
|
40098
1f2ef108cfcb
novell: Remove unused data/code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40097
diff
changeset
|
383 | NMRequest *new_request = |
|
1f2ef108cfcb
novell: Remove unused data/code.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40097
diff
changeset
|
384 | nm_create_request(cmd, conn->trans_id, cb, NULL, data); |
|
9360
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
385 | nm_conn_add_request_item(conn, new_request); |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
386 | |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
387 | /* Set the out param if it was sent in, otherwise release the request */ |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
388 | if (request) |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
389 | *request = new_request; |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
390 | else |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
391 | nm_release_request(new_request); |
| 8675 | 392 | } |
| 393 | ||
|
9360
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
394 | if (request_fields != NULL) |
|
c40bc951573a
[gaim-migrate @ 10168]
Mike Stoddard <mistoddard@novell.com>
parents:
9268
diff
changeset
|
395 | nm_free_fields(&request_fields); |
| 8675 | 396 | |
| 397 | return rc; | |
| 398 | } | |
| 399 | ||
| 400 | NMERR_T | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
401 | nm_read_header(NMUser *user) |
| 8675 | 402 | { |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
403 | NMConn *conn; |
| 8675 | 404 | NMERR_T rc = NM_OK; |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
405 | gchar *buffer; |
| 8675 | 406 | char *ptr = NULL; |
| 407 | int i; | |
| 408 | char rtn_buf[8]; | |
| 409 | int rtn_code = 0; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
410 | GError *error = NULL; |
| 8675 | 411 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
412 | g_return_val_if_fail(user != NULL, NMERR_BAD_PARM); |
|
40120
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
413 | g_return_val_if_fail(user->conn != NULL, NMERR_BAD_PARM); |
|
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
414 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
415 | conn = user->conn; |
| 8675 | 416 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
417 | buffer = g_data_input_stream_read_line(conn->input, NULL, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
418 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
419 | if (error == NULL) { |
| 8675 | 420 | /* Find the return code */ |
| 421 | ptr = strchr(buffer, ' '); | |
| 422 | if (ptr != NULL) { | |
| 423 | ptr++; | |
| 424 | ||
| 425 | i = 0; | |
| 426 | while (isdigit(*ptr) && (i < 3)) { | |
| 427 | rtn_buf[i] = *ptr; | |
| 428 | i++; | |
| 429 | ptr++; | |
| 430 | } | |
| 431 | rtn_buf[i] = '\0'; | |
|
8684
7ec649752daa
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
432 | |
| 8675 | 433 | if (i > 0) |
| 434 | rtn_code = atoi(rtn_buf); | |
| 435 | } | |
| 436 | } | |
| 437 | ||
| 438 | /* Finish reading header, in the future we might want to do more processing here */ | |
| 439 | /* TODO: handle more general redirects in the future */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
440 | while ((error == NULL) && !purple_strequal(buffer, "\r")) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
441 | g_free(buffer); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
442 | buffer = g_data_input_stream_read_line(conn->input, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
443 | user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
444 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
445 | g_free(buffer); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
446 | |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
447 | if (error != NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
448 | if (error->code != G_IO_ERROR_WOULD_BLOCK && |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
449 | error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
450 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
451 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
452 | g_error_free(error); |
| 8675 | 453 | } |
| 454 | ||
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
455 | if (rc == NM_OK && rtn_code == 301) |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
456 | rc = NMERR_SERVER_REDIRECT; |
| 8675 | 457 | |
| 458 | return rc; | |
| 459 | } | |
| 460 | ||
| 461 | NMERR_T | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
462 | nm_read_fields(NMUser *user, int count, NMField **fields) |
| 8675 | 463 | { |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
464 | NMConn *conn; |
| 8675 | 465 | NMERR_T rc = NM_OK; |
| 466 | guint8 type; | |
| 467 | guint8 method; | |
| 468 | guint32 val; | |
| 469 | char tag[64]; | |
| 470 | NMField *sub_fields = NULL; | |
| 471 | char *str = NULL; | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
472 | GError *error = NULL; |
| 8675 | 473 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
474 | g_return_val_if_fail(user != NULL, NMERR_BAD_PARM); |
|
40120
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
475 | g_return_val_if_fail(user->conn != NULL, NMERR_BAD_PARM); |
|
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
476 | g_return_val_if_fail(fields != NULL, NMERR_BAD_PARM); |
|
649d1bfd0ecc
Re-arrange some NULL checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40119
diff
changeset
|
477 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
478 | conn = user->conn; |
| 8675 | 479 | |
| 480 | do { | |
|
8753
4a4e7b193a43
[gaim-migrate @ 9508]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
481 | if (count > 0) { |
| 8675 | 482 | count--; |
| 483 | } | |
| 484 | ||
| 485 | /* Read the field type, method, and tag */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
486 | type = g_data_input_stream_read_byte(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
487 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
488 | if (error != NULL || type == 0) { |
| 8675 | 489 | break; |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
490 | } |
| 8675 | 491 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
492 | method = g_data_input_stream_read_byte(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
493 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
494 | if (error != NULL) { |
| 8675 | 495 | break; |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
496 | } |
| 8675 | 497 | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
498 | val = g_data_input_stream_read_uint32(conn->input, user->cancellable, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
499 | &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
500 | if (error != NULL) { |
| 8675 | 501 | break; |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
502 | } |
| 8675 | 503 | |
| 504 | if (val > sizeof(tag)) { | |
| 505 | rc = NMERR_PROTOCOL; | |
| 506 | break; | |
| 507 | } | |
| 508 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
509 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), tag, val, NULL, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
510 | user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
511 | if (error != NULL) { |
| 8675 | 512 | break; |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
513 | } |
| 8675 | 514 | |
| 515 | if (type == NMFIELD_TYPE_MV || type == NMFIELD_TYPE_ARRAY) { | |
| 516 | ||
| 517 | /* Read the subarray (first read the number of items in the array) */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
518 | val = g_data_input_stream_read_uint32(conn->input, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
519 | user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
520 | if (error != NULL) { |
| 8675 | 521 | break; |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
522 | } |
| 8675 | 523 | |
| 524 | if (val > 0) { | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
525 | rc = nm_read_fields(user, val, &sub_fields); |
| 8675 | 526 | if (rc != NM_OK) |
| 527 | break; | |
| 528 | } | |
| 529 | ||
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
530 | *fields = nm_field_add_pointer(*fields, tag, 0, method, |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
531 | 0, sub_fields, type); |
| 8675 | 532 | |
| 533 | sub_fields = NULL; | |
| 534 | ||
| 535 | } else if (type == NMFIELD_TYPE_UTF8 || type == NMFIELD_TYPE_DN) { | |
| 536 | ||
| 537 | /* Read the string (first read the length) */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
538 | val = g_data_input_stream_read_uint32(conn->input, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
539 | user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
540 | if (error != NULL) { |
| 8675 | 541 | break; |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
542 | } |
| 8675 | 543 | |
|
8753
4a4e7b193a43
[gaim-migrate @ 9508]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
544 | if (val >= NMFIELD_MAX_STR_LENGTH) { |
|
4a4e7b193a43
[gaim-migrate @ 9508]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
545 | rc = NMERR_PROTOCOL; |
|
4a4e7b193a43
[gaim-migrate @ 9508]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
546 | break; |
|
4a4e7b193a43
[gaim-migrate @ 9508]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
547 | } |
|
4a4e7b193a43
[gaim-migrate @ 9508]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
548 | |
| 8675 | 549 | if (val > 0) { |
| 550 | str = g_new0(char, val + 1); | |
| 551 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
552 | g_input_stream_read_all(G_INPUT_STREAM(conn->input), str, val, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
553 | NULL, user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
554 | if (error != NULL) { |
| 8675 | 555 | break; |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
556 | } |
|
8753
4a4e7b193a43
[gaim-migrate @ 9508]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
557 | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
558 | *fields = nm_field_add_pointer(*fields, tag, 0, method, |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
559 | 0, str, type); |
|
8753
4a4e7b193a43
[gaim-migrate @ 9508]
Mike Stoddard <mistoddard@novell.com>
parents:
8684
diff
changeset
|
560 | str = NULL; |
| 8675 | 561 | } |
| 562 | ||
| 563 | } else { | |
| 564 | ||
| 565 | /* Read the numerical value */ | |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
566 | val = g_data_input_stream_read_uint32(conn->input, |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
567 | user->cancellable, &error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
568 | if (error != NULL) { |
| 8675 | 569 | break; |
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
570 | } |
| 8675 | 571 | |
|
8933
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
572 | *fields = nm_field_add_number(*fields, tag, 0, method, |
|
0f1e8160581d
[gaim-migrate @ 9703]
Mike Stoddard <mistoddard@novell.com>
parents:
8874
diff
changeset
|
573 | 0, val, type); |
| 8675 | 574 | } |
| 575 | ||
|
39913
ce96d4639dc7
Remove redundant conditions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
38358
diff
changeset
|
576 | } while (count != 0); |
| 8675 | 577 | |
|
37389
7240fd8e3462
free() and g_free() are specified to be NULL-safe. Remove NULL checks.
Michael McConville <mmcconville@mykolab.com>
parents:
19859
diff
changeset
|
578 | g_free(str); |
| 8675 | 579 | |
| 580 | if (sub_fields != NULL) { | |
| 581 | nm_free_fields(&sub_fields); | |
| 582 | } | |
| 583 | ||
|
40119
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
584 | if (error != NULL) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
585 | if (error->code != G_IO_ERROR_WOULD_BLOCK && error->code != G_IO_ERROR_CANCELLED) { |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
586 | rc = NMERR_TCP_READ; |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
587 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
588 | g_error_free(error); |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
589 | } |
|
2e1969768857
novell: Replace socket wrappers with GIO functions.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
40118
diff
changeset
|
590 | |
| 8675 | 591 | return rc; |
| 592 | } | |
| 593 | ||
| 594 | void | |
| 595 | nm_conn_add_request_item(NMConn * conn, NMRequest * request) | |
| 596 | { | |
| 597 | if (conn == NULL || request == NULL) | |
| 598 | return; | |
| 599 | ||
| 600 | nm_request_add_ref(request); | |
| 601 | conn->requests = g_slist_append(conn->requests, request); | |
| 602 | } | |
| 603 | ||
| 604 | void | |
| 605 | nm_conn_remove_request_item(NMConn * conn, NMRequest * request) | |
| 606 | { | |
| 607 | if (conn == NULL || request == NULL) | |
| 608 | return; | |
| 609 | ||
| 610 | conn->requests = g_slist_remove(conn->requests, request); | |
| 611 | nm_release_request(request); | |
| 612 | } | |
| 613 | ||
| 614 | NMRequest * | |
| 615 | nm_conn_find_request(NMConn * conn, int trans_id) | |
| 616 | { | |
| 617 | NMRequest *req = NULL; | |
| 618 | GSList *itr = NULL; | |
| 619 | ||
| 620 | if (conn == NULL) | |
| 621 | return NULL; | |
| 622 | ||
| 623 | itr = conn->requests; | |
| 624 | while (itr) { | |
| 625 | req = (NMRequest *) itr->data; | |
| 626 | if (req != NULL && nm_request_get_trans_id(req) == trans_id) { | |
| 627 | return req; | |
| 628 | } | |
| 629 | itr = g_slist_next(itr); | |
| 630 | } | |
| 631 | return NULL; | |
| 632 | } |