Exemple #1
0
/*! \brief
 * Parse Event header field body
 */
int parse_event(struct hdr_field* _h)
{
	event_t* e;

	if (_h->parsed != 0) {
		return 0;
	}

	e = (event_t*)pkg_malloc(sizeof(event_t));
	if (e == 0) {
		LOG(L_ERR, "parse_event(): No memory left\n");
		return -1;
	}

	memset(e, 0, sizeof(event_t));

	if (event_parser(_h->body.s, _h->body.len, e) < 0) {
		LOG(L_ERR, "parse_event(): Error in event_parser\n");
		pkg_free(e);
		return -2;
	}

	_h->parsed = (void*)e;
	return 0;
}
Exemple #2
0
/*
 * Parse Event header field body
 */
int parse_event(struct hdr_field* _h)
{
	event_t* e;

	if (_h->parsed != 0) {
		return 0;
	}

	e = (event_t*)pkg_malloc(sizeof(event_t));
	if (e == 0) {
		LM_ERR("no pkg memory left\n");
		return -1;
	}

	memset(e, 0, sizeof(event_t));

	if (event_parser(_h->body.s, _h->body.len, e) < 0) {
		pkg_free(e);
		/*TODO - error
		LM_ERR("event_parser failed\n");
		set_err_info(OSER_EC_PARSER, OSER_EL_MEDIUM,
			"error parsing EVENT header");
		set_err_reply(400, "bad headers");
		 */
		return -2;
	}

	_h->parsed = (void*)e;
	return 0;
}
Exemple #3
0
pres_ev_t* contains_event(str* sname, event_t* parsed_event)
{
	event_t event;
	pres_ev_t* e;

	memset(&event, 0, sizeof(event_t));
	if(event_parser(sname->s, sname->len, &event)< 0)
	{
		LM_ERR("parsing event\n");
		return NULL;
	}
	if(parsed_event)
		*parsed_event= event;
	else
	{
		free_event_params(event.params, PKG_MEM_TYPE);
	}
	e= search_event(&event);

	return e;
}
Exemple #4
0
int add_rls_event(modparam_t type, void* val)
{
	char* event= (char*)val;
	event_t e;

	if(event_parser(event, strlen(event), &e)< 0)
	{
		LM_ERR("while parsing event = %s\n", event);
		return -1;
	}
	if(e.parsed & EVENT_OTHER)
	{
		LM_ERR("wrong event= %s\n", event);
		return -1;
	}

	rls_events|= e.parsed;

	return 0;

}
Exemple #5
0
pres_ev_t *contains_event(str *sname, event_t *parsed_event)
{
	event_t event;
	event_t *pe;
	pres_ev_t *e;

	pe = (parsed_event) ? parsed_event : &event;

	memset(pe, 0, sizeof(event_t));
	if(event_parser(sname->s, sname->len, pe) < 0) {
		LM_ERR("parsing event\n");
		return NULL;
	}
	e = search_event(pe);
	if(parsed_event == 0) {
		free_event_params(pe->params.list, PKG_MEM_TYPE);
		pe->params.list = NULL;
	}

	return e;
}
Exemple #6
0
int rls_update_subs(struct sip_msg *msg, char *puri, char *pevent)
{
	str uri;
	str event;
	struct sip_uri parsed_uri;
	event_t e;
	int i;
	
	if (fixup_get_svalue(msg, (gparam_p)puri, &uri) != 0)
	{
		LM_ERR("invalid uri parameter\n");
		return -1;
	}

	if (fixup_get_svalue(msg, (gparam_p)pevent, &event) != 0)
	{
		LM_ERR("invalid event parameter\n");
		return -1;
	}

	if (event_parser(event.s, event.len, &e) < 0)
	{
		LM_ERR("while parsing event: %.*s\n", event.len, event.s);
		return -1;
	}

	if (e.type & EVENT_OTHER)
	{
		LM_ERR("unrecognised event: %.*s\n", event.len, event.s);
		return -1;
	}

	if (!(e.type & rls_events))
	{
		LM_ERR("event not supported by RLS: %.*s\n", event.len,
			event.s);
		return -1;
	}

	if (parse_uri(uri.s, uri.len, &parsed_uri) < 0)
	{
		LM_ERR("bad uri: %.*s\n", uri.len, uri.s);
		return -1;
	}

	LM_DBG("watcher username: %.*s, watcher domain: %.*s\n",
		parsed_uri.user.len, parsed_uri.user.s,
		parsed_uri.host.len, parsed_uri.host.s);

	if (dbmode==RLS_DB_ONLY)
	{
		int ret;
		lock_get(rls_update_subs_lock);
		ret = (update_all_subs_rlsdb(&parsed_uri.user, &parsed_uri.host, &event));
		lock_release(rls_update_subs_lock);
		return ret;
	}


	if (rls_table == NULL)
	{
		LM_ERR("rls_table is NULL\n");
		return -1;
	}

	/* Search through the entire subscription table for matches... */
	for (i = 0; i < hash_size; i++)
	{
		subs_t *subs;

		lock_get(&rls_table[i].lock);

		subs = rls_table[i].entries->next;

		while (subs != NULL)
		{
			if (subs->watcher_user.len == parsed_uri.user.len &&
				strncmp(subs->watcher_user.s, parsed_uri.user.s, parsed_uri.user.len) == 0 &&
				subs->watcher_domain.len == parsed_uri.host.len &&
				strncmp(subs->watcher_domain.s, parsed_uri.host.s, parsed_uri.host.len) == 0 &&
				subs->event->evp->type == e.type)
			{
				subs_t *subs_copy = NULL;

				LM_DBG("found matching RLS subscription for: %.*s\n",
					subs->pres_uri.len, subs->pres_uri.s);

				if ((subs_copy = pres_copy_subs(subs, PKG_MEM_TYPE)) == NULL)
				{
					LM_ERR("subs_t copy failed\n");
					lock_release(&rls_table[i].lock);
					return -1;
				}

				update_a_sub(subs_copy);
			}
			subs = subs->next;
		}		
		lock_release(&rls_table[i].lock);
	}

	return 1;
}
Exemple #7
0
int pres_htable_restore(void)
{
	/* query all records from presentity table and insert records
	 * in presentity table */
	db_key_t result_cols[6];
	db_res_t *result= NULL;
	db_row_t *rows= NULL ;
	db_val_t *row_vals;
	int  i;
	str user, domain, ev_str, uri, body;
	int n_result_cols= 0;
	int user_col, domain_col, event_col, expires_col, body_col = 0, etag_col;
	int event;
	event_t ev;
	char* sphere= NULL;
	int nr_rows;
	str etag;
	int no_rows = 10;

	result_cols[user_col= n_result_cols++]= &str_username_col;
	result_cols[domain_col= n_result_cols++]= &str_domain_col;
	result_cols[event_col= n_result_cols++]= &str_event_col;
	result_cols[expires_col= n_result_cols++]= &str_expires_col;
	result_cols[etag_col= n_result_cols++]= &str_etag_col;
	if(sphere_enable)
		result_cols[body_col= n_result_cols++]= &str_body_col;

	if (pa_dbf.use_table(pa_db, &presentity_table) < 0)
	{
		LM_ERR("unsuccessful use table sql operation\n");
		goto error;
	}

	/* select the whole tabel and all the columns */
	if (DB_CAPABILITY(pa_dbf, DB_CAP_FETCH))
	{
		if(pa_dbf.query(pa_db,0,0,0,result_cols, 0,
		n_result_cols, result_cols[user_col], 0) < 0)
		{
			LM_ERR("Error while querying (fetch) database\n");
			return -1;
		}
		no_rows = estimate_available_rows( 32+32+32+4+64, n_result_cols);
		if (no_rows==0) no_rows = 10;
		if(pa_dbf.fetch_result(pa_db,&result, no_rows)<0)
		{
			LM_ERR("fetching rows failed\n");
			return -1;
		}
	} else
	{
		if (pa_dbf.query (pa_db, 0, 0, 0,result_cols,0, n_result_cols,
					result_cols[user_col], &result) < 0)
		{
			LM_ERR("querying presentity\n");
			goto error;
		}
	}

	nr_rows = RES_ROW_N(result);

	do {
		LM_DBG("loading information from database for %i records\n", nr_rows);

		rows = RES_ROWS(result);

		/* for every row */
		for(i=0; i<nr_rows; i++)
		{
			row_vals = ROW_VALUES(rows + i);

			if (VAL_NULL(row_vals) || VAL_NULL(row_vals+1))
			{
				LM_ERR("columns %.*s or/and %.*s cannot be null -> skipping\n",
					str_username_col.len, str_username_col.s,
					str_domain_col.len, str_domain_col.s);
				continue;
			}

			if (VAL_NULL(row_vals+2) || VAL_NULL(row_vals+3))
			{
				LM_ERR("columns %.*s or/and %.*s cannot be null -> skipping\n",
					str_event_col.len, str_event_col.s,
					str_domain_col.len, str_domain_col.s);
				continue;
			}

			if(row_vals[expires_col].val.int_val< (int)time(NULL))
				continue;

			sphere= NULL;
			user.s= (char*)row_vals[user_col].val.string_val;
			user.len= strlen(user.s);
			domain.s= (char*)row_vals[domain_col].val.string_val;
			domain.len= strlen(domain.s);
			ev_str.s= (char*)row_vals[event_col].val.string_val;
			ev_str.len= strlen(ev_str.s);
			etag.s= (char*)row_vals[etag_col].val.string_val;
			etag.len= strlen(etag.s);

			if(event_parser(ev_str.s, ev_str.len, &ev)< 0)
			{
				LM_ERR("parsing event\n");
				free_event_params(ev.params, PKG_MEM_TYPE);
				goto error;
			}
			event= ev.parsed;
			free_event_params(ev.params, PKG_MEM_TYPE);

			if(uandd_to_uri(user, domain, &uri)< 0)
			{
				LM_ERR("constructing uri\n");
				goto error;
			}
			/* insert in hash_table*/

			if(sphere_enable && event== EVENT_PRESENCE )
			{
				body.s= (char*)row_vals[body_col].val.string_val;
				body.len= strlen(body.s);
				sphere= extract_sphere(body);
			}

			if(insert_phtable(&uri, event, &etag, sphere, 0)== NULL)
			{
				LM_ERR("inserting record in presentity hash table");
				pkg_free(uri.s);
				if(sphere)
					pkg_free(sphere);
				goto error;
			}
			if(sphere)
				pkg_free(sphere);
			pkg_free(uri.s);
		}

		/* any more data to be fetched ?*/
		if (DB_CAPABILITY(pa_dbf, DB_CAP_FETCH))
		{
			if (pa_dbf.fetch_result( pa_db, &result, no_rows) < 0)
			{
				LM_ERR("fetching more rows failed\n");
				goto error;
			}
			nr_rows = RES_ROW_N(result);
		} else
			nr_rows = 0;

	}while (nr_rows>0);

	pa_dbf.free_result(pa_db, result);

	return 0;

error:
	if(result)
		pa_dbf.free_result(pa_db, result);
	return -1;
}