Exemplo n.º 1
0
static void rls_trace_subscription(rpc_t *rpc, void *c, rl_subscription_t *s, int details)
{
	virtual_subscription_t *vs;
	int cnt, i;
	
	switch (s->type) {
		case rls_internal_subscription:
			rpc->printf(c, "URI = %.*s", FMT_STR(*s->u.internal.record_id));
			rpc_lf(rpc, c);
			break;
		case rls_external_subscription:
			rpc->printf(c, "URI = %.*s", FMT_STR(s->u.external.record_id));
			rpc_lf(rpc, c);
			break;
	}

	cnt = ptr_vector_size(&s->vs);
	for (i = 0; i < cnt; i++) {
		vs = ptr_vector_get(&s->vs, i);
		if (!vs) continue;
		if (details > 0) trace_vs(rpc, c, vs, details - 1);
	}
	
	rpc_lf(rpc, c);
}
Exemplo n.º 2
0
int get_msg_rules_action(cp_ruleset_t *r, const str_t *wuri, 
		msg_handling_t *dst_action)
{
	int res = 1; /* rule not found */
	cp_rule_t *rule;
	msg_handling_t a = msg_handling_block;
	msg_handling_t aa;
	
	if (!r) return -1;
	
	rule = r->rules;
	while (rule) {
		DEBUG_LOG("TRYING rule %.*s for uri %.*s\n", 
					FMT_STR(rule->id), FMT_STR(*wuri));
		if (is_rule_for_uri(rule, wuri)) {
			DEBUG_LOG("rule %.*s matches for uri %.*s\n", 
					FMT_STR(rule->id), FMT_STR(*wuri));

			if (!rule->actions) continue;
			if (!rule->actions->unknown) continue;
			aa = *(msg_handling_t*)(rule->actions->unknown->data);
			if (aa > a) a = aa;
			res = 0;
		}
		rule = rule->next;
	}
	if (dst_action && (res == 0)) *dst_action = a;
	
	return res;
}
Exemplo n.º 3
0
static int serialize_route_ex(sstream_t *ss, rr_t **_r)
{
	int do_it = 0;
	int res = 0;
	
	if (is_input_sstream(ss)) { /* read route */
		if (serialize_int(ss, &do_it) != 0) return -1;
		if (!do_it) *_r = NULL;
		else {
			*_r = (rr_t*)cds_malloc(sizeof(rr_t));
			if (!*_r) {
				ERROR_LOG("serialize_route(): can't allocate memory\n");
				return -1;
			}
			(*_r)->r2 = NULL;
			(*_r)->params = NULL;
			(*_r)->next = NULL;
		}
	}
	else { /* store route */
		if (*_r) do_it = 1;
		else do_it = 0;
		if (serialize_int(ss, &do_it) != 0) return -1;
	}
		
	if (do_it) {
		rr_t *r = *_r;
		str s = { r->nameaddr.name.s, r->len };
		int delta = r->nameaddr.uri.s - r->nameaddr.name.s;

		res = serialize_str(ss, &s) | res;
		res = serialize_int(ss, &r->nameaddr.name.len) | res;
		res = serialize_int(ss, &r->nameaddr.uri.len) | res;
		res = serialize_int(ss, &r->nameaddr.len) | res;
		res = serialize_int(ss, &delta) | res;
		if (is_input_sstream(ss)) {
			r->nameaddr.name.s = s.s;
			r->nameaddr.uri.s = s.s + delta;
		}
		/* !!! optimalized strings - use carefuly !!! */
		/*res = serialize_str(ss, &r->nameaddr.name) | res;
		res = serialize_str(ss, &r->nameaddr.uri) | res;
		res = serialize_int(ss, &r->nameaddr.len) | res;*/
		
		/* ??? res = serialize_r2(ss, &r->nameaddr.params) | res; ??? */
		res = serialize_params(ss, &r->params) | res;
		res = serialize_int(ss, &r->len) | res;

		TRACE_LOG("ROUTE: rlen=%d name=%.*s, uri=%.*s\n len=%d WHOLE=%.*s\n", 
				r->len,
				FMT_STR(r->nameaddr.name),
				FMT_STR(r->nameaddr.uri),
				r->nameaddr.len,
				r->nameaddr.len, r->nameaddr.name.s
				);
	}
	
	return res;
}
Exemplo n.º 4
0
unsigned int hash_dlg_id(dlg_id_t *id)
{
	char tmp[512];
	int len;
	
	if (!id) return 0;
	
	len = snprintf(tmp, sizeof(tmp), "%.*s%.*s%.*s",
			FMT_STR(id->call_id),
			FMT_STR(id->rem_tag),
			FMT_STR(id->loc_tag));

	return rshash(tmp, len);
}
	void CPackage::DecodeFromGS( CPlayer *pPlayer, DBReadSet &db )
	{
		BYTE flag = db.GetByteFromByteArray();
		if( flag == 1 )
		{
			if( m_pGoods != NULL )
			{
				CGoodsFactory::GarbageCollect( &m_pGoods );
			}
			m_pGoods = CGoodsFactory::UnserializeGoods( db,35 );		
			m_pContainer->Release();
			m_pContainer->SetContainerVolume( m_pGoods );
			m_pContainer->Unserialize( db );

			Log4c::Trace(ROOT_MODULE,FMT_STR( "Decode package for player [%s] ok", pPlayer->GetName() ) );
		}
		else
		{
			if( m_pGoods != NULL )
			{
				CGoodsFactory::GarbageCollect( &m_pGoods );
			}
			m_pContainer->Release();
		}
	}
Exemplo n.º 6
0
static void trace_vs(rpc_t *rpc, void *c, virtual_subscription_t *vs, int details)
{
	rpc->printf(c, " Virtual subscriptions:");
	rpc_lf(rpc, c);
	
	rpc->printf(c, " -> URI = %.*s", FMT_STR(vs->uri));
	rpc_lf(rpc, c);
	rpc->printf(c, " -> status = %d", vs->status);
	rpc_lf(rpc, c);

	if (details > 0) {
		rpc->printf(c, " -> document = %.*s", FMT_STR(vs->state_document));
		rpc_lf(rpc, c);
	}

	rpc_lf(rpc, c);
}
static notifier_domain_t *add_domain_nolock(domain_maintainer_t *dm, const str_t *name)
{
	notifier_domain_t *d = create_notifier_domain(name);
	
	if (d) {
		DEBUG_LOG("created domain: \'%.*s\'\n", FMT_STR(d->name));
		ptr_vector_add(&dm->registered_domains, d);
		return d;
	}
	else return NULL;
}
void release_notifier_domain(domain_maintainer_t *dm, notifier_domain_t *domain)
{
	if ((!dm) || (!domain)) return;
	
	cds_mutex_lock(&dm->mutex);
	if (remove_reference(&domain->ref)) {
		/* last reference */
		DEBUG_LOG("freeing domain: \'%.*s\'\n", FMT_STR(domain->name));
		remove_notifier_domain(dm, domain);
		destroy_notifier_domain(domain);
	}
	cds_mutex_unlock(&dm->mutex);
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
int rls_create_internal_subscription(virtual_subscription_t *vs, 
		rl_subscription_t **dst, 
		flat_list_t *flat,
		int nesting_level)
{
	rl_subscription_t *rls;
	
	/* try to make subscription and release it if internal subscription 
	 * not created */

	if (dst) *dst = NULL;

	rls = rls_alloc_subscription(rls_internal_subscription);
	if (!rls) {
		ERR("processing INTERNAL RLS subscription - memory allocation error\n");
		return -1;
	}

	rls->u.internal.record_id = &vs->uri; /* !!! NEVER !!! free this */
	rls->u.internal.package = rls_get_package(vs->subscription); /* !!! NEVER !!! free this */
	rls->u.internal.subscriber_id = rls_get_subscriber(vs->subscription); /* !!! NEVER !!! free this */
	rls->xcap_params = vs->subscription->xcap_params; /* !!! NEVER free this !!! */
	rls->u.internal.vs = vs;
	if (dst) *dst = rls;

	DBG("creating internal subscription to %.*s (VS %p)\n",
			FMT_STR(*rls->u.internal.record_id), 
			rls->u.internal.vs);

	if (add_virtual_subscriptions(rls, flat, nesting_level) != 0) {
		rls_free(rls);
		if (dst) *dst = NULL;
		return -1;
	}

	rls_generate_notify(rls, 1);

	return 0;
}
void destroy_domain_maintainer(domain_maintainer_t *dm) 
{
	int i, cnt;
	notifier_domain_t *d;
	
	if (!dm) return;
			
	DEBUG_LOG("destroying domain maintainer\n");

	cnt = ptr_vector_size(&dm->registered_domains);
	for (i = 0; i < cnt; i++) {
		d = ptr_vector_get(&dm->registered_domains, i);
		if (!d) continue;
		if (remove_reference(&d->ref)) {
			DEBUG_LOG("freeing domain: \'%.*s\'\n", FMT_STR(d->name));
			destroy_notifier_domain(d);
		}
	}
	ptr_vector_destroy(&dm->registered_domains);
	cds_mutex_destroy(&dm->mutex);
	cds_free(dm);
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
int xcap_query_impl(const char *uri, xcap_query_params_t *params, char **buf, int *bsize)
{
    CURLcode res = -1;
    static CURL *handle = NULL;
    dstring_t data;
    char *auth = NULL;
    int i;
    long auth_methods;

    if (!uri) {
        ERR("BUG: no uri given\n");
        return -1;
    }
    if (!buf) {
        ERR("BUG: no buf given\n");
        return -1;
    }

    i = 0;
    if (params) {
        i += params->auth_user.len;
        i += params->auth_pass.len;
    }
    if (i > 0) {
        /* do authentication */
        auth = (char *)cds_malloc_pkg(i + 2);
        if (!auth) return -1;
        sprintf(auth, "%.*s:%.*s", FMT_STR(params->auth_user),
                FMT_STR(params->auth_pass));
    }

    auth_methods = CURLAUTH_BASIC | CURLAUTH_DIGEST;

    dstr_init(&data, 512);

    if (!handle) handle = curl_easy_init();
    if (handle) {
        curl_easy_setopt(handle, CURLOPT_URL, uri);
        /* TRACE_LOG("uri: %s\n", uri ? uri : "<null>"); */

        /* do not store data into a file - store them in memory */
        curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, write_data_func);
        curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data);

        /* be quiet */
#ifdef CURLOPT_MUTE
        curl_easy_setopt(handle, CURLOPT_MUTE, 1);
#endif /* CURLOPT_MUTE */

        /* non-2xx => error */
        curl_easy_setopt(handle, CURLOPT_FAILONERROR, 1);

        /* auth */
        curl_easy_setopt(handle, CURLOPT_HTTPAUTH, auth_methods); /* TODO possibility of selection */
        curl_easy_setopt(handle, CURLOPT_NETRC, CURL_NETRC_IGNORED);
        curl_easy_setopt(handle, CURLOPT_USERPWD, auth);

        /* SSL */
        if (params) {
            if (params->enable_unverified_ssl_peer) {
                curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);
                curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0);
            }
        }

        /* follow redirects (needed for apache mod_speling - case insesitive names) */
        curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);

        /*	curl_easy_setopt(handle, CURLOPT_TCP_NODELAY, 1);
        	curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, 10);*/

        /* Accept headers */

        res = curl_easy_perform(handle);
        /* curl_easy_cleanup(handle); */ /* FIXME: experimental */
    }
    else ERROR_LOG("can't initialize curl handle\n");
    if (res == 0) {
        *bsize = dstr_get_data_length(&data);
        if (*bsize) {
            *buf = (char*)cds_malloc(*bsize);
            if (!*buf) {
                ERROR_LOG("can't allocate %d bytes\n", *bsize);
                res = -1;
                *bsize = 0;
            }
            else dstr_get_data(&data, *buf);
        }
    }
    else DBG("curl error: %d\n", res); /* see curl/curl.h for possible values*/
    dstr_destroy(&data);
    if (auth) cds_free_pkg(auth);
    return res;
}