comparison src/pop3/pop3-client.c @ 22702:024c9456f8e5

pop3: Simplify logout format variable handling
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Mon, 04 Dec 2017 11:15:15 +0200
parents b4c9f96470ca
children fe760efc829a
comparison
equal deleted inserted replaced
22701:8dcf3b113b6d 22702:024c9456f8e5
517 } 517 }
518 } 518 }
519 519
520 static const char *client_stats(struct client *client) 520 static const char *client_stats(struct client *client)
521 { 521 {
522 static struct var_expand_table static_tab[] = { 522 const char *uidl_change = "";
523 { 'p', NULL, "top_bytes" }, 523 if (var_has_key(client->set->pop3_logout_format,
524 { 't', NULL, "top_count" }, 524 'o', "uidl_change"))
525 { 'b', NULL, "retr_bytes" }, 525 uidl_change = client_build_uidl_change_string(client);
526 { 'r', NULL, "retr_count" }, 526
527 { 'd', NULL, "deleted_count" }, 527 const struct var_expand_table tab[] = {
528 { 'm', NULL, "message_count" }, 528 { 'p', dec2str(client->top_bytes), "top_bytes" },
529 { 's', NULL, "message_bytes" }, 529 { 't', dec2str(client->top_count), "top_count" },
530 { 'i', NULL, "input" }, 530 { 'b', dec2str(client->retr_bytes), "retr_bytes" },
531 { 'o', NULL, "output" }, 531 { 'r', dec2str(client->retr_count), "retr_count" },
532 { 'u', NULL, "uidl_change" }, 532 { 'd', !client->delete_success ? "0" :
533 { '\0', NULL, "session" }, 533 dec2str(client->deleted_count), "deleted_count" },
534 { 'd', NULL, "deleted_bytes" }, 534 { 'm', dec2str(client->messages_count), "message_count" },
535 { 's', dec2str(client->total_size), "message_bytes" },
536 { 'i', dec2str(client->input->v_offset), "input" },
537 { 'o', dec2str(client->output->offset), "output" },
538 { 'u', uidl_change, "uidl_change" },
539 { '\0', client->session_id, "session" },
540 { 'd', !client->delete_success ? "0" :
541 dec2str(client->deleted_size), "deleted_bytes" },
535 { '\0', NULL, NULL } 542 { '\0', NULL, NULL }
536 }; 543 };
537 struct var_expand_table *tab;
538 string_t *str;
539
540 tab = t_malloc(sizeof(static_tab));
541 memcpy(tab, static_tab, sizeof(static_tab));
542
543 tab[0].value = dec2str(client->top_bytes);
544 tab[1].value = dec2str(client->top_count);
545 tab[2].value = dec2str(client->retr_bytes);
546 tab[3].value = dec2str(client->retr_count);
547 tab[4].value = client->delete_success ?
548 dec2str(client->deleted_count) : "0";
549 tab[5].value = dec2str(client->messages_count);
550 tab[6].value = dec2str(client->total_size);
551 tab[7].value = dec2str(client->input->v_offset);
552 tab[8].value = dec2str(client->output->offset);
553 if (var_has_key(client->set->pop3_logout_format,
554 tab[9].key, tab[9].long_key))
555 tab[9].value = client_build_uidl_change_string(client);
556 else
557 tab[9].value = "";
558 tab[10].value = client->session_id;
559 tab[11].value = client->delete_success ?
560 dec2str(client->deleted_size) : "0";
561
562 str = t_str_new(128); 544 str = t_str_new(128);
563 var_expand(str, client->set->pop3_logout_format, tab); 545 var_expand(str, client->set->pop3_logout_format, tab);
564 return str_c(str); 546 return str_c(str);
565 } 547 }
566 548