void buffer_push(ProfBuff buffer, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message) { ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t)); e->show_char = show_char; e->flags = flags; e->attrs = attrs; e->date_fmt = malloc(strlen(date_fmt)+1); strcpy(e->date_fmt, date_fmt); e->from = malloc(strlen(from)+1); strcpy(e->from, from); e->message = malloc(strlen(message)+1); strcpy(e->message, message); if (g_slist_length(buffer->entries) == BUFF_SIZE) { _free_entry(buffer->entries->data); buffer->entries = g_slist_delete_link(buffer->entries, buffer->entries); } buffer->entries = g_slist_append(buffer->entries, e); }
static void _free_state(struct vparse_state *state) { buf_free(&state->buf); _free_card(state->card); _free_entry(state->entry); _free_param(state->param); if (state->multival) strarray_free(state->multival); if (state->multiparam) strarray_free(state->multiparam); memset(state, 0, sizeof(struct vparse_state)); }
static void _free_card(struct vparse_card *card) { struct vparse_card *cardnext; for (; card; card = cardnext) { cardnext = card->next; free(card->type); _free_entry(card->properties); _free_card(card->objects); free(card); } }
EXPORTED void vparse_delete_entries(struct vparse_card *card, const char *group, const char *name) { struct vparse_entry **entryp = &card->properties; while (*entryp) { struct vparse_entry *entry = *entryp; if ((!group || !strcasecmpsafe(entry->group, group)) && !strcasecmpsafe(entry->name, name)) { *entryp = entry->next; entry->next = NULL; /* so free doesn't walk the chain */ _free_entry(entry); } else { entryp = &((*entryp)->next); } } }
void buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt) { ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t)); e->show_char = show_char; e->pad_indent = pad_indent; e->flags = flags; e->theme_item = theme_item; e->time = g_date_time_ref(time); e->from = from ? strdup(from) : NULL; e->message = strdup(message); e->receipt = receipt; if (g_slist_length(buffer->entries) == BUFF_SIZE) { _free_entry(buffer->entries->data); buffer->entries = g_slist_delete_link(buffer->entries, buffer->entries); } buffer->entries = g_slist_append(buffer->entries, e); }
static int _parse_vcard(struct vparse_state *state, struct vparse_card *card, int only_one) { struct vparse_card **subp = &card->objects; struct vparse_entry **entryp = &card->properties; struct vparse_card *sub; const char *cardstart = state->p; const char *entrystart; int r; while (*state->p) { /* whitespace is very skippable before AND afterwards */ if (*state->p == '\r' || *state->p == '\n' || *state->p == ' ' || *state->p == '\t') { INC(1); continue; } entrystart = state->p; MAKE(state->entry, vparse_entry); r = _parse_entry(state); if (r) return r; if (!strcasecmp(state->entry->name, "begin")) { /* shouldn't be any params */ if (state->entry->params) { state->itemstart = entrystart; return PE_BEGIN_PARAMS; } /* only possible if some idiot passes 'begin' as * multivalue field name */ if (state->entry->multivalue) { state->itemstart = entrystart; return PE_BEGIN_PARAMS; } MAKE(sub, vparse_card); sub->type = strdup(state->entry->v.value); _free_entry(state->entry); state->entry = NULL; /* we must stitch it in first, because state won't hold it */ *subp = sub; subp = &sub->next; r = _parse_vcard(state, sub, /*only_one*/0); if (r) return r; if (only_one) return 0; } else if (!strcasecmp(state->entry->name, "end")) { /* shouldn't be any params */ if (state->entry->params) { state->itemstart = entrystart; return PE_BEGIN_PARAMS; } /* only possible if some idiot passes 'end' as * multivalue field name */ if (state->entry->multivalue) { state->itemstart = entrystart; return PE_BEGIN_PARAMS; } if (!card->type) { /* no type means we're at the top level, haven't seen a BEGIN! */ state->itemstart = cardstart; return PE_MISMATCHED_CARD; } if (strcasecmp(state->entry->v.value, card->type)) { /* special case mismatched card, the "start" was the start of * the card */ state->itemstart = cardstart; return PE_MISMATCHED_CARD; } _free_entry(state->entry); state->entry = NULL; return 0; } else { /* it's a parameter on this one */ *entryp = state->entry; entryp = &state->entry->next; state->entry = NULL; } } if (card->type) return PE_FINISHED_EARLY; return 0; }