Пример #1
0
static int db_add_watcher(presentity_t *_p, watcher_t *watcher)
{
	str_t tmp;
	db_key_t query_cols[20];
	db_val_t query_vals[20];
	
	int n_query_cols = 0;

	if (!use_db) return 0;
	
	str_clear(&tmp);

	if (pa_dbf.use_table(pa_db, watcherinfo_table) < 0) {
		LOG(L_ERR, "db_add_watcher: Error in use_table\n");
		return -1;
	}
	
	if (set_watcher_db_data(_p, watcher, 
				query_cols, query_vals, &n_query_cols,
				&tmp) != 0) {
		return -1;
	}

	/* insert new record into database */
	if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0) {
		LOG(L_ERR, "db_add_watcher: Error while inserting watcher\n");
		str_free_content(&tmp);
		return -1;
	}
	str_free_content(&tmp);
	
	return 0;
}
Пример #2
0
int create_lpidf_document(presentity_info_t *p, str_t *dst, str_t *dst_content_type)
{
	dstring_t buf;
	int err;
	
	if (!dst) return -1;
	
	str_clear(dst);
	if (dst_content_type) str_clear(dst_content_type);

	if (!p) return -1;
	
	if (dst_content_type) {
		if (str_dup_zt(dst_content_type, "text/lpidf") < 0) {
			return -1;
		}
	}

/*	if (!p->first_tuple) return 0;*/	/* no tuples => nothing to say */ 
	
	dstr_init(&buf, 2048);
	
	doc_add_presentity(&buf, p);
	
	err = dstr_get_str(&buf, dst);
	dstr_destroy(&buf);
	
	if (err != 0) {
		str_free_content(dst);
		if (dst_content_type) str_free_content(dst_content_type);
	}
	
	return err;
}
Пример #3
0
static int prepare_winfo_notify(struct retr_buf **dst,
                                struct presentity* _p, struct watcher* _w,
                                pa_notify_cb_param_t *cbd)
{
    str doc = STR_NULL;
    str content_type = STR_NULL;
    str headers = STR_NULL;
    int res = 0;
    str body = STR_STATIC_INIT("");
    uac_req_t	uac_r;

    switch (_w->preferred_mimetype) {
    case DOC_WINFO:
        create_winfo_document(_p, _w, &doc, &content_type);
        DEBUG("winfo document created\n");
        break;
    /* other formats ? */
    default:
        ERR("unknow doctype\n");
        return -1;
    }

    if (create_headers(_w, &headers, &content_type) < 0) {
        ERR("Error while adding headers\n");
        str_free_content(&doc);
        str_free_content(&content_type);
        return -7;
    }

    if (!is_str_empty(&doc)) body = doc;
    /* res = tmb.t_request_within(&notify, &headers, &body, _w->dialog, 0, 0); */
    set_uac_req(&uac_r,
                &notify,
                &headers,
                &body,
                _w->dialog,
                TMCB_LOCAL_COMPLETED,
                pa_notify_cb,
                cbd
               );
    res = tmb.prepare_request_within(&uac_r, dst);
    if (res < 0) {
        ERR("Can't send watcherinfo notification (%d)\n", res);
    }
    else {
        _w->document_index++; /* increment index for next document */
    }

    str_free_content(&doc);
    str_free_content(&headers);
    str_free_content(&content_type);

    return res;
}
Пример #4
0
int send_winfo_notify_offline(struct presentity* _p,
                              struct watcher* _w,
                              offline_winfo_t *info,
                              transaction_cb completion_cb, void* cbp)
{
    str doc = STR_NULL;
    str content_type = STR_NULL;
    str headers = STR_NULL;
    str body = STR_STATIC_INIT("");
    uac_req_t	uac_r;

    switch (_w->preferred_mimetype) {
    case DOC_WINFO:
        create_winfo_document_offline(_p, _w, info, &doc, &content_type);
        break;
    /* other formats ? */
    default:
        ERR("send_winfo_notify: unknow doctype\n");
        return -1;
    }

    if (create_headers(_w, &headers, &content_type) < 0) {
        ERR("send_winfo_notify(): Error while adding headers\n");
        str_free_content(&doc);
        str_free_content(&content_type);
        return -7;
    }

    if (!is_str_empty(&doc)) body = doc;
    set_uac_req(&uac_r,
                &notify,
                &headers,
                &body,
                _w->dialog,
                TMCB_LOCAL_COMPLETED,
                completion_cb,
                cbp
               );
    tmb.t_request_within(&uac_r);

    str_free_content(&doc);
    str_free_content(&headers);
    str_free_content(&content_type);

    _w->document_index++; /* increment index for next document */

    if (use_db) db_update_watcher(_p, _w); /* dialog and index have changed */

    return 0;
}
Пример #5
0
/**
 * Encode a dlg_t into a binary form
 * @param x - binary data to append to
 * @param d - the dlg_t to encode
 * @returns 1 on succcess or 0 on error
 */
int bin_encode_dlg_t(bin_data *x,dlg_t *d)
{
	str s={0,0};
	if (d){
		if (dialogb.dlg2str(d,&s)!=0) goto error;
	}
	if (!bin_encode_str(x,&s)) goto error;
	str_free_content(&s);
	return 1;
error:
	LOG(L_ERR,"ERR:"M_NAME":bin_encode_dlg_t: Error while encoding.\n");
	if (s.s) str_free_content(&s);
	return 0;		
}
Пример #6
0
void rls_free(rl_subscription_t *s)
{
	int i, cnt;
	virtual_subscription_t *vs;
	
	if (!s) return;

	if (use_db) rls_db_remove(s);
	
	cnt = ptr_vector_size(&s->vs);
	for (i = 0; i < cnt; i++) {
		vs = ptr_vector_get(&s->vs, i);
		if (!vs) continue;
		vs_free(vs);
	}

	if (s->type == rls_external_subscription) {
		sm_release_subscription_nolock(rls_manager, &s->u.external);
		
		/* free ONLY for external subscriptions */
		free_xcap_params_content(&s->xcap_params);
	}
	else {
		/* release_internal_subscription(s); */
		/* don't free xcap_params */
	}

	ptr_vector_destroy(&s->vs);
	str_free_content(&s->from_uid);
	mem_free(s);
}
Пример #7
0
int prepare_unauthorized_notify(struct retr_buf **dst,
                                struct presentity* _p, struct watcher* _w,
                                pa_notify_cb_param_t *cbd)
{
    str headers = STR_NULL;
    str body = STR_STATIC_INIT("");
    int res;
    unc_req_t	uac_r;

    /* send notifications to unauthorized (pending) watchers */
    if (create_headers(_w, &headers, NULL) < 0) {
        LOG(L_ERR, "notify_unauthorized_watcher(): Error while adding headers\n");
        return -7;
    }

    set_uac_req(&uac_r,
                &notify,
                &headers,
                &body,
                _w->dialog,
                TMCB_LOCAL_COMPLETED,
                pa_notify_cb,
                cbd
               );
    res = tmb.prepare_request_within(&uac_r, dst);
    if (res < 0) {
        ERR("Can't send NOTIFY (%d) in dlg %.*s, %.*s, %.*s\n", res,
            FMT_STR(_w->dialog->id.call_id),
            FMT_STR(_w->dialog->id.rem_tag),
            FMT_STR(_w->dialog->id.loc_tag));
    }

    str_free_content(&headers);


    return res;
}
Пример #8
0
void free_tuple_change_info_content(tuple_change_info_t *i)
{
	str_free_content(&i->user);
	str_free_content(&i->contact);
}
Пример #9
0
static inline int db_add_presentity(presentity_t* presentity)
{
	db_key_t query_cols[6];
	db_val_t query_vals[6];
	int n_query_cols = 0;
	int res;
	str str_xcap_params;
	
	query_cols[0] = col_uri;
	query_vals[0].type = DB_STR;
	query_vals[0].nul = 0;
	query_vals[0].val.str_val = presentity->data.uri;
	n_query_cols++;

	query_cols[n_query_cols] = col_pdomain;
	query_vals[n_query_cols].type = DB_STR;
	query_vals[n_query_cols].nul = 0;
	query_vals[n_query_cols].val.str_val = *presentity->pdomain->name;
	n_query_cols++;
	
	query_cols[n_query_cols] = col_uid;
	query_vals[n_query_cols].type = DB_STR;
	query_vals[n_query_cols].nul = 0;
	query_vals[n_query_cols].val.str_val = presentity->uuid;
	n_query_cols++;
	
	query_cols[n_query_cols] = col_pres_id;
	query_vals[n_query_cols].type = DB_STR;
	query_vals[n_query_cols].nul = 0;
	query_vals[n_query_cols].val.str_val = presentity->pres_id;
	n_query_cols++;
	
	/*query_cols[n_query_cols] = "id_cntr";
	query_vals[n_query_cols].type = DB_INT;
	query_vals[n_query_cols].nul = 0;
	query_vals[n_query_cols].val.int_val = presentity->id_cntr;
	n_query_cols++;*/

	/* store XCAP parameters with presentity */
	if (xcap_params2str(&str_xcap_params, &presentity->xcap_params) != 0) {
		LOG(L_ERR, "Error while serializing xcap params\n");
		return -1;
	}
	query_cols[n_query_cols] = col_xcap_params;
	query_vals[n_query_cols].type = DB_BLOB;
	query_vals[n_query_cols].nul = 0;
	query_vals[n_query_cols].val.blob_val = str_xcap_params;
	n_query_cols++;
	
	res = 0;
	
	if (pa_dbf.use_table(pa_db, presentity_table) < 0) {
		ERR("Error in use_table\n");
		res = -1;
	}

	/* insert new record into database */
	if (res == 0) {
		if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0) {
			ERR("Error while inserting presentity into DB\n");
			res = -1;
		}
	}
	str_free_content(&str_xcap_params);
	return res;
}
Пример #10
0
static int prepare_presence_notify(struct retr_buf **dst,
                                   struct presentity* _p, struct watcher* _w,
                                   pa_notify_cb_param_t *cbd)
{
    /* Send a notify, saved Contact will be put in
     * Request-URI, To will be put in from and new tag
     * will be generated, callid will be callid,
     * from will be put in to including tag
     */
    str doc = STR_NULL;
    str content_type = STR_NULL;
    str headers = STR_NULL;
    str body = STR_STATIC_INIT("");
    int res = 0;
    uac_req_t	uac_r;

    switch(_w->preferred_mimetype) {
    case DOC_XPIDF:
        res = create_xpidf_document(&_p->data, &doc, &content_type);
        break;

    case DOC_LPIDF:
        res = create_lpidf_document(&_p->data, &doc, &content_type);
        break;

    case DOC_CPIM_PIDF:
        res = create_cpim_pidf_document(&_p->data, &doc, &content_type);
        break;

    case DOC_MSRTC_PIDF:
    case DOC_PIDF:
    default:
        res = create_pidf_document(&_p->data, &doc, &content_type);
    }

    if (res != 0) {
        LOG(L_ERR, "can't create presence document (%d)\n", _w->preferred_mimetype);
        return -2;
    }

    if (create_headers(_w, &headers, &content_type) < 0) {
        LOG(L_ERR, "send_presence_notify(): Error while adding headers\n");
        str_free_content(&doc);
        str_free_content(&content_type);

        return -7;
    }

    if (!is_str_empty(&doc)) body = doc;
    /*	res = tmb.t_request_within(&notify, &headers, &body,
    			_w->dialog, pa_notify_cb, cbd);*/
    set_uac_req(&uac_r,
                &notify,
                &headers,
                &body,
                _w->dialog,
                TMCB_LOCAL_COMPLETED,
                pa_notify_cb,
                cbd
               );
    res = tmb.prepare_request_within(&uac_r, dst);
    if (res < 0) {
        ERR("Can't send NOTIFY (%d) in dlg %.*s, %.*s, %.*s\n", res,
            FMT_STR(_w->dialog->id.call_id),
            FMT_STR(_w->dialog->id.rem_tag),
            FMT_STR(_w->dialog->id.loc_tag));
    }

    str_free_content(&doc);
    str_free_content(&headers);
    str_free_content(&content_type);

    return res;
}
Пример #11
0
int get_rls_from_full_doc(const str_t *uri, 
		/* const str_t *filename,  */
		xcap_query_params_t *xcap_params, 
		const str_t *package, flat_list_t **dst)
{
	char *data = NULL;
	int dsize = 0;
	rls_services_t *rls = NULL;
	service_t *service = NULL;
	str_t curi;
	int res;
	char *xcap_uri = NULL;
	str_t *filename = NULL;

	if (!dst) return RES_INTERNAL_ERR;
	

	/* get basic document */
	xcap_uri = xcap_uri_for_global_document(xcap_doc_rls_services, 
			filename, xcap_params);
	if (!xcap_uri) {
		ERROR_LOG("can't get XCAP uri\n");
		return -1;
	}
	
	res = xcap_query(xcap_uri, xcap_params, &data, &dsize);
	if (res != 0) {
		ERROR_LOG("XCAP problems for uri \'%s\'\n", xcap_uri);
		if (data) {
			cds_free(data);
		}
		cds_free(xcap_uri);
		return RES_XCAP_QUERY_ERR;
	}
	cds_free(xcap_uri);
	
	/* parse document as a service element in rls-sources */
	if (parse_rls_services_xml(data, dsize, &rls) != 0) {
		ERROR_LOG("Parsing problems!\n");
		if (rls) free_rls_services(rls);
		if (data) {
			cds_free(data);
		}
		return RES_XCAP_PARSE_ERR;
	}
/*	DEBUG_LOG("%.*s\n", dsize, data);*/
	if (data) cds_free(data);

	/* try to find given service according to uri */
	canonicalize_uri(uri, &curi);
	service = find_service(rls, &curi); 
	if (!service) DEBUG_LOG("Service %.*s not found!\n", FMT_STR(curi));
	str_free_content(&curi);
	
	if (!service) {
		if (rls) free_rls_services(rls);
		return RES_XCAP_QUERY_ERR;
	}

	/* verify the package */
	if (verify_package(service, package) != 0) {
		free_rls_services(rls);
		return RES_BAD_EVENT_PACKAGE_ERR;
	}
	
	/* create flat document */
	res = create_flat_list(service, xcap_params, dst);
	if (res != RES_OK) {
		ERROR_LOG("Flat list creation error\n");
		free_rls_services(rls);
		free_flat_list(*dst);
		*dst = NULL;
		return res;
	}
	free_rls_services(rls);
	
	return RES_OK;
}