Example #1
0
/* Creates the necessary lumps in order to push the new header value.
 * The whole change/update value process (for the header) is based on a
 * anchoring lump tree that deletes the header and adds the future new values.
 * A chain of "DEL-> SKIP->" is fix and the the new values will be chained
 * on the "after" SKIP branch
 * This works as a multi-time full hdr header replacement (covering hdr name 
 * and CRLF)
 */
static inline struct lump* _push_changes_into_lumps(struct sip_msg *msg,
						struct lump *l, struct hdr_field *hdr, str *body)
{
	struct lump *l1;

	/* is this the first change ? */
	if (l==NULL) {

		/* first change, so build on the static anchoring lump tree (where
		 * all the future changes will be attached ) */
		l = del_lump(msg, hdr->name.s-msg->buf, hdr->len, hdr->type);
		if (l==NULL) {
			LM_ERR("failed to insert del lump\n");
			return NULL;
		}
		l->flags |= LUMP_FLAG_LISTHDR;

		l = insert_skip_lump_after( l );
		if (l==NULL) {
			LM_ERR("failed to insert new skip lump after del\n");
			return NULL;
		}

	}

	/* add the new value to the existing anchoring lump tree */

	l1 = insert_new_lump_after( l, body->s, body->len, hdr->type);
	if (l1==NULL) {
		LM_ERR("failed to insert new lump after skip\n");
		return NULL;
	}

	return l1;
}
Example #2
0
/*
 * Create the necessary lumps from the message
 */
static int create_codec_lumps(struct sip_msg * msg)
{

	struct sdp_session_cell * cur_session;
	struct lump * tmp;
	int count;

	/* get the number of streams */
	lumps_len = 0;
	cur_session = msg->sdp->sessions;

	while(cur_session)
	{
		lumps_len += cur_session->streams_num;
		cur_session = cur_session->next;
	}

	if (lumps_len>MAX_STREAMS)
	{
		LM_ERR("Overflow - too many streams (%d), limit is %d\n",
			lumps_len, MAX_STREAMS);
		return -1;
	}
	memset(lumps, 0, MAX_STREAMS * sizeof(struct lump*));

	/* for each stream create a specific lump for deletion, skip
	 * and insertion */

	LM_DBG("creating %d streams\n",lumps_len);

	count = 0;
	cur_session = msg->sdp->sessions;

	while(cur_session)
	{
		struct sdp_stream_cell * cur_cell = cur_session->streams;
		struct lump* l;
		str text;

		while(cur_cell)
		{
			l = del_lump(msg, cur_cell->payloads.s - msg->buf,
					cur_cell->payloads.len,0);

			lumps[count] = l;

			if( l == NULL)
			{
				LM_ERR("Error adding delete lump for m=\n");
				return -1;
			}

			l->flags |= LUMPFLAG_CODEC;

			tmp = insert_skip_lump_after( l );
			if(tmp == NULL)
			{
				LM_ERR("Error adding skip lump for m=\n");
				return -1;
			}

			text.len = cur_cell->payloads.len;
			text.s = (char*)pkg_malloc(cur_cell->payloads.len);

			if( text.s == NULL )
			{
				LM_ERR("Error alocating lump buffer\n");
				return -1;
			}

			memcpy(text.s,cur_cell->payloads.s,cur_cell->payloads.len);

			tmp = insert_new_lump_after( tmp, text.s, text.len, 0);
			if(tmp == NULL)
			{
				LM_ERR("Error adding insert lump for m=\n");
				return -1;
			}

			count ++;
			cur_cell = cur_cell->next;
		}

		cur_session = cur_session->next;

	}

	return 0;
};