static inline int add_event_hf(dstring_t *buf, int event_package) { dstr_append_zt(buf, "Event: "); dstr_append_zt(buf, event_package2str(event_package)); dstr_append_zt(buf, "\r\n"); return 0; }
static inline int create_headers(struct watcher* _w, str *dst, str *content_type) { dstring_t buf; time_t t; int err = 0; dstr_init(&buf, 256); str_clear(dst); /* required by RFC 3261 */ dstr_append_zt(&buf, "Max-Forwards: 70\r\n"); /* Event header */ dstr_append_zt(&buf, "Event: "); dstr_append_zt(&buf, event_package2str(_w->event_package)); dstr_append_zt(&buf, "\r\n"); /* Content-Type header */ /* content types can have dynamical parameters (multipart/related) * => don't generate them "staticaly"; use values created in the * time of document creation */ if (!is_str_empty(content_type)) { /* documents without body doesn't need it */ dstr_append_zt(&buf, "Content-Type: "); dstr_append_str(&buf, content_type); dstr_append_zt(&buf, "\r\n"); } /* Contact header */ if (is_str_empty(&_w->server_contact)) { LOG(L_WARN, "add_contact_hf(): Can't add empty contact to NOTIFY.\n"); } else { dstr_append_zt(&buf, "Contact: "); dstr_append_str(&buf, &_w->server_contact); dstr_append_zt(&buf, "\r\n"); } /* Subscription-State header */ if (_w->expires) t = _w->expires - time(0); else t = 0; if (add_subs_state_hf(&buf, _w->status, t) < 0) { LOG(L_ERR, "create_headers(): Error while adding Subscription-State\n"); dstr_destroy(&buf); return -3; } err = dstr_get_str(&buf, dst); dstr_destroy(&buf); return err; }
static int set_watcher_db_data(presentity_t *_p, watcher_t *watcher, db_key_t *cols, db_val_t *vals, int *col_cnt, str *dialog_str /* destination for dialog string -> must be freed after ! */ ) { int n_cols = 0; char *package = (char*)event_package2str(watcher->event_package); str dialog; /* serialized dialog */ str_clear(dialog_str); if (dlg_func.dlg2str(watcher->dialog, &dialog) != 0) { LOG(L_ERR, "Error while serializing dialog\n"); return -1; } cols[n_cols] = col_w_uri; vals[n_cols].type = DB_STR; vals[n_cols].nul = 0; vals[n_cols].val.str_val = watcher->uri; n_cols++; cols[n_cols] = col_package; vals[n_cols].type = DB_STR; vals[n_cols].nul = 0; vals[n_cols].val.str_val.s = package; vals[n_cols].val.str_val.len = strlen(package); n_cols++; cols[n_cols] = col_s_id; vals[n_cols].type = DB_STR; vals[n_cols].nul = 0; vals[n_cols].val.str_val = watcher->id; n_cols++; cols[n_cols] = col_status; vals[n_cols].type = DB_STR; vals[n_cols].nul = 0; vals[n_cols].val.str_val = watcher_status_names[watcher->status]; n_cols++; cols[n_cols] = col_event; vals[n_cols].type = DB_STR; vals[n_cols].nul = 0; vals[n_cols].val.str_val = watcher_event_names[watcher->event]; n_cols++; cols[n_cols] = col_display_name; vals[n_cols].type = DB_STR; vals[n_cols].nul = 0; vals[n_cols].val.str_val.s = watcher->display_name.s; vals[n_cols].val.str_val.len = watcher->display_name.len; n_cols++; cols[n_cols] = col_accepts; vals[n_cols].type = DB_INT; vals[n_cols].nul = 0; vals[n_cols].val.int_val = watcher->preferred_mimetype; n_cols++; cols[n_cols] = col_expires; vals[n_cols].type = DB_DATETIME; vals[n_cols].nul = 0; vals[n_cols].val.time_val = watcher->expires; n_cols++; cols[n_cols] = col_dialog; vals[n_cols].type = DB_BLOB; vals[n_cols].nul = 0; vals[n_cols].val.blob_val = dialog; n_cols++; cols[n_cols] = col_server_contact; vals[n_cols].type = DB_STR; vals[n_cols].nul = 0; vals[n_cols].val.str_val = watcher->server_contact; n_cols++; cols[n_cols] = col_pres_id; vals[n_cols].type = DB_STR; vals[n_cols].nul = 0; vals[n_cols].val.str_val = _p->pres_id; n_cols++; cols[n_cols] = col_doc_index; vals[n_cols].type = DB_INT; vals[n_cols].nul = 0; vals[n_cols].val.int_val = watcher->document_index; n_cols++; *col_cnt = n_cols; if (dialog_str) *dialog_str = dialog; return 0; }