rem: if(write(pipe, &jsmsg, sizeof(jsmsg)) != sizeof(jsmsg))
add: fl = write(pipe, &jsmsg, sizeof(jsmsg)); if(fl != sizeof(jsmsg))
context: int xjab_manage_sipmsg(struct sip_msg *msg, int type){	str body, dst;	xj_sipmsg jsmsg;	struct to_body to, from;	struct sip_uri _uri;	int pipe, fl;	struct to_param *foo,*bar;	char   *cp, *buf=0;	t_xj_jkey jkey, *p;	// extract message body - after that whole SIP MESSAGE is parsed	if (type==XJ_SEND_MESSAGE && imb.im_extract_body(msg,&body)==-1 )	{		LOG(L_ERR,"XJAB:xjab_manage_sipmsg: ERROR:cannot extract body"				" from sip msg!\n");		goto error;	}		// check for FROM header	if(!msg->from)	{		LOG(L_ERR,"XJAB:xjab_manage_sipmsg: cannot find FROM HEADER!\n");		goto error;	}		/* parsing from header */	memset(&from,0,sizeof(from));	cp = translate_pointer(msg->orig,msg->buf,msg->from->body.s);	buf = (char*)pkg_malloc(msg->from->body.len+1);	if (!buf) 	{		DBG("XJAB:xjab_manage_sipmsg: error no free pkg memory\n");		goto error;	}	memcpy(buf,cp,msg->from->body.len+1);	parse_to(buf,buf+msg->from->body.len+1,&from);	if (from.error!=PARSE_OK ) 	{		DBG("XJAB:xjab_manage_sipmsg: error cannot parse from header\n");		goto error;	}	/* we are not intrested in from param-> le's free them now*/	for(foo=from.param_lst ; foo ; foo=bar)	{		bar = foo->next;		pkg_free(foo);	}	jkey.hash = xj_get_hash(&from.uri, NULL);	jkey.id = &from.uri;	// get the communication pipe with the worker	switch(type)	{		case XJ_SEND_MESSAGE:		case XJ_JOIN_JCONF:		case XJ_GO_ONLINE:			if((pipe = xj_wlist_get(jwl, &jkey, &p)) < 0)			{				DBG("XJAB:xjab_manage_sipmsg: cannot find pipe of the worker!\n");				goto error;			}		break;		case XJ_SEND_BYE:		case XJ_EXIT_JCONF:		case XJ_GO_OFFLINE:			if((pipe = xj_wlist_check(jwl, &jkey, &p)) < 0)			{				DBG("XJAB:xjab_manage_sipmsg: no open Jabber session for"						" <%.*s>!\n", from.uri.len, from.uri.s);				goto error;			}		break;		default:			DBG("XJAB:xjab_manage_sipmsg: ERROR:strange SIP msg type!\n");			goto error;	}		// determination of destination	dst.len = 0;	if( msg->new_uri.len > 0 )	{		DBG("XJAB:xjab_manage_sipmsg: using NEW URI for destination\n");		dst.s = msg->new_uri.s;		dst.len = msg->new_uri.len;	} else if ( msg->first_line.u.request.uri.len > 0 )	{		DBG("XJAB:xjab_manage_sipmsg: parsing URI from first line\n");		if(parse_uri(msg->first_line.u.request.uri.s,					msg->first_line.u.request.uri.len, &_uri) < 0)		{			DBG("XJAB:xjab_manage_sipmsg: ERROR parsing URI from first line\n");			goto error;		}		if(_uri.user.len > 0)		{			DBG("XJAB:xjab_manage_sipmsg: using URI for destination\n");			dst.s = msg->first_line.u.request.uri.s;			dst.len = msg->first_line.u.request.uri.len;		}		free_uri(&_uri);	}	if(dst.len == 0 && msg->to != NULL)	{		memset( &to , 0, sizeof(to) );		parse_to(msg->to->body.s, msg->to->body.s + msg->to->body.len + 1,				&to);		if(to.uri.len > 0) // to.error == PARSE_OK)		{			DBG("XJAB:xjab_manage_sipmsg: TO parsed OK <%.*s>.\n",				to.uri.len, to.uri.s);			dst.s = to.uri.s;			dst.len = to.uri.len;		}		else		{			DBG("XJAB:xjab_manage_sipmsg: TO NOT parsed\n");			goto error;		}	}	if(dst.len == 0)	{		DBG("XJAB:xjab_manage_sipmsg: destination not found in SIP message\n");		goto error;	}		/** skip 'sip:' in destination address */	if(dst.s[0]=='s' && dst.s[1]=='i' && dst.s[2]=='p')	{		dst.s += 3;		dst.len -= 3;		fl = 1;		while(*dst.s == ' ' || *dst.s == '\t' || *dst.s == ':')		{			dst.s++;			dst.len--;			fl = 0;		}		if(fl)		{			dst.s -= 3;			dst.len += 3;		}				DBG("XJAB:xjab_manage_sipmsg: DESTINATION corrected [%.*s].\n", 				dst.len, dst.s);	}		//putting the SIP message parts in share memory to be accessible by workers    jsmsg = (xj_sipmsg)shm_malloc(sizeof(t_xj_sipmsg));    if(jsmsg == NULL)    	return -1;		switch(type)	{		case XJ_SEND_MESSAGE:			jsmsg->msg.len = body.len;			if((jsmsg->msg.s = (char*)shm_malloc(jsmsg->msg.len+1)) == NULL)			{				shm_free(jsmsg);				goto error;			}			strncpy(jsmsg->msg.s, body.s, jsmsg->msg.len);		break;		case XJ_SEND_BYE:		case XJ_JOIN_JCONF:		case XJ_EXIT_JCONF:		case XJ_GO_ONLINE:		case XJ_GO_OFFLINE:			jsmsg->msg.len = 0;			jsmsg->msg.s = NULL;		break;		default:			DBG("XJAB:xjab_manage_sipmsg: this SHOULD NOT appear\n");			shm_free(jsmsg);			goto error;	}	jsmsg->to.len = dst.len;	if((jsmsg->to.s = (char*)shm_malloc(jsmsg->to.len+1)) == NULL)	{		if(type == XJ_SEND_MESSAGE)			shm_free(jsmsg->msg.s);		shm_free(jsmsg);		goto error;	}	strncpy(jsmsg->to.s, dst.s, jsmsg->to.len);	jsmsg->jkey = p;	jsmsg->type = type;	jsmsg->jkey->hash = jkey.hash;	DBG("XJAB:xjab_manage_sipmsg:%d: sending <%p> to worker through <%d>\n",			getpid(), jsmsg, pipe);	// sending the SHM pointer of SIP message to the worker	if(write(pipe, &jsmsg, sizeof(jsmsg)) != sizeof(jsmsg))	{		DBG("XJAB:xjab_manage_sipmsg: error when writting to worker pipe!\n");		if(type == XJ_SEND_MESSAGE)			shm_free(jsmsg->msg.s);		shm_free(jsmsg->to.s);		shm_free(jsmsg);		goto error;	}		if (buf) 		pkg_free(buf);		return 1;error:	if (buf) 		pkg_free(buf);	return -1;}