annotate src/protocols/novell/nmconn.c @ 8700:ddd2bf87fe8d

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