void SipProcess(osip_t* osip, char* pBuf, int size, SOCKET sock) { osip_event_t *evt = osip_parse(pBuf, size); // doesn't need to be free int rc; if (evt == NULL) { OutputDebugString(TEXT("unknown message received\r\n")); return; } rc = osip_find_transaction_and_add_event(osip, evt); if (0 != rc) { OutputDebugString(TEXT("this event has no transaction, create a new one\r\n")); if(evt->type == RCV_REQINVITE) { ProcessNewReqIst(osip, evt, sock); } else { ProcessNewReqNist(osip, evt, sock); }; } }
int sipdump(const u_char* frame, unsigned int frame_length, sip_graph_t *sg[], unsigned short *sg_length) { //header part //struct ether_header *ether_header = (struct ether_header *) frame; struct iphdr *ip_header = (struct iphdr *) (frame + sizeof(struct ether_header)); int ip_header_length = ip_header->ihl * 4; //ip header size may be variable // struct udphdr *udp_header = (struct udphdr *) (frame + sizeof(struct ether_header) + ip_header_length); unsigned int header_length = (sizeof(struct ether_header) + ip_header_length + sizeof(struct udphdr)); //payload part char *payload = (char *) (frame + header_length); unsigned int payload_length = frame_length - header_length; osip_event_t *oe = osip_parse(payload, payload_length); if(oe == NULL) { //perror("Error parsing SIP"); return -1; } oe->sip->message = malloc(100); memcpy(oe->sip->message, payload, 100); if( ins_sip_graph(ip_header, oe, sg, sg_length) == -1) { //perror("Could not insert message into sip_graph"); return -1; } return 0; }
void processSipMsg() { int port; char host[256]; char msg[MESSAGE_MAX_LENGTH]; int msgLen; osip_event_t *sipevent; osip_transaction_t *transaction = NULL; struct sockaddr_in sa; int status; if((msgLen = networkMsgRecv(sipSock,msg,MESSAGE_MAX_LENGTH,&sa)) > 0){ printf("processSipMsg: RECEIVED MSG\n"); printf("%s\n",msg); sipevent = osip_parse(msg,msgLen); if((sipevent==NULL)||(sipevent->sip==NULL)){ printf("Could not parse SIP message\n"); osip_event_free(sipevent); return; } } osip_message_fix_last_via_header(sipevent->sip,(char *)inet_ntoa(sa.sin_addr),ntohs(sa.sin_port)); if((status = osip_find_transaction_and_add_event(osip,sipevent)) != 0){ printf("New transaction!\n"); if(MSG_IS_REQUEST(sipevent->sip)){ printf("Got New Request\n");; }else if(MSG_IS_RESPONSE(sipevent->sip)){ printf("Bad Message:%s\n",msg); osip_event_free(sipevent); }else{ printf("Unsupported message:%s\n",msg); osip_event_free(sipevent); } } }