Changeset 2142
- Timestamp:
- 06/13/07 09:17:12
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/libtinymail-camel/camel-lite/camel/camel-mime-parser.c (modified) (1 diff)
- trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.c (modified) (19 diffs)
- trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r2140 r2142 1 2007-06-13 Philip Van Hoof <pvanhoof@gnome.org> 2 3 * Added some extra locking into the camel-lite's POP3 code 4 1 5 2007-06-13 Philip Van Hoof <pvanhoof@gnome.org> 2 6 trunk/libtinymail-camel/camel-lite/camel/camel-mime-parser.c
r1943 r2142 1305 1305 { 1306 1306 int atleast = s->atleast, newatleast; 1307 register char *inptr ;1307 register char *inptr=NULL; 1308 1308 char *inend; 1309 1309 char *start; trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.c
r2139 r2142 61 61 camel_pop3_engine_init(CamelPOP3Engine *pe, CamelPOP3EngineClass *peclass) 62 62 { 63 pe->lock = g_new0 (GStaticRecMutex, 1); 64 g_static_rec_mutex_init (pe->lock); 65 63 66 e_dlist_init(&pe->active); 64 67 e_dlist_init(&pe->queue); … … 71 74 { 72 75 /* FIXME: Also flush/free any outstanding requests, etc */ 76 77 g_static_rec_mutex_lock (pe->lock); 73 78 74 79 if (pe->stream) … … 78 83 if (pe->apop) 79 84 g_free(pe->apop); 85 86 g_static_rec_mutex_unlock (pe->lock); 87 88 g_static_rec_mutex_free (pe->lock); 89 pe->lock = NULL; 80 90 } 81 91 … … 106 116 unsigned char *line, *apop, *apopend; 107 117 unsigned int len; 108 118 119 120 g_static_rec_mutex_lock (pe->lock); 121 109 122 /* first, read the greeting */ 110 123 if (camel_pop3_stream_line (pe->stream, &line, &len) == -1 111 || strncmp ((char *) line, "+OK", 3) != 0) 124 || strncmp ((char *) line, "+OK", 3) != 0) { 125 g_static_rec_mutex_unlock (pe->lock); 112 126 return -1; 113 127 } 128 114 129 if ((apop = (unsigned char *) strchr ((char *) line + 3, '<')) 115 130 && (apopend = (unsigned char *) strchr ((char *) apop, '>'))) { … … 121 136 122 137 pe->auth = g_list_prepend (pe->auth, &camel_pop3_password_authtype); 123 138 139 g_static_rec_mutex_unlock (pe->lock); 140 124 141 return 0; 125 142 } … … 141 158 142 159 pe = (CamelPOP3Engine *)camel_object_new(camel_pop3_engine_get_type ()); 160 161 g_static_rec_mutex_lock (pe->lock); 143 162 144 163 pe->stream = (CamelPOP3Stream *)camel_pop3_stream_new(source); … … 147 166 148 167 if (read_greeting (pe) == -1) { 168 g_static_rec_mutex_unlock (pe->lock); 149 169 camel_object_unref (pe); 150 170 return NULL; 151 171 } 152 172 153 173 get_capabilities (pe); 154 174 g_static_rec_mutex_unlock (pe->lock); 175 155 176 return pe; 156 177 } … … 167 188 { 168 189 g_return_if_fail (CAMEL_IS_POP3_ENGINE (engine)); 169 190 191 g_static_rec_mutex_lock (engine->lock); 170 192 get_capabilities (engine); 193 g_static_rec_mutex_unlock (engine->lock); 171 194 } 172 195 … … 193 216 int i; 194 217 CamelServiceAuthType *auth; 218 219 g_static_rec_mutex_lock (pe->lock); 195 220 196 221 dd(printf("cmd_capa\n")); … … 223 248 } 224 249 } while (ret>0); 250 251 g_static_rec_mutex_unlock (pe->lock); 225 252 } 226 253 … … 229 256 { 230 257 CamelPOP3Command *pc; 231 258 259 g_static_rec_mutex_lock (pe->lock); 260 232 261 if (!(pe->flags & CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS)) { 233 262 pc = camel_pop3_engine_command_new(pe, CAMEL_POP3_COMMAND_MULTI, cmd_capa, NULL, "CAPA\r\n"); … … 248 277 } 249 278 } 279 280 g_static_rec_mutex_unlock (pe->lock); 281 250 282 } 251 283 … … 255 287 { 256 288 257 #warning FIXME 258 if (!pe) { 259 g_warning ("FIXME: pe == NULL in %s", __FUNCTION__); 260 return FALSE; 261 } 289 g_static_rec_mutex_lock (pe->lock); 262 290 263 291 if (((pe->capa & CAMEL_POP3_CAP_PIPE) == 0 || (pe->sentlen + strlen(pc->data)) > CAMEL_POP3_SEND_LIMIT) 264 292 && pe->current != NULL) { 265 293 e_dlist_addtail(&pe->queue, (EDListNode *)pc); 294 g_static_rec_mutex_unlock (pe->lock); 266 295 return FALSE; 267 } else { 268 /* ??? */ 269 270 /* TNY TODO: Check online status here, else it will crash 271 Correction, it will not crash but will emit a SIGPIPE */ 272 273 if (camel_stream_write((CamelStream *)pe->stream, pc->data, strlen(pc->data)) == -1) { 274 e_dlist_addtail(&pe->queue, (EDListNode *)pc); 275 return FALSE; 276 } 277 278 pe->sentlen += strlen(pc->data); 279 280 pc->state = CAMEL_POP3_COMMAND_DISPATCHED; 281 282 if (pe->current == NULL) 283 pe->current = pc; 284 else 285 e_dlist_addtail(&pe->active, (EDListNode *)pc); 286 287 return TRUE; 288 } 296 } 297 298 /* TNY TODO: Check online status here, else it will crash 299 Correction, it will not crash but will emit a SIGPIPE */ 300 301 if (camel_stream_write((CamelStream *)pe->stream, pc->data, strlen(pc->data)) == -1) { 302 e_dlist_addtail(&pe->queue, (EDListNode *)pc); 303 g_static_rec_mutex_unlock (pe->lock); 304 return FALSE; 305 } 306 307 pe->sentlen += strlen(pc->data); 308 309 pc->state = CAMEL_POP3_COMMAND_DISPATCHED; 310 311 if (pe->current == NULL) 312 pe->current = pc; 313 else 314 e_dlist_addtail(&pe->active, (EDListNode *)pc); 315 316 g_static_rec_mutex_unlock (pe->lock); 317 318 return TRUE; 289 319 } 290 320 … … 297 327 CamelPOP3Command *pc, *pw, *pn; 298 328 299 #warning FIXME 300 if (!pe) { 301 g_warning ("FIXME: pe == NULL in %s", __FUNCTION__); 329 g_static_rec_mutex_lock (pe->lock); 330 331 if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK) { 332 g_static_rec_mutex_unlock (pe->lock); 302 333 return 0; 303 334 } 304 305 if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK) 335 336 pc = pe->current; 337 if (pc == NULL) { 338 g_static_rec_mutex_unlock (pe->lock); 306 339 return 0; 307 308 pc = pe->current; 309 if (pc == NULL) 310 return 0; 311 312 /* LOCK */ 340 } 313 341 314 342 if (camel_pop3_stream_line(pe->stream, &pe->line, &pe->linelen) == -1) … … 349 377 } 350 378 351 e_dlist_addtail(&pe->done, (EDListNode *)pc); 379 if (pc) 380 e_dlist_addtail(&pe->done, (EDListNode *)pc); 381 else 382 g_warning ("Unexpected, pc == NULL"); 352 383 353 384 if (pc && pc->data) … … 362 393 pw = (CamelPOP3Command *)pe->queue.head; 363 394 pn = pw->next; 364 while (pn) { 395 396 while (pn) 397 { 365 398 if (((pe->capa & CAMEL_POP3_CAP_PIPE) == 0 || (pe->sentlen + strlen(pw->data)) > CAMEL_POP3_SEND_LIMIT) 366 399 && pe->current != NULL) … … 384 417 } 385 418 386 /* UNLOCK */ 387 388 if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK) 419 if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK) { 420 g_static_rec_mutex_unlock (pe->lock); 389 421 return 0; 390 422 } 423 424 g_static_rec_mutex_unlock (pe->lock); 391 425 return pe->current==NULL?0:1; 426 392 427 ioerror: 393 428 /* we assume all outstanding commands are gunna fail now */ … … 408 443 } 409 444 445 g_static_rec_mutex_unlock (pe->lock); 410 446 return -1; 411 447 } … … 435 471 camel_pop3_engine_command_free(CamelPOP3Engine *pe, CamelPOP3Command *pc) 436 472 { 437 #warning FIXME 438 if (!pe) { 439 g_warning ("FIXME: pe == NULL in %s", __FUNCTION__); 440 return; 441 } 442 473 g_static_rec_mutex_lock (pe->lock); 443 474 if (pe->current != pc) 444 475 e_dlist_remove((EDListNode *)pc); 445 g_free(pc->data); 476 g_free(pc->data); pc->data = NULL; 446 477 g_free(pc); 447 } 478 g_static_rec_mutex_unlock (pe->lock); 479 } trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.h
r1943 r2142 118 118 void *store; gboolean partial_happening; 119 119 gint type; gint param; 120 121 GStaticRecMutex *lock; 120 122 }; 121 123
