static void test_overflow(void){ belle_sdp_session_description_t* sdp; belle_sip_list_t *mds; belle_sdp_media_description_t *vmd; int i; const size_t orig_buffsize=1024; size_t buffsize=orig_buffsize; char *buffer=belle_sip_malloc0(buffsize); size_t offset=0; sdp=belle_sdp_session_description_parse(big_sdp); CU_ASSERT_PTR_NOT_NULL(sdp); mds=belle_sdp_session_description_get_media_descriptions(sdp); CU_ASSERT_PTR_NOT_NULL(mds); CU_ASSERT_PTR_NOT_NULL(mds->next); vmd=(belle_sdp_media_description_t*)mds->next->data; for(i=0;i<16;i++){ belle_sdp_media_description_add_attribute(vmd,belle_sdp_attribute_create("candidate","2 1 UDP 1694498815 82.65.223.97 9078 typ srflx raddr 192.168.0.2 rport 9078")); } CU_ASSERT_EQUAL(belle_sip_object_marshal(BELLE_SIP_OBJECT(sdp),buffer,buffsize,&offset),BELLE_SIP_BUFFER_OVERFLOW); belle_sip_message("marshal size is %i",(int)offset); CU_ASSERT_TRUE(offset==buffsize); belle_sip_object_unref(sdp); belle_sip_free(buffer); }
static void test_session_description(void) { const char* l_src = big_sdp; belle_sdp_origin_t* l_origin; belle_sdp_session_description_t* lTmp; belle_sip_list_t* media_descriptions; belle_sdp_session_description_t* l_session_description = belle_sdp_session_description_parse(l_src); char* l_raw_session_description = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_session_description)); belle_sip_object_unref(BELLE_SIP_OBJECT(l_session_description)); lTmp = belle_sdp_session_description_parse(l_raw_session_description); belle_sip_free(l_raw_session_description); l_session_description = BELLE_SDP_SESSION_DESCRIPTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp)); CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_version(l_session_description)); CU_ASSERT_EQUAL(belle_sdp_version_get_version(belle_sdp_session_description_get_version(l_session_description)),0); l_origin = belle_sdp_session_description_get_origin(l_session_description); CU_ASSERT_PTR_NOT_NULL(l_origin); CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address(l_origin),"2a01:e35:1387:1020:6233:4bff:fe0b:5663") CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address_type(l_origin),"IP6") CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_network_type(l_origin),"IN") CU_ASSERT_EQUAL(belle_sdp_origin_get_session_id(l_origin),1239) CU_ASSERT_EQUAL(belle_sdp_origin_get_session_version(l_origin),1239) CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_session_name(l_session_description)); CU_ASSERT_STRING_EQUAL(belle_sdp_session_name_get_value(belle_sdp_session_description_get_session_name(l_session_description)),"SIP Talk"); CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_connection(l_session_description)); CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_time_descriptions(l_session_description)); CU_ASSERT_EQUAL(belle_sdp_time_get_start(belle_sdp_time_description_get_time((belle_sdp_time_description_t*)(belle_sdp_session_description_get_time_descriptions(l_session_description)->data))),0); CU_ASSERT_EQUAL(belle_sdp_time_get_stop(belle_sdp_time_description_get_time((belle_sdp_time_description_t*)(belle_sdp_session_description_get_time_descriptions(l_session_description)->data))),0); media_descriptions = belle_sdp_session_description_get_media_descriptions(l_session_description); CU_ASSERT_PTR_NOT_NULL(media_descriptions); CU_ASSERT_STRING_EQUAL (belle_sdp_media_get_media_type(belle_sdp_media_description_get_media((belle_sdp_media_description_t*)(media_descriptions->data))),"audio"); media_descriptions=media_descriptions->next; CU_ASSERT_PTR_NOT_NULL(media_descriptions); test_media_description_base((belle_sdp_media_description_t*)(media_descriptions->data)); belle_sip_object_unref(l_session_description); return; }
static void test_image_mline() { const char * sdp = "v=0\r\n" "o=cp10 138884701697 138884701699 IN IP4 10.7.1.133\r\n" "s=SIP Call\r\n" "c=IN IP4 91.121.128.144\r\n" "t=0 0\r\n" "m=image 33802 udptl t38\r\n" "a=sendrecv\r\n" "a=T38FaxVersion:0\r\n" "a=T38MaxBitRate:9600\r\n" "a=T38FaxRateManagement:transferredTCF\r\n" "a=T38FaxMaxBuffer:1000\r\n" "a=T38FaxMaxDatagram:200\r\n" "a=T38FaxUdpEC:t38UDPRedundancy\r\n"; belle_sdp_session_description_t* l_session_description = belle_sdp_session_description_parse(sdp); belle_sip_object_unref(l_session_description); }
/* * Extract the sdp from a sip message. * If there is no body in the message, the session_desc is set to null, 0 is returned. * If body was present is not a SDP or parsing of SDP failed, -1 is returned and SalReason is set appropriately. * **/ static int extract_sdp(SalOp *op, belle_sip_message_t* message,belle_sdp_session_description_t** session_desc, SalReason *error) { const char *body; belle_sip_header_content_type_t* content_type; if (op&&op->sdp_handling == SalOpSDPSimulateError){ ms_error("Simulating SDP parsing error for op %p", op); *session_desc=NULL; *error=SalReasonNotAcceptable; return -1; } else if( op && op->sdp_handling == SalOpSDPSimulateRemove){ ms_error("Simulating no SDP for op %p", op); *session_desc = NULL; return 0; } body = belle_sip_message_get_body(message); if(body == NULL) { *session_desc = NULL; return 0; } content_type = belle_sip_message_get_header_by_type(message,belle_sip_header_content_type_t); if (content_type){ if (strcmp("application",belle_sip_header_content_type_get_type(content_type))==0 && strcmp("sdp",belle_sip_header_content_type_get_subtype(content_type))==0) { *session_desc=belle_sdp_session_description_parse(body); if (*session_desc==NULL) { ms_error("Failed to parse SDP message."); *error=SalReasonNotAcceptable; return -1; } }else{ *error=SalReasonUnsupportedContent; return -1; } }else *session_desc=NULL; return 0; }
int main(int argc, char *argv[]){ char *str; struct stat st; int fd; int i; const char *filename=NULL; const char *protocol="sip"; if (argc<2){ fprintf(stderr,"Usage:\n%s [--protocol sip|http|sdp] <text file containing messages>\n",argv[0]); return -1; } for(i=1;i<argc;++i){ if (strcmp(argv[i],"--protocol")==0){ i++; if (i<argc){ protocol=argv[i]; }else{ fprintf(stderr,"Missing argument for --protocol\n"); return -1; } }else filename=argv[i]; } if (!filename){ fprintf(stderr,"No filename specified\n"); return -1; } if (stat(filename,&st)==-1){ fprintf(stderr,"Could not stat %s: %s\n",filename,strerror(errno)); return -1; } fd=open(filename,O_RDONLY); if (fd==-1){ fprintf(stderr,"Could not open %s: %s\n",filename,strerror(errno)); return -1; } str=belle_sip_malloc0(st.st_size+1); if (read(fd,str,st.st_size)==-1){ fprintf(stderr,"Could not read %s: %s\n",filename,strerror(errno)); belle_sip_free(str); close(fd); return -1; } close(fd); belle_sip_set_log_level(BELLE_SIP_LOG_DEBUG); for (i=0;i<st.st_size;){ size_t read; if (strcasecmp(protocol,"sip")==0 || strcasecmp(protocol,"http")==0){ belle_sip_message_t *msg; uint64_t begin,end; begin=belle_sip_time_ms(); msg=belle_sip_message_parse_raw(str+i,st.st_size-i,&read); end=belle_sip_time_ms(); if (msg){ printf("Successfully parsed %s message of %i bytes in %i ms.\n",protocol,(int)read, (int)(end-begin)); }else{ fprintf(stderr,"Failed to parse message.\n"); break; } i+=read; }else if (strcasecmp(protocol,"sdp")==0){ belle_sdp_session_description_t *sdp=belle_sdp_session_description_parse(str); if (sdp){ printf("Successfully parsed %s message of %i bytes.\n",protocol,(int)strlen(str)); }else{ fprintf(stderr,"Failed to parse SDP message.\n"); } break; } } belle_sip_free(str); return 0; }
static void test_simple_session_description(void) { const char* l_src = "v=0\r\n"\ "o=jehan-mac 1239 1239 IN IP4 192.168.0.18\r\n"\ "s=Talk\r\n"\ "c=IN IP4 192.168.0.18\r\n"\ "t=0 0\r\n"\ "m=audio 7078 RTP/AVP 111 110 3 0 8 101\r\n"\ "a=rtpmap:111 speex/16000\r\n"\ "a=fmtp:111 vbr=on\r\n"\ "a=rtpmap:110 speex/8000\r\n"\ "a=fmtp:110 vbr=on\r\n"\ "a=rtpmap:101 telephone-event/8000\r\n"\ "a=fmtp:101 0-11\r\n"\ "m=video 8078 RTP/AVP 99 97 98\r\n"\ "c=IN IP4 192.168.0.18\r\n"\ "b=AS:380\r\n"\ "a=rtpmap:99 MP4V-ES/90000\r\n"\ "a=fmtp:99 profile-level-id=3\r\n"\ "a=rtpmap:97 theora/90000\r\n"\ "a=rtpmap:98 H263-1998/90000\r\n"\ "a=fmtp:98 CIF=1;QCIF=1\r\n"; belle_sdp_origin_t* l_origin; belle_sip_list_t* media_descriptions; belle_sdp_session_description_t* lTmp; belle_sdp_session_description_t* l_session_description = belle_sdp_session_description_parse(l_src); char* l_raw_session_description = belle_sip_object_to_string(BELLE_SIP_OBJECT(l_session_description)); belle_sip_object_unref(BELLE_SIP_OBJECT(l_session_description)); lTmp = belle_sdp_session_description_parse(l_raw_session_description); belle_sip_free(l_raw_session_description); l_session_description = BELLE_SDP_SESSION_DESCRIPTION(belle_sip_object_clone(BELLE_SIP_OBJECT(lTmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(lTmp)); CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_version(l_session_description)); CU_ASSERT_EQUAL(belle_sdp_version_get_version(belle_sdp_session_description_get_version(l_session_description)),0); l_origin = belle_sdp_session_description_get_origin(l_session_description); CU_ASSERT_PTR_NOT_NULL(l_origin); CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address(l_origin),"192.168.0.18") CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_address_type(l_origin),"IP4") CU_ASSERT_STRING_EQUAL(belle_sdp_origin_get_network_type(l_origin),"IN") CU_ASSERT_EQUAL(belle_sdp_origin_get_session_id(l_origin),1239) CU_ASSERT_EQUAL(belle_sdp_origin_get_session_version(l_origin),1239) CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_session_name(l_session_description)); CU_ASSERT_STRING_EQUAL(belle_sdp_session_name_get_value(belle_sdp_session_description_get_session_name(l_session_description)),"Talk"); CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_connection(l_session_description)); CU_ASSERT_PTR_NOT_NULL(belle_sdp_session_description_get_time_descriptions(l_session_description)); CU_ASSERT_EQUAL(belle_sdp_time_get_start(belle_sdp_time_description_get_time((belle_sdp_time_description_t*)(belle_sdp_session_description_get_time_descriptions(l_session_description)->data))),0); CU_ASSERT_EQUAL(belle_sdp_time_get_stop(belle_sdp_time_description_get_time((belle_sdp_time_description_t*)(belle_sdp_session_description_get_time_descriptions(l_session_description)->data))),0); media_descriptions = belle_sdp_session_description_get_media_descriptions(l_session_description); CU_ASSERT_PTR_NOT_NULL(media_descriptions); CU_ASSERT_STRING_EQUAL (belle_sdp_media_get_media_type(belle_sdp_media_description_get_media((belle_sdp_media_description_t*)(media_descriptions->data))),"audio"); media_descriptions=media_descriptions->next; CU_ASSERT_PTR_NOT_NULL(media_descriptions); test_media_description_base((belle_sdp_media_description_t*)(media_descriptions->data)); belle_sip_object_unref(l_session_description); return; }