Example #1
0
static int
ping_contact_f(struct sip_msg *msg, char *str1, char *str2)
{
	struct dest_info dst;
	str s;
	avp_t *avp;
	avp_value_t val;

	switch (((fparam_t *)str1)->type) {
		case FPARAM_AVP:
			if (!(avp = search_first_avp(((fparam_t *)str1)->v.avp.flags,
			    ((fparam_t *)str1)->v.avp.name, &val, 0))) {
				return -1;
			} else {
				if ((avp->flags & AVP_VAL_STR) == 0)
					return -1;
				s = val.s;
			}
			break;
		case FPARAM_STRING:
			s = ((fparam_t *)str1)->v.str;
			break;
	        default:
        	        ERR("BUG: Invalid parameter value in ping_contact\n");
                	return -1;
        }
	init_dest_info(&dst);
	return natping_contact(s, &dst);
}
static void
natping(unsigned int ticks, void *param)
{
	int rval;
	void *buf, *cp;
	str c;
	struct dest_info dst;

	buf = NULL;
	if (cblen > 0) {
		buf = pkg_malloc(cblen);
		if (buf == NULL) {
			LOG(L_ERR, "ERROR: nathelper::natping: out of memory\n");
			return;
		}
	}
	rval = ul.get_all_ucontacts(buf, cblen, (ping_nated_only ? FL_NAT : 0));
	if (rval > 0) {
		if (buf != NULL)
			pkg_free(buf);
		cblen = rval * 2;
		buf = pkg_malloc(cblen);
		if (buf == NULL) {
			LOG(L_ERR, "ERROR: nathelper::natping: out of memory\n");
			return;
		}
		rval = ul.get_all_ucontacts(buf, cblen, (ping_nated_only ? FL_NAT : 0));
		if (rval != 0) {
			pkg_free(buf);
			return;
		}
	}

	if (buf == NULL)
		return;

	cp = buf;
	while (1) {
		memcpy(&(c.len), cp, sizeof(c.len));
		if (c.len == 0)
			break;
		c.s = (char *)cp + sizeof(c.len);
		cp =  (char *)cp + sizeof(c.len) + c.len;
		init_dest_info(&dst);
		memcpy(&dst.send_sock, cp, sizeof(dst.send_sock));
		cp += sizeof(dst.send_sock);
		natping_contact(c, &dst);
	}
	pkg_free(buf);
}