Mercurial > pidgin
annotate src/protocols/novell/nmconn.c @ 8718:6ab61697426e
[gaim-migrate @ 9473]
simguy wants this
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Tue, 20 Apr 2004 04:04:41 +0000 |
parents | 046dd8ef2920 |
children | c7e9687bfd79 |
rev | line source |
---|---|
8675 | 1 /* |
2 * nmconn.c | |
3 * | |
4 * Copyright © 2004 Unpublished Work of Novell, Inc. All Rights Reserved. | |
5 * | |
6 * THIS WORK IS AN UNPUBLISHED WORK OF NOVELL, INC. NO PART OF THIS WORK MAY BE | |
7 * USED, PRACTICED, PERFORMED, COPIED, DISTRIBUTED, REVISED, MODIFIED, | |
8 * TRANSLATED, ABRIDGED, CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED, | |
9 * RECAST, TRANSFORMED OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT OF NOVELL, | |
10 * INC. ANY USE OR EXPLOITATION OF THIS WORK WITHOUT AUTHORIZATION COULD SUBJECT | |
11 * THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY. | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
12 * |
8675 | 13 * AS BETWEEN [GAIM] AND NOVELL, NOVELL GRANTS [GAIM] THE RIGHT TO REPUBLISH |
14 * THIS WORK UNDER THE GPL (GNU GENERAL PUBLIC LICENSE) WITH ALL RIGHTS AND | |
15 * LICENSES THEREUNDER. IF YOU HAVE RECEIVED THIS WORK DIRECTLY OR INDIRECTLY | |
16 * FROM [GAIM] AS PART OF SUCH A REPUBLICATION, YOU HAVE ALL RIGHTS AND LICENSES | |
17 * GRANTED BY [GAIM] UNDER THE GPL. IN CONNECTION WITH SUCH A REPUBLICATION, IF | |
18 * ANYTHING IN THIS NOTICE CONFLICTS WITH THE TERMS OF THE GPL, SUCH TERMS | |
19 * PREVAIL. | |
20 * | |
21 */ | |
22 | |
23 #include <glib.h> | |
24 #include <unistd.h> | |
25 #include <errno.h> | |
26 #include <string.h> | |
27 #include <ctype.h> | |
28 #include <time.h> | |
29 #include "nmconn.h" | |
30 | |
31 #ifdef _WIN32 | |
32 #include <windows.h> | |
33 #endif | |
34 | |
35 #define NO_ESCAPE(ch) ((ch == 0x20) || (ch >= 0x30 && ch <= 0x39) || \ | |
36 (ch >= 0x41 && ch <= 0x5a) || (ch >= 0x61 && ch <= 0x7a)) | |
37 | |
38 /* Read data from conn until the end of a line */ | |
39 static NMERR_T | |
40 read_line(NMConn * conn, char *buff, int len) | |
41 { | |
42 NMERR_T rc = NM_OK; | |
43 int total_bytes = 0; | |
44 | |
45 while ((rc == NM_OK) && (total_bytes < (len - 1))) { | |
46 rc = nm_read_all(conn, &buff[total_bytes], 1); | |
47 if (rc == NM_OK) { | |
48 total_bytes += 1; | |
49 if (buff[total_bytes - 1] == '\n') { | |
50 break; | |
51 } | |
52 } | |
53 } | |
54 buff[total_bytes] = '\0'; | |
55 | |
56 return rc; | |
57 } | |
58 | |
59 static char * | |
60 url_escape_string(char *src) | |
61 { | |
62 guint32 escape = 0; | |
63 char *p; | |
64 char *q; | |
65 char *encoded = NULL; | |
66 int ch; | |
67 | |
68 static const char hex_table[16] = "0123456789abcdef"; | |
69 | |
70 if (src == NULL) { | |
71 return NULL; | |
72 } | |
73 | |
74 /* Find number of chars to escape */ | |
75 for (p = src; *p != '\0'; p++) { | |
76 ch = (guchar) *p; | |
77 if (!NO_ESCAPE(ch)) { | |
78 escape++; | |
79 } | |
80 } | |
81 | |
82 encoded = g_malloc((p - src) + (escape * 2) + 1); | |
83 | |
84 /* Escape the string */ | |
85 for (p = src, q = encoded; *p != '\0'; p++) { | |
86 ch = (guchar) * p; | |
87 if (NO_ESCAPE(ch)) { | |
88 if (ch != 0x20) { | |
89 *q = ch; | |
90 q++; | |
91 } else { | |
92 *q = '+'; | |
93 q++; | |
94 } | |
95 } else { | |
96 *q = '%'; | |
97 q++; | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
98 |
8675 | 99 *q = hex_table[ch >> 4]; |
100 q++; | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
101 |
8675 | 102 *q = hex_table[ch & 15]; |
103 q++; | |
104 } | |
105 } | |
106 *q = '\0'; | |
107 | |
108 return encoded; | |
109 } | |
110 | |
111 static char * | |
112 encode_method(guint8 method) | |
113 { | |
114 char *str; | |
115 | |
116 switch (method) { | |
117 case NMFIELD_METHOD_EQUAL: | |
118 str = "G"; | |
119 break; | |
120 case NMFIELD_METHOD_UPDATE: | |
121 str = "F"; | |
122 break; | |
123 case NMFIELD_METHOD_GTE: | |
124 str = "E"; | |
125 break; | |
126 case NMFIELD_METHOD_LTE: | |
127 str = "D"; | |
128 break; | |
129 case NMFIELD_METHOD_NE: | |
130 str = "C"; | |
131 break; | |
132 case NMFIELD_METHOD_EXIST: | |
133 str = "B"; | |
134 break; | |
135 case NMFIELD_METHOD_NOTEXIST: | |
136 str = "A"; | |
137 break; | |
138 case NMFIELD_METHOD_SEARCH: | |
139 str = "9"; | |
140 break; | |
141 case NMFIELD_METHOD_MATCHBEGIN: | |
142 str = "8"; | |
143 break; | |
144 case NMFIELD_METHOD_MATCHEND: | |
145 str = "7"; | |
146 break; | |
147 case NMFIELD_METHOD_NOT_ARRAY: | |
148 str = "6"; | |
149 break; | |
150 case NMFIELD_METHOD_OR_ARRAY: | |
151 str = "5"; | |
152 break; | |
153 case NMFIELD_METHOD_AND_ARRAY: | |
154 str = "4"; | |
155 break; | |
156 case NMFIELD_METHOD_DELETE_ALL: | |
157 str = "3"; | |
158 break; | |
159 case NMFIELD_METHOD_DELETE: | |
160 str = "2"; | |
161 break; | |
162 case NMFIELD_METHOD_ADD: | |
163 str = "1"; | |
164 break; | |
165 default: /* NMFIELD_METHOD_VALID */ | |
166 str = "0"; | |
167 break; | |
168 } | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
169 |
8675 | 170 return str; |
171 } | |
172 | |
173 int | |
174 nm_tcp_write(NMConn * conn, const void *buff, int len) | |
175 { | |
176 if (conn == NULL || buff == NULL) | |
177 return -1; | |
178 | |
179 if (!conn->use_ssl) | |
180 return (write(conn->fd, buff, len)); | |
181 else if (conn->ssl_conn && conn->ssl_conn->write) | |
182 return (conn->ssl_conn->write(conn->ssl_conn->data, buff, len)); | |
183 else | |
184 return -1; | |
185 } | |
186 | |
187 int | |
188 nm_tcp_read(NMConn * conn, void *buff, int len) | |
189 { | |
190 if (conn == NULL || buff == NULL) | |
191 return -1; | |
192 | |
193 if (!conn->use_ssl) | |
194 return (read(conn->fd, buff, len)); | |
195 else if (conn->ssl_conn && conn->ssl_conn->read) | |
196 return (conn->ssl_conn->read(conn->ssl_conn->data, buff, len)); | |
197 else | |
198 return -1; | |
199 } | |
200 | |
201 NMERR_T | |
202 nm_read_all(NMConn * conn, char *buff, int len) | |
203 { | |
204 NMERR_T rc = NM_OK; | |
205 int bytes_left = len; | |
206 int bytes_read; | |
207 int total_bytes = 0; | |
208 int retry = 10; | |
209 | |
210 if (conn == NULL || buff == NULL) | |
211 return NMERR_BAD_PARM; | |
212 | |
213 /* Keep reading until buffer is full */ | |
214 while (bytes_left) { | |
215 bytes_read = nm_tcp_read(conn, &buff[total_bytes], bytes_left); | |
216 if (bytes_read > 0) { | |
217 bytes_left -= bytes_read; | |
218 total_bytes += bytes_read; | |
219 } else { | |
220 if (errno == EAGAIN) { | |
221 if (--retry == 0) { | |
222 rc = NMERR_TCP_READ; | |
223 break; | |
224 } | |
225 #ifdef _WIN32 | |
226 Sleep(1000); | |
227 #else | |
228 usleep(1000); | |
229 #endif | |
230 } else { | |
231 rc = NMERR_TCP_READ; | |
232 break; | |
233 } | |
234 } | |
235 } | |
236 return rc; | |
237 } | |
238 | |
239 NMERR_T | |
240 nm_write_fields(NMConn * conn, NMField * fields) | |
241 { | |
242 NMERR_T rc = NM_OK; | |
243 NMField *field; | |
244 char *value = NULL; | |
245 char *method = NULL; | |
246 char buffer[512]; | |
247 int ret; | |
248 int bytes_to_send; | |
249 int val = 0; | |
250 | |
251 if (conn == NULL || fields == NULL) { | |
252 return NMERR_BAD_PARM; | |
253 } | |
254 | |
255 /* Format each field as valid "post" data and write it out */ | |
256 for (field = fields; (rc == NM_OK) && (field->tag); field++) { | |
257 | |
258 /* We don't currently handle binary types */ | |
259 if (field->method == NMFIELD_METHOD_IGNORE || | |
260 field->type == NMFIELD_TYPE_BINARY) { | |
261 continue; | |
262 } | |
263 | |
264 /* Write the field tag */ | |
265 bytes_to_send = g_snprintf(buffer, sizeof(buffer), "&tag=%s", field->tag); | |
266 ret = nm_tcp_write(conn, buffer, bytes_to_send); | |
267 if (ret < 0) { | |
268 rc = NMERR_TCP_WRITE; | |
269 } | |
270 | |
271 /* Write the field method */ | |
272 if (rc == NM_OK) { | |
273 method = encode_method(field->method); | |
274 bytes_to_send = g_snprintf(buffer, sizeof(buffer), "&cmd=%s", method); | |
275 ret = nm_tcp_write(conn, buffer, bytes_to_send); | |
276 if (ret < 0) { | |
277 rc = NMERR_TCP_WRITE; | |
278 } | |
279 } | |
280 | |
281 /* Write the field value */ | |
282 if (rc == NM_OK) { | |
283 switch (field->type) { | |
284 case NMFIELD_TYPE_UTF8: | |
285 case NMFIELD_TYPE_DN: | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
286 |
8675 | 287 value = url_escape_string((char *) field->value); |
288 bytes_to_send = g_snprintf(buffer, sizeof(buffer), | |
289 "&val=%s", value); | |
290 ret = nm_tcp_write(conn, buffer, bytes_to_send); | |
291 if (ret < 0) { | |
292 rc = NMERR_TCP_WRITE; | |
293 } | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
294 |
8675 | 295 g_free(value); |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
296 |
8675 | 297 break; |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
298 |
8675 | 299 case NMFIELD_TYPE_ARRAY: |
300 case NMFIELD_TYPE_MV: | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
301 |
8675 | 302 val = nm_count_fields((NMField *) field->value); |
303 bytes_to_send = g_snprintf(buffer, sizeof(buffer), | |
304 "&val=%u", val); | |
305 ret = nm_tcp_write(conn, buffer, bytes_to_send); | |
306 if (ret < 0) { | |
307 rc = NMERR_TCP_WRITE; | |
308 } | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
309 |
8675 | 310 break; |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
311 |
8675 | 312 default: |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
313 |
8675 | 314 bytes_to_send = g_snprintf(buffer, sizeof(buffer), |
315 "&val=%u", field->value); | |
316 ret = nm_tcp_write(conn, buffer, bytes_to_send); | |
317 if (ret < 0) { | |
318 rc = NMERR_TCP_WRITE; | |
319 } | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
320 |
8675 | 321 break; |
322 } | |
323 } | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
324 |
8675 | 325 /* Write the field type */ |
326 if (rc == NM_OK) { | |
327 bytes_to_send = g_snprintf(buffer, sizeof(buffer), | |
328 "&type=%u", field->type); | |
329 ret = nm_tcp_write(conn, buffer, bytes_to_send); | |
330 if (ret < 0) { | |
331 rc = NMERR_TCP_WRITE; | |
332 } | |
333 } | |
334 | |
335 /* If the field is a sub array then post its fields */ | |
336 if (rc == NM_OK && val > 0) { | |
337 if (field->type == NMFIELD_TYPE_ARRAY || | |
338 field->type == NMFIELD_TYPE_MV) { | |
339 | |
340 rc = nm_write_fields(conn, (NMField *) field->value); | |
341 | |
342 } | |
343 } | |
344 } | |
345 | |
346 return rc; | |
347 } | |
348 | |
349 NMERR_T | |
350 nm_send_request(NMConn * conn, char *cmd, NMField * fields, NMRequest ** req) | |
351 { | |
352 NMERR_T rc = NM_OK; | |
353 char buffer[512]; | |
354 int bytes_to_send; | |
355 int ret; | |
356 NMField *request = NULL; | |
357 | |
358 if (conn == NULL || cmd == NULL) | |
359 return NMERR_BAD_PARM; | |
360 | |
361 /* Write the post */ | |
362 bytes_to_send = g_snprintf(buffer, sizeof(buffer), | |
363 "POST /%s HTTP/1.0\r\n", cmd); | |
364 ret = nm_tcp_write(conn, buffer, bytes_to_send); | |
365 if (ret < 0) { | |
366 rc = NMERR_TCP_WRITE; | |
367 } | |
368 | |
369 /* Write headers */ | |
370 if (rc == NM_OK) { | |
371 if (strcmp("login", cmd) == 0) { | |
372 bytes_to_send = g_snprintf(buffer, sizeof(buffer), | |
373 "Host: %s:%d\r\n\r\n", conn->addr, conn->port); | |
374 ret = nm_tcp_write(conn, buffer, bytes_to_send); | |
375 if (ret < 0) { | |
376 rc = NMERR_TCP_WRITE; | |
377 } | |
378 } else { | |
379 bytes_to_send = g_snprintf(buffer, sizeof(buffer), "\r\n"); | |
380 ret = nm_tcp_write(conn, buffer, bytes_to_send); | |
381 if (ret < 0) { | |
382 rc = NMERR_TCP_WRITE; | |
383 } | |
384 } | |
385 } | |
386 | |
387 /* Add the transaction id to the request fields */ | |
388 if (rc == NM_OK) { | |
389 request = nm_copy_field_array(fields); | |
390 if (request) { | |
391 char *str = g_strdup_printf("%d", ++(conn->trans_id)); | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
392 |
8675 | 393 request = nm_add_field(request, NM_A_SZ_TRANSACTION_ID, 0, |
394 NMFIELD_METHOD_VALID, 0, | |
395 (guint32) str, NMFIELD_TYPE_UTF8); | |
396 } | |
397 } | |
398 | |
399 /* Send the request to the server */ | |
400 if (rc == NM_OK) { | |
401 rc = nm_write_fields(conn, request); | |
402 } | |
403 | |
404 /* Write the CRLF to terminate the data */ | |
405 if (rc == NM_OK) { | |
406 ret = nm_tcp_write(conn, "\r\n", strlen("\r\n")); | |
407 if (ret < 0) { | |
408 rc = NMERR_TCP_WRITE; | |
409 } | |
410 } | |
411 | |
412 /* Create a request struct and return it */ | |
413 if (rc == NM_OK) { | |
414 *req = nm_create_request(cmd, conn->trans_id, time(0)); | |
415 } | |
416 | |
417 if (request != NULL) { | |
418 nm_free_fields(&request); | |
419 } | |
420 | |
421 return rc; | |
422 } | |
423 | |
424 NMERR_T | |
425 nm_read_header(NMConn * conn) | |
426 { | |
427 NMERR_T rc = NM_OK; | |
428 char buffer[512]; | |
429 char *ptr = NULL; | |
430 int i; | |
431 char rtn_buf[8]; | |
432 int rtn_code = 0; | |
433 | |
434 if (conn == NULL) | |
435 return NMERR_BAD_PARM; | |
436 | |
437 *buffer = '\0'; | |
438 rc = read_line(conn, buffer, sizeof(buffer)); | |
439 if (rc == NM_OK) { | |
440 | |
441 /* Find the return code */ | |
442 ptr = strchr(buffer, ' '); | |
443 if (ptr != NULL) { | |
444 ptr++; | |
445 | |
446 i = 0; | |
447 while (isdigit(*ptr) && (i < 3)) { | |
448 rtn_buf[i] = *ptr; | |
449 i++; | |
450 ptr++; | |
451 } | |
452 rtn_buf[i] = '\0'; | |
8684
046dd8ef2920
[gaim-migrate @ 9437]
Christian Hammond <chipx86@chipx86.com>
parents:
8675
diff
changeset
|
453 |
8675 | 454 if (i > 0) |
455 rtn_code = atoi(rtn_buf); | |
456 } | |
457 } | |
458 | |
459 /* Finish reading header, in the future we might want to do more processing here */ | |
460 /* TODO: handle more general redirects in the future */ | |
461 while ((rc == NM_OK) && (strcmp(buffer, "\r\n") != 0)) { | |
462 rc = read_line(conn, buffer, sizeof(buffer)); | |
463 } | |
464 | |
465 if (rc == NM_OK && rtn_code == 301) { | |
466 conn->use_ssl = TRUE; | |
467 conn->redirect = TRUE; | |
468 rc = NMERR_SSL_REDIRECT; | |
469 } | |
470 | |
471 return rc; | |
472 } | |
473 | |
474 NMERR_T | |
475 nm_read_fields(NMConn * conn, int count, NMField ** fields) | |
476 { | |
477 NMERR_T rc = NM_OK; | |
478 guint8 type; | |
479 guint8 method; | |
480 guint32 val; | |
481 char tag[64]; | |
482 NMField *sub_fields = NULL; | |
483 char *str = NULL; | |
484 | |
485 if (conn == NULL || fields == NULL) | |
486 return NMERR_BAD_PARM; | |
487 | |
488 do { | |
489 if (count != -1) { | |
490 count--; | |
491 } | |
492 | |
493 /* Read the field type, method, and tag */ | |
494 rc = nm_read_all(conn, &type, sizeof(type)); | |
495 if (rc != NM_OK || type == 0) | |
496 break; | |
497 | |
498 rc = nm_read_all(conn, &method, sizeof(method)); | |
499 if (rc != NM_OK) | |
500 break; | |
501 | |
502 rc = nm_read_all(conn, (char *) &val, sizeof(val)); | |
503 if (rc != NM_OK) | |
504 break; | |
505 | |
506 if (val > sizeof(tag)) { | |
507 rc = NMERR_PROTOCOL; | |
508 break; | |
509 } | |
510 | |
511 rc = nm_read_all(conn, tag, val); | |
512 if (rc != NM_OK) | |
513 break; | |
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) */ | |
518 rc = nm_read_all(conn, (char *) &val, sizeof(val)); | |
519 if (rc != NM_OK) | |
520 break; | |
521 | |
522 if (val > 0) { | |
523 rc = nm_read_fields(conn, val, &sub_fields); | |
524 if (rc != NM_OK) | |
525 break; | |
526 } | |
527 | |
528 *fields = nm_add_field(*fields, tag, 0, method, 0, | |
529 (guint32) sub_fields, type); | |
530 | |
531 sub_fields = NULL; | |
532 | |
533 } else if (type == NMFIELD_TYPE_UTF8 || type == NMFIELD_TYPE_DN) { | |
534 | |
535 /* Read the string (first read the length) */ | |
536 rc = nm_read_all(conn, (char *) &val, sizeof(val)); | |
537 if (rc != NM_OK) | |
538 break; | |
539 | |
540 if (val > 0) { | |
541 str = g_new0(char, val + 1); | |
542 | |
543 rc = nm_read_all(conn, str, val); | |
544 if (rc != NM_OK) | |
545 break; | |
546 } | |
547 | |
548 *fields = nm_add_field(*fields, tag, 0, method, 0, | |
549 (guint32) str, type); | |
550 str = NULL; | |
551 } else { | |
552 | |
553 /* Read the numerical value */ | |
554 rc = nm_read_all(conn, (char *) &val, sizeof(val)); | |
555 if (rc != NM_OK) | |
556 break; | |
557 | |
558 *fields = nm_add_field(*fields, tag, 0, method, 0, val, type); | |
559 } | |
560 | |
561 } while ((type != 0) && (count != 0)); | |
562 | |
563 | |
564 if (str != NULL) { | |
565 g_free(str); | |
566 } | |
567 | |
568 if (sub_fields != NULL) { | |
569 nm_free_fields(&sub_fields); | |
570 } | |
571 | |
572 return rc; | |
573 } | |
574 | |
575 void | |
576 nm_conn_add_request_item(NMConn * conn, NMRequest * request) | |
577 { | |
578 if (conn == NULL || request == NULL) | |
579 return; | |
580 | |
581 nm_request_add_ref(request); | |
582 conn->requests = g_slist_append(conn->requests, request); | |
583 } | |
584 | |
585 void | |
586 nm_conn_remove_request_item(NMConn * conn, NMRequest * request) | |
587 { | |
588 if (conn == NULL || request == NULL) | |
589 return; | |
590 | |
591 conn->requests = g_slist_remove(conn->requests, request); | |
592 nm_release_request(request); | |
593 } | |
594 | |
595 NMRequest * | |
596 nm_conn_find_request(NMConn * conn, int trans_id) | |
597 { | |
598 NMRequest *req = NULL; | |
599 GSList *itr = NULL; | |
600 | |
601 if (conn == NULL) | |
602 return NULL; | |
603 | |
604 itr = conn->requests; | |
605 while (itr) { | |
606 req = (NMRequest *) itr->data; | |
607 if (req != NULL && nm_request_get_trans_id(req) == trans_id) { | |
608 return req; | |
609 } | |
610 itr = g_slist_next(itr); | |
611 } | |
612 return NULL; | |
613 } | |
614 | |
615 const char * | |
616 nm_conn_get_addr(NMConn * conn) | |
617 { | |
618 if (conn == NULL) | |
619 return NULL; | |
620 else | |
621 return conn->addr; | |
622 } | |
623 | |
624 int | |
625 nm_conn_get_port(NMConn * conn) | |
626 { | |
627 if (conn == NULL) | |
628 return -1; | |
629 else | |
630 return conn->port; | |
631 } |