Commit 67432176 6743217693a0d837a62b364209c1a6a1edbc2de0 by Sergey Poznyakoff

(sieve_vlist_do, sieve_vlist_compare): New functions.

1 parent a5be4691
...@@ -338,6 +338,7 @@ tag_printer (sieve_runtime_tag_t *val, struct debug_data *dbg) ...@@ -338,6 +338,7 @@ tag_printer (sieve_runtime_tag_t *val, struct debug_data *dbg)
338 sieve_debug_internal (dbg->printer, dbg->data, ")"); 338 sieve_debug_internal (dbg->printer, dbg->data, ")");
339 } 339 }
340 sieve_debug_internal (dbg->printer, dbg->data, " "); 340 sieve_debug_internal (dbg->printer, dbg->data, " ");
341 return 0;
341 } 342 }
342 343
343 void 344 void
...@@ -370,4 +371,64 @@ sieve_mark_deleted (message_t msg, int deleted) ...@@ -370,4 +371,64 @@ sieve_mark_deleted (message_t msg, int deleted)
370 return rc; 371 return rc;
371 } 372 }
372 373
374 int
375 sieve_vlist_do (sieve_value_t *val, list_action_t *ac, void *data)
376 {
377 switch (val->type)
378 {
379 case SVT_VALUE_LIST:
380 case SVT_STRING_LIST:
381 return list_do (val->v.list, ac, data);
382
383 default:
384 return -1;
385 }
386 }
387
388 struct comp_data {
389 sieve_value_t *val;
390 sieve_comparator_t comp;
391 sieve_retrieve_t retr;
392 void *data;
393 };
394
395 struct comp_data2 {
396 char *sample;
397 sieve_comparator_t comp;
398 };
399
400 int
401 _comp_action2 (void *item, void *data)
402 {
403 struct comp_data2 *cp = data;
404 return cp->comp (item, cp->sample);
405 }
406
407 int
408 _comp_action (void *item, void *data)
409 {
410 struct comp_data *cp = data;
411 struct comp_data2 d;
412 int rc;
413
414 if (cp->retr (item, cp->data, &d.sample))
415 return 0;
416 d.comp = cp->comp;
417 rc = sieve_vlist_do (cp->val, _comp_action2, &d);
418 free (d.sample);
419 return rc;
420 }
421
422 int
423 sieve_vlist_compare (sieve_value_t *a, sieve_value_t *b,
424 sieve_comparator_t comp, sieve_retrieve_t retr,
425 void *data)
426 {
427 struct comp_data d;
373 428
429 d.comp = comp;
430 d.retr = retr;
431 d.data = data;
432 d.val = b;
433 return sieve_vlist_do (a, _comp_action, &d);
434 }
......