Skip to content

Commit a20a628

Browse files
committed
Switch from strings to bytes for NS data in protocol
1 parent 99de4fa commit a20a628

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

protocol

Submodule protocol updated 1 file

trawler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ typedef struct trequest {
6868
zframe_t *client ;
6969
/* reply being built for the response */
7070
Trawler__Reply reply;
71-
size_t reply_headers_len;
72-
size_t reply_response_len;
7371
/* arguments from client */
7472
int32_t id;
7573
method_t method;

trawlerd.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ int trawlerd_receive_request(zframe_t *client, Trawler__Request *preq,
195195
treq->reply.req_id = treq->id = preq->id;
196196
treq->method = preq->method;
197197
treq->path = strdup(preq->path);
198-
treq->reply.headers = NULL;
199-
treq->reply_headers_len = 0;
200-
treq->reply.response = NULL;
201-
treq->reply_response_len = 0;
198+
treq->reply.headers.data = NULL;
199+
treq->reply.headers.len = 0;
200+
treq->reply.response.data = NULL;
201+
treq->reply.response.len = 0;
202202
if( preq->query != NULL ) {
203203
treq->query = strdup(preq->query);
204204
} else {
@@ -263,7 +263,8 @@ int trawlerd_logout(trawler_t *trawler, const char *client_hex,
263263
static char *concat(const char *a, const char *b, const char *c,
264264
const char *d) {
265265
char *res = strdup(a);
266-
size_t total = strlen(res)+strlen(b)+strlen(c)+strlen(d);
266+
size_t total = strlen(res)
267+
+ (b?strlen(b):0) + (c?strlen(c):0) + (d?strlen(d):0);
267268
res = realloc(res,total+1);
268269
if(b) strcat(res, b);
269270
if(c) strcat(res, c);
@@ -296,6 +297,13 @@ int trawlerd_fulfill_request(zmq_socket_t src, zhash_t *sessions, trequest_t *re
296297
if( req->session != NULL ) {
297298
err |= curl_easy_setopt( ch, CURLOPT_COOKIE, req->session );
298299
}
300+
req->reply.has_response = true;
301+
if( req->headers ) {
302+
curl_easy_setopt( ch, CURLOPT_HEADERFUNCTION, trawlerd_headers_append);
303+
req->reply.has_headers = true;
304+
} else {
305+
curl_easy_setopt( ch, CURLOPT_HEADERFUNCTION, NULL );
306+
}
299307
err |= curl_easy_perform( ch );
300308
free(url);
301309
err |= curl_easy_getinfo( ch, CURLINFO_RESPONSE_CODE,
@@ -305,11 +313,11 @@ int trawlerd_fulfill_request(zmq_socket_t src, zhash_t *sessions, trequest_t *re
305313
return trawlerd_reply(src, req->client, &(req->reply));
306314
}
307315

308-
static inline int trawlerd_str_append( char **str, size_t *strlen,
316+
static inline int trawlerd_str_append( uint8_t **str, size_t *strlen,
309317
const size_t size, const size_t nmemb,
310318
void *stream) {
311-
char *cur = *str;
312-
char *new = realloc( cur, *strlen + size*nmemb );
319+
uint8_t *cur = *str;
320+
uint8_t *new = realloc( cur, *strlen + size*nmemb );
313321
memmove( new+*strlen, stream, size*nmemb );
314322
if( cur != new ) {
315323
*str = new;
@@ -320,15 +328,15 @@ static inline int trawlerd_str_append( char **str, size_t *strlen,
320328

321329
int trawlerd_headers_append(void *stream, size_t size, size_t nmemb,
322330
trequest_t *treq) {
323-
return trawlerd_str_append( &(treq->reply.headers),
324-
&(treq->reply_headers_len),
331+
return trawlerd_str_append( &(treq->reply.headers.data),
332+
&(treq->reply.headers.len),
325333
size, nmemb, stream );
326334
}
327335

328336
int trawlerd_response_append(void *stream, size_t size, size_t nmemb,
329337
trequest_t *treq) {
330-
return trawlerd_str_append( &(treq->reply.response),
331-
&(treq->reply_response_len),
338+
return trawlerd_str_append( &(treq->reply.response.data),
339+
&(treq->reply.response.len),
332340
size, nmemb, stream );
333341
}
334342

0 commit comments

Comments
 (0)