149 |
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, cred); |
curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, cred); |
150 |
g_free(cred); |
g_free(cred); |
151 |
} |
} |
152 |
} |
} else |
153 |
|
printf("gcvote: no proxy configured\n"); |
154 |
} |
} |
155 |
|
|
156 |
void gcvote_request_free(gcvote_request_t *request) { |
void gcvote_request_free(gcvote_request_t *request) { |
177 |
|
|
178 |
printf("gcvote: result handler\n"); |
printf("gcvote: result handler\n"); |
179 |
|
|
180 |
/* worker thread has already reduced its refcounter */ |
if(request->refcount < 2) { |
|
if(request->refcount < 1) { |
|
181 |
printf("gcvote: main app isn't listening anymore\n"); |
printf("gcvote: main app isn't listening anymore\n"); |
182 |
|
gcvote_request_free(request); |
183 |
return FALSE; |
return FALSE; |
184 |
} |
} |
185 |
|
|
186 |
if(request->res) { |
if(request->res) { |
187 |
printf("gcvote: curl failed\n"); |
printf("gcvote: curl failed\n"); |
188 |
request->cb(NULL, request->userdata); |
request->cb(NULL, request->userdata); |
189 |
|
gcvote_request_free(request); |
190 |
return FALSE; |
return FALSE; |
191 |
} |
} |
192 |
|
|
195 |
if(!request->mem.ptr || !request->mem.len) { |
if(!request->mem.ptr || !request->mem.len) { |
196 |
printf("gcvote: ignoring zero length reply\n"); |
printf("gcvote: ignoring zero length reply\n"); |
197 |
request->cb(NULL, request->userdata); |
request->cb(NULL, request->userdata); |
198 |
|
gcvote_request_free(request); |
199 |
return FALSE; |
return FALSE; |
200 |
} |
} |
201 |
|
|
209 |
/* nothing could be parsed, just give up */ |
/* nothing could be parsed, just give up */ |
210 |
if(!doc) { |
if(!doc) { |
211 |
request->cb(NULL, request->userdata); |
request->cb(NULL, request->userdata); |
212 |
|
gcvote_request_free(request); |
213 |
return FALSE; |
return FALSE; |
214 |
} |
} |
215 |
|
|
238 |
} else |
} else |
239 |
printf("gcvote: no vote found\n"); |
printf("gcvote: no vote found\n"); |
240 |
|
|
241 |
|
gcvote_request_free(request); |
242 |
return FALSE; |
return FALSE; |
243 |
} |
} |
244 |
|
|
303 |
CURL *curl = curl_easy_init(); |
CURL *curl = curl_easy_init(); |
304 |
if(!curl) { |
if(!curl) { |
305 |
curl_formfree(formpost); |
curl_formfree(formpost); |
|
gcvote_request_free(request); |
|
306 |
|
|
307 |
/* callback anyway, so main loop can also clean up */ |
/* callback anyway, so main loop can also clean up */ |
308 |
g_idle_add(gcvote_result_handler, request); |
g_idle_add(gcvote_result_handler, request); |
332 |
|
|
333 |
/* always cleanup */ |
/* always cleanup */ |
334 |
curl_easy_cleanup(curl); |
curl_easy_cleanup(curl); |
335 |
|
|
336 |
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &request->response); |
printf("gcvote: 1\n"); |
337 |
|
|
338 |
/* then cleanup the formpost chain */ |
/* then cleanup the formpost chain */ |
339 |
curl_formfree(formpost); |
curl_formfree(formpost); |
340 |
|
|
341 |
printf("gcvote: worker thread done\n"); |
printf("gcvote: 2\n"); |
|
gcvote_request_free(request); |
|
342 |
|
|
343 |
/* cause gtk main loop to handle result */ |
/* cause gtk main loop to handle result only if main loop */ |
344 |
g_idle_add(gcvote_result_handler, request); |
/* is still interested. Don't free request then, since the */ |
345 |
|
/* gcvote_result_handler will do this */ |
346 |
printf("gcvote: thread terminating\n"); |
if(request->refcount > 1) |
347 |
|
g_idle_add(gcvote_result_handler, request); |
348 |
|
else |
349 |
|
gcvote_request_free(request); |
350 |
|
|
351 |
|
printf("gcvote: worker thread done\n"); |
352 |
|
|
353 |
return NULL; |
return NULL; |
354 |
} |
} |
355 |
|
|
367 |
return NULL; |
return NULL; |
368 |
} |
} |
369 |
|
|
370 |
|
request->proxy = appdata->proxy; |
371 |
request->id += strlen(ID_PATTERN); |
request->id += strlen(ID_PATTERN); |
372 |
request->refcount = 2; // master and worker hold a reference |
request->refcount = 2; // master and worker hold a reference |
373 |
request->cb = cb; |
request->cb = cb; |