144 |
{ |
{ |
145 |
char buf[RESPONSE_BUF]; |
char buf[RESPONSE_BUF]; |
146 |
char *c, *m; |
char *c, *m; |
147 |
unsigned long f, blen, mlen; |
short f; |
148 |
|
unsigned int blen, mlen; |
149 |
|
|
150 |
f = blen = mlen = 0; |
f = blen = mlen = 0; |
151 |
|
|
162 |
while (*c && (isdigit(*c) || *c == ' ')) |
while (*c && (isdigit(*c) || *c == ' ')) |
163 |
*(m++) = *(c++); |
*(m++) = *(c++); |
164 |
*m = 0; |
*m = 0; |
165 |
} else { |
} else { /* Search results are continued from |
166 |
|
previous packet. */ |
167 |
c = buf; |
c = buf; |
168 |
blen = strlen(buf); |
blen = strlen(buf); |
169 |
mlen = strlen(*mesgs); |
mlen = strlen(*mesgs); |
186 |
*/ |
*/ |
187 |
int fetch_response(unsigned int tag) |
int fetch_response(unsigned int tag) |
188 |
{ |
{ |
|
int sa, sb, n, i, f; |
|
|
char s[6]; |
|
|
char *b; |
|
189 |
char buf[RESPONSE_BUF]; |
char buf[RESPONSE_BUF]; |
190 |
char hdrs[HEADERS_BUF]; |
char hdrs[HEADERS_BUF]; |
191 |
|
short f; |
192 |
|
unsigned int sa, sb, i, n; |
193 |
|
char s[8]; |
194 |
|
char *b; |
195 |
|
|
196 |
hdrs[0] = 0; |
hdrs[0] = 0; |
197 |
sa = sb = i = f = 0; |
sa = sb = i = f = 0; |
203 |
b = buf; |
b = buf; |
204 |
|
|
205 |
while (f || (b = strchr(b, '{'))) { |
while (f || (b = strchr(b, '{'))) { |
206 |
|
/* Headers are continued from previous packet. */ |
207 |
if (f) { |
if (f) { |
208 |
f = 0; |
f = 0; |
209 |
for (; i < HEADERS_BUF - 1 && i < sa - 2; i++) { |
for (; i < HEADERS_BUF - 1 && i < sa - 2; i++) { |
210 |
|
/* Continued in next packet. */ |
211 |
if (!*b) { |
if (!*b) { |
212 |
f = 1; |
f = 1; |
213 |
break; |
break; |
215 |
hdrs[i] = *(b++); |
hdrs[i] = *(b++); |
216 |
} |
} |
217 |
} else { |
} else { |
218 |
if (b == buf + RESPONSE_BUF - 1) { |
/* Left bracket is last byte of buffer. */ |
219 |
|
if (b == buf + RESPONSE_BUF - 2) { |
220 |
receive_response(buf); |
receive_response(buf); |
221 |
b = buf; |
b = buf; |
222 |
} |
} else |
223 |
sa = atoi(++b); |
b++; |
224 |
|
|
225 |
|
sa = atoi(b); |
226 |
|
|
227 |
|
/* Headers length may be continued in next packet. */ |
228 |
if (!(b = strchr(b, '}'))) { |
if (!(b = strchr(b, '}'))) { |
229 |
receive_response(buf); |
receive_response(buf); |
230 |
if (buf != (b = strchr(buf, '}'))) { |
if (buf != (b = strchr(buf, '}'))) { |
231 |
sb = atoi(buf); |
sb = atoi(buf); |
232 |
snprintf(s, 6, "%d%d", sa, sb); |
strncat(s, ultostr(sa, 10), 7); |
233 |
|
strncat(s, ultostr(sb, 10), 7); |
234 |
sa = atoi(s); |
sa = atoi(s); |
235 |
|
s[0] = 0; |
236 |
} |
} |
237 |
b += 3; |
b += 3; |
238 |
} else if ((n = RESPONSE_BUF - 1 - (b - buf)) < 3) { |
} else if ((n = RESPONSE_BUF - 1 - (b - buf)) < 3) { |