Beispiel #1
0
static inline void pike_raise_event(char *ip)
{
	evi_params_p list;
	str ip_str;
	static str parameter_str = { "ip", 2 };

	if (pike_event_id == EVI_ERROR) {
		LM_ERR("event not registered %d\n", pike_event_id);
		return;
	}

	if (evi_probe_event(pike_event_id)) {
		if (!(list = evi_get_params()))
			return;
		ip_str.s = ip;
		ip_str.len = strlen(ip);
		if (evi_param_add_str(list, &parameter_str, &ip_str)) {
			LM_ERR("unable to add socket parameter\n");
			evi_free_params(list);
			return;
		}
		if (evi_raise_event(pike_event_id, list)) {
			LM_ERR("unable to send event %d\n", pike_event_id);
		}
	} else {
		LM_DBG("no event sent\n");
	}
}
Beispiel #2
0
void shm_event_raise(long used, long size, long perc)
{
	evi_params_p list = 0;

	*event_shm_pending = 1;
	*event_shm_last = perc;

	// event has to be triggered - check for subscribers
	if (!evi_probe_event(EVI_SHM_THRESHOLD_ID)) {
		goto end;
	}

	if (!(list = evi_get_params()))
		goto end;
	if (evi_param_add_int(list, &shm_usage_str, (int *)&perc)) {
		LM_ERR("unable to add usage parameter\n");
		goto end;
	}
	if (evi_param_add_int(list, &shm_threshold_str, (int *)&event_shm_threshold)) {
		LM_ERR("unable to add threshold parameter\n");
		goto end;
	}
	if (evi_param_add_int(list, &shm_used_str, (int *)&used)) {
		LM_ERR("unable to add used parameter\n");
		goto end;
	}
	if (evi_param_add_int(list, &shm_size_str, (int *)&size)) {
		LM_ERR("unable to add size parameter\n");
		goto end;
	}

	/*
	 * event has to be raised without the lock otherwise a deadlock will be
	 * generated by the transport modules, or by the event_route processing
	 */
#ifdef HP_MALLOC
	shm_unlock(0);
#else
	shm_unlock();
#endif

	if (evi_raise_event(EVI_SHM_THRESHOLD_ID, list)) {
		LM_ERR("unable to send shm threshold event\n");
	}

#ifdef HP_MALLOC
	shm_lock(0);
#else
	shm_lock();
#endif

	list = 0;
end:
	if (list)
		evi_free_params(list);
	*event_shm_pending = 0;
}
Beispiel #3
0
void pkg_event_raise(long used, long size, long perc)
{
	evi_params_p list = 0;
	int pid;

	event_pkg_pending = 1;
	event_pkg_last = perc;

	// event has to be triggered - check for subscribers
	if (!evi_probe_event(EVI_PKG_THRESHOLD_ID)) {
		goto end;
	}

	if (!(list = evi_get_params()))
		goto end;
	if (evi_param_add_int(list, &pkg_usage_str, (int *)&perc)) {
		LM_ERR("unable to add usage parameter\n");
		goto end;
	}
	if (evi_param_add_int(list, &pkg_threshold_str, (int *)&event_pkg_threshold)) {
		LM_ERR("unable to add threshold parameter\n");
		goto end;
	}
	if (evi_param_add_int(list, &pkg_used_str, (int *)&used)) {
		LM_ERR("unable to add used parameter\n");
		goto end;
	}
	if (evi_param_add_int(list, &pkg_size_str, (int *)&size)) {
		LM_ERR("unable to add size parameter\n");
		goto end;
	}
	pid = getpid();
	if (evi_param_add_int(list, &pkg_pid_str, (int *)&pid)) {
		LM_ERR("unable to add size parameter\n");
		goto end;
	}

	if (evi_raise_event(EVI_PKG_THRESHOLD_ID, list)) {
		LM_ERR("unable to send pkg threshold event\n");
	}
	list = 0;
end:
	if (list)
		evi_free_params(list);
	event_pkg_pending = 0;
}
Beispiel #4
0
static inline void mysql_raise_event(const db_con_t *conn)
{
	evi_params_p list = NULL;
	if (mysql_evi_id == EVI_ERROR) {
		LM_ERR("event not registered %d\n", mysql_evi_id);
		return;
	}

	if (!conn) {
		LM_ERR("no connection specified\n");
		return;
	}

	if (mysql_last_event == CON_DISCON(conn)) {
		LM_DBG("MySQL status has not changed: %s\n",
			   mysql_last_event ? "disconnected" : "connected");
		return;
	}
	mysql_last_event = CON_DISCON(conn);

	if (evi_probe_event(mysql_evi_id)) {
		if (!(list = evi_get_params()))
			return;
		if (evi_param_add_str(list, &mysql_url_str, (void*)&conn->url)) {
			LM_ERR("unable to add url parameter\n");
			goto free;
		}
		if (evi_param_add_str(list, &mysql_stat_str, CON_DISCON(conn) ?
					&mysql_stat_disconnected_str : &mysql_stat_connected_str)) {
			LM_ERR("unable to add status parameter\n");
			goto free;
		}
		if (evi_raise_event(mysql_evi_id, list)) {
			LM_ERR("unable to send event\n");
		}
	} else {
		LM_DBG("no event sent\n");
	}
	return;
free:
	evi_free_params(list);
}
Beispiel #5
0
void lb_raise_event(struct lb_dst *dst)
{
	evi_params_p list = NULL;

	if (lb_evi_id == EVI_ERROR || !evi_probe_event(lb_evi_id))
		return;

	list = evi_get_params();
	if (!list) {
		LM_ERR("cannot create event params\n");
		return;
	}

	if (evi_param_add_int(list, &lb_group_str, &dst->group) < 0) {
		LM_ERR("cannot add destination group\n");
		goto error;
	}

	if (evi_param_add_str(list, &lb_uri_str, &dst->uri) < 0) {
		LM_ERR("cannot add destination uri\n");
		goto error;
	}

	if (evi_param_add_str(list, &lb_state_str,
			dst->flags&LB_DST_STAT_DSBL_FLAG ? &lb_disabled_str : &lb_enabled_str) < 0) {
		LM_ERR("cannot add destination state\n");
		goto error;
	}

	if (evi_raise_event(lb_evi_id, list)) {
		LM_ERR("unable to send %.*s event\n", lb_event.len, lb_event.s);
	}
	return;

error:
	evi_free_params(list);
}
int evi_raise_event(event_id_t id, evi_params_t* params)
{
	evi_subs_p subs, prev;
	long now;
	int ret = 0;

	if (id < 0 || id >= events_no) {
		LM_ERR("invalid event %d\n", id);
		return -1;
	}

	lock_get(events[id].lock);
	now = time(0);
	subs = events[id].subscribers;
	prev = NULL;
	while (subs) {
		if (!subs->reply_sock) {
			LM_ERR("unknown destination\n");
			continue;
		}
		/* check expire */
		if (subs->reply_sock->flags & EVI_EXPIRE &&
				subs->reply_sock->subscription_time +
				subs->reply_sock->expire < now) {
			if (subs->trans_mod && subs->trans_mod->free)
				subs->trans_mod->free(subs->reply_sock);
			else
				shm_free(subs->reply_sock);
			if (!prev) {
				events[id].subscribers = subs->next;
				shm_free(subs);
				subs = events[id].subscribers;
			} else {
				prev->next = subs->next;
				shm_free(subs);
				subs = prev->next;
			}
			continue;
		}
	
		if (!subs->trans_mod) {
			LM_ERR("unknown transfer protocol\n");
			goto next;
		}
		
		LM_DBG("found subscriber %.*s\n",
				subs->reply_sock->address.len, subs->reply_sock->address.s);
		if (!subs->trans_mod->raise) {
			LM_ERR("\"%.*s\" protocol cannot raise events\n",
					subs->trans_mod->proto.len, subs->trans_mod->proto.s);
			goto next;
		}

		ret += (subs->trans_mod->raise)(&events[id].name,
					subs->reply_sock, params);
next:
		prev = subs;
		subs = subs->next;
	}
	lock_release(events[id].lock);

	/* done sending events - free parameters */
	if (params)
		evi_free_params(params);
	return ret;

}
int evi_raise_script_event(event_id_t id, void * _a, void * _v)
{
	pv_spec_p vals = (pv_spec_p)_v;
	pv_spec_p attrs = (pv_spec_p)_a;
	struct usr_avp *v_avp = NULL;
	struct usr_avp *a_avp = NULL;
	int err = evi_probe_event(id);
	int_str val, attr;
	str *at;
	evi_params_p params = NULL;

	if (err < 0)
		return err;
	else if (!err)
		return 1;

	if (!vals)
		goto raise;
	if (!(params = evi_get_params())) {
		LM_ERR("cannot create parameters list\n");
		goto raise;
	}

	/* handle parameters */
	while ((v_avp = search_first_avp(vals->pvp.pvn.u.isname.type,
					vals->pvp.pvn.u.isname.name.n, &val, v_avp))) {
		at = NULL;
		/* check attribute */
		if (attrs) {
			err = -1;
			a_avp = search_first_avp(attrs->pvp.pvn.u.isname.type,
					attrs->pvp.pvn.u.isname.name.n, &attr, a_avp);
			if (!a_avp) {
				LM_ERR("missing attribute\n");
				goto error;
			}
			if (!(a_avp->flags & AVP_VAL_STR)) {
				LM_ERR("invalid attribute name - must be string\n");
				goto error;
			}
			at = &attr.s;
		}

		if (v_avp->flags & AVP_VAL_STR)
			err = evi_param_add_str(params, at, &val.s);
		else
			err = evi_param_add_int(params, at, &val.n);
		if (err) {
			LM_ERR("error while adding parameter\n");
			goto error;
		}
	}

	/* check if there were too many attribute names */
	if (attrs && a_avp && search_first_avp(attrs->pvp.pvn.u.isname.type,
				attrs->pvp.pvn.u.isname.name.n, &attr, a_avp)) {
		/* only signal error - continue */
		LM_ERR("too many attribute names\n");
	}

raise:
	err = evi_raise_event(id, params);
	return err ? err : 1;
error:
	evi_free_params(params);
	return -1;
}
Beispiel #8
0
/*
 * destroy DLG_STATE_CHANGED event
 */
void state_changed_event_destroy(void)
{
	evi_free_params(event_params);
}
Beispiel #9
0
int evi_raise_event_msg(struct sip_msg *msg, event_id_t id, evi_params_t* params)
{
	evi_subs_p subs, prev;
	long now;
	int flags, pflags = 0;
	int ret = 0;

	if (id < 0 || id >= events_no) {
		LM_ERR("invalid event %d\n", id);
		return -1;
	}

	if (events_rec_level == 0) {
		LM_ERR("Too many nested events %d\n", MAX_REC_LEV);
		return -1;
	}
	events_rec_level--;
	if (params)
		pflags = params->flags;

	lock_get(events[id].lock);
	now = time(0);
	subs = events[id].subscribers;
	prev = NULL;
	while (subs) {
		if (!subs->reply_sock) {
			LM_ERR("unknown destination\n");
			continue;
		}
		/* check expire */
		if (!(subs->reply_sock->flags & EVI_PENDING) &&
				subs->reply_sock->flags & EVI_EXPIRE &&
				subs->reply_sock->subscription_time +
				subs->reply_sock->expire < now) {
			if (subs->trans_mod && subs->trans_mod->free)
				subs->trans_mod->free(subs->reply_sock);
			else
				shm_free(subs->reply_sock);
			if (!prev) {
				events[id].subscribers = subs->next;
				shm_free(subs);
				subs = events[id].subscribers;
			} else {
				prev->next = subs->next;
				shm_free(subs);
				subs = prev->next;
			}
			continue;
		}

		if (!subs->trans_mod) {
			LM_ERR("unknown transfer protocol\n");
			goto next;
		}

		LM_DBG("found subscriber %.*s\n",
				subs->reply_sock->address.len, subs->reply_sock->address.s);
		if (!subs->trans_mod->raise) {
			LM_ERR("\"%.*s\" protocol cannot raise events\n",
					subs->trans_mod->proto.len, subs->trans_mod->proto.s);
			goto next;
		}
		/* we use this var to make sure nested calls don't reset the flag */
		flags = subs->reply_sock->flags;
		subs->reply_sock->flags |= EVI_PENDING;
		/* make sure nested events don't deadlock */
		lock_release(events[id].lock);

		ret += (subs->trans_mod->raise)(msg, &events[id].name,
					subs->reply_sock, params);

		lock_get(events[id].lock);
		subs->reply_sock->flags = flags;
next:
		prev = subs;
		subs = subs->next;
	}
	lock_release(events[id].lock);

	/* done sending events - free parameters */
	if (params) {
		/* make sure no one is messing with our flags */
		params->flags = pflags;
		if (params->flags & EVI_FREE_LIST)
			evi_free_params(params);
	}
	events_rec_level++;
	return ret;

}
Beispiel #10
0
void frd_event_destroy(void)
{
	evi_free_params(event_params);
}
Beispiel #11
0
int ds_set_state(int group, str *address, int state, int type)
{
	int i=0;
	ds_set_p idx = NULL;
	evi_params_p list = NULL;

	if(_ds_list==NULL || _ds_list_nr<=0)
	{
		LM_DBG("empty destination set\n");
		return -1;
	}
	
	/* get the index of the set */
	if(ds_get_index(group, &idx)!=0)
	{
		LM_ERR("destination set [%d] not found\n", group);
		return -1;
	}

	while(i<idx->nr)
	{
		if(idx->dlist[i].uri.len==address->len 
				&& strncasecmp(idx->dlist[i].uri.s, address->s,
					address->len)==0)
		{
			
			/* remove the Probing/Inactive-State? Set the fail-count to 0. */
			if (state == DS_PROBING_DST) {
				if (type) {
					if (idx->dlist[i].flags & DS_INACTIVE_DST) {
						LM_INFO("Ignoring the request to set this destination"
								" to probing: It is already inactive!\n");
						return 0;
					}
					
					idx->dlist[i].failure_count++;
					/* Fire only, if the Threshold is reached. */
					if (idx->dlist[i].failure_count 
							< probing_threshhold) return 0;
					if (idx->dlist[i].failure_count
							> probing_threshhold) 
						idx->dlist[i].failure_count
							= probing_threshhold;
				}
			}
			/* Reset the Failure-Counter */
			if ((state & DS_RESET_FAIL_DST) > 0) {
				idx->dlist[i].failure_count = 0;
				state &= ~DS_RESET_FAIL_DST;
			}
			
			if(type)
				idx->dlist[i].flags |= state;
			else
				idx->dlist[i].flags &= ~state;
			if (dispatch_evi_id == EVI_ERROR) {
				LM_ERR("event not registered %d\n", dispatch_evi_id);
			} else if (evi_probe_event(dispatch_evi_id)) {
				if (!(list = evi_get_params()))
					return 0;
				if (evi_param_add_int(list, &group_str, &group)) {
					LM_ERR("unable to add group parameter\n");
					evi_free_params(list);
					return 0;
				}
				if (evi_param_add_str(list, &address_str, address)) {
					LM_ERR("unable to add address parameter\n");
					evi_free_params(list);
					return 0;
				}
				if (evi_param_add_str(list, &status_str,
							type ? &inactive_str : &active_str)) {
					LM_ERR("unable to add status parameter\n");
					evi_free_params(list);
					return 0;
				}

				if (evi_raise_event(dispatch_evi_id, list)) {
					LM_ERR("unable to send event\n");
				}
			} else {
				LM_DBG("no event sent\n");
			}
			return 0;
		}
		i++;
	}

	return -1;
}