diff options
author | Mattias Andrée <maandree@kth.se> | 2021-04-02 16:24:55 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-04-02 16:24:55 +0200 |
commit | 63145b929b143cfc8858a220d3e1d7fc88f7031e (patch) | |
tree | ddcf0e8a0dd72e1e9abebc4a26214cae8cb88d9e /libcontacts_parse_contact.c | |
parent | First commit (diff) | |
download | libcontacts-63145b929b143cfc8858a220d3e1d7fc88f7031e.tar.gz libcontacts-63145b929b143cfc8858a220d3e1d7fc88f7031e.tar.bz2 libcontacts-63145b929b143cfc8858a220d3e1d7fc88f7031e.tar.xz |
Add block info
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libcontacts_parse_contact.c')
-rw-r--r-- | libcontacts_parse_contact.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/libcontacts_parse_contact.c b/libcontacts_parse_contact.c index da39432..a81a744 100644 --- a/libcontacts_parse_contact.c +++ b/libcontacts_parse_contact.c @@ -2,6 +2,22 @@ #include "common.h" +static time_t +gettime(const char *data) +{ + time_t ret = 0; + if (*data > '1' || '9' > *data) + return 0; + for (; isdigit(*data); data++) { + if (ret > (TIME_MAX - (*data & 15)) / 10) + return 0; + ret = ret * 10 + (*data & 15); + } + if (*data) + return 0; + return ret; +} + static char * getstr(char *data) { @@ -169,6 +185,7 @@ libcontacts_parse_contact(char *data, struct libcontacts_contact *contact) char *p, *q; size_t i; + time_t t; void *temp; int state = 0; @@ -358,6 +375,32 @@ libcontacts_parse_contact(char *data, struct libcontacts_contact *contact) } break; + } else if (!strcmp(p, "BLOCK:")) { + ADD(contact->blocks); + state = 8; + break; + case 8: + if (TEST(unindent(p), "SRV") && !contact->blocks[i]->service) { + if (!(contact->blocks[i]->service = strdup(getstr(p)))) + goto fail; + } else if (!strcmp(p, "OFF") && !contact->blocks[i]->shadow_block) { + contact->blocks[i]->shadow_block = LIBCONTACTS_BLOCK_OFF; + } else if (!strcmp(p, "BUSY") && !contact->blocks[i]->shadow_block) { + contact->blocks[i]->shadow_block = LIBCONTACTS_BLOCK_BUSY; + } else if (!strcmp(p, "IGNORE") && !contact->blocks[i]->shadow_block) { + contact->blocks[i]->shadow_block = LIBCONTACTS_BLOCK_IGNORE; + } else if (!strcmp(p, "EXPLICIT")) { + contact->blocks[i]->explicit = 1; + } else if (TEST(unindent(p), "ASK") && !contact->blocks[i]->soft_unblock && (t = gettime(p))) { + contact->blocks[i]->soft_unblock = t; + } else if (TEST(unindent(p), "REMOVE") && !contact->blocks[i]->hard_unblock && (t = gettime(p))) { + contact->blocks[i]->hard_unblock = t; + } else { + if (addstr(&contact->organisations[i]->unrecognised_data, getstr(p))) + goto fail; + } + break; + } else if (TEST(p, "BIRTH") && !contact->birthday) { contact->birthday = malloc(sizeof(*contact->birthday)); if (!contact->birthday) |