/* * Create a new watcher structure but do not write to database */ int new_watcher_no_wb(str* _uri, time_t _e, int event_package, int doc_type, dlg_t* _dlg, str *_dn, str *server_contact, str *id, watcher_t** _w) { watcher_t* watcher; int size; dbid_t dbid; str sid; /* Check parameters */ if (!_uri && !_dlg && !_w) { LOG(L_ERR, "new_watcher(): Invalid parameter value\n"); return -1; } if (!id) { /* generate new database/watcher id (needed for winfo documents!) */ generate_dbid(dbid); sid.s = dbid_strptr(dbid); sid.len = dbid_strlen(dbid); id = &sid; } /* Allocate memory buffer for watcher_t structure and uri string */ size = sizeof(watcher_t) + id->len + _uri->len + _dn->len + server_contact->len; watcher = (watcher_t*)mem_alloc(size); if (!watcher) { paerrno = PA_NO_MEMORY; ERR("No memory left (%d bytes)\n", size); return -1; } memset(watcher, 0, sizeof(watcher_t)); /* Copy ID string */ watcher->id.s = (char*)watcher + sizeof(watcher_t); str_cpy(&watcher->id, id); /* Copy uri string */ watcher->uri.s = after_str_ptr(&watcher->id); str_cpy(&watcher->uri, _uri); /* Copy display_name string */ watcher->display_name.s = after_str_ptr(&watcher->uri); str_cpy(&watcher->display_name, _dn); /* Copy server_contact string */ watcher->server_contact.s = after_str_ptr(&watcher->display_name); str_cpy(&watcher->server_contact, server_contact); watcher->document_index = 0; watcher->event_package = event_package; watcher->expires = _e; /* Expires value */ watcher->preferred_mimetype = doc_type; /* Accepted document type */ watcher->dialog = _dlg; /* Dialog handle */ watcher->event = WE_SUBSCRIBE; watcher->status = WS_PENDING; *_w = watcher; return 0; }
static int publish_presence(struct sip_msg* _m, struct presentity* presentity) { char *body = get_body(_m); int body_len = 0; int msg_expires = default_expires; time_t expires = 0; str etag; dbid_t generated_etag; int has_etag; presentity_info_t *p = NULL; int content_type = -1; if (_m->content_type) content_type = get_content_type(_m); if (_m->content_length) body_len = get_content_length(_m); if (_m->expires) { if (_m->expires->parsed) { msg_expires = ((exp_body_t*)_m->expires->parsed)->val; } } if (msg_expires > max_publish_expiration) msg_expires = max_publish_expiration; if (msg_expires != 0) expires = msg_expires + act_time; if (_m->sipifmatch) { if (_m->sipifmatch->parsed) etag = *(str*)_m->sipifmatch->parsed; else str_clear(&etag); has_etag = 1; } else { /* ETag was not set, generate a new one */ generate_dbid(generated_etag); etag.len = dbid_strlen(generated_etag); etag.s = dbid_strptr(generated_etag); has_etag = 0; } if (body_len > 0) { switch (content_type) { case MIMETYPE(APPLICATION,PIDFXML): if (parse_pidf_document(&p, body, body_len) != 0) { LOG(L_ERR, "can't parse PIDF document\n"); paerrno = PA_UNSUPP_DOC; /* ? PA_PARSE_ERR */ } break; case MIMETYPE(APPLICATION,CPIM_PIDFXML): if (parse_cpim_pidf_document(&p, body, body_len) != 0) { LOG(L_ERR, "can't parse CPIM-PIDF document\n"); paerrno = PA_UNSUPP_DOC; } break; default: LOG(L_ERR, "unsupported Content-Type 0x%x for PUBLISH handling\n", content_type); paerrno = PA_UNSUPP_DOC; } if (paerrno != PA_OK) return -1; } if (process_published_presentity_info(presentity, p, &etag, expires, has_etag) == 0) { /* add header fields into response */ add_expires_to_rpl(_m, msg_expires); add_etag_to_rpl(_m, &etag); } if (p) free_presentity_info(p); return 0; }