int main (int argc, char *argv[]) { int i; int ret; const char *root_ca_path = NULL; const char *env_domain=getenv("TEST_DOMAIN"); belle_sip_tester_init(NULL); #ifndef WIN32 /*this hack doesn't work for argv[0]="c:\blablab\"*/ // this allows to launch liblinphone_tester from outside of tester directory if (strstr(argv[0], ".libs")) { int prefix_length = strstr(argv[0], ".libs") - argv[0] + 1; char *prefix = belle_sip_strdup_printf("%s%.*s", argv[0][0] == '/' ? "" : "./", prefix_length, argv[0]); // printf("Resource prefix set to %s\n", prefix); bc_tester_set_resource_dir_prefix(prefix); bc_tester_set_writable_dir_prefix(prefix); belle_sip_free(prefix); } #endif if (env_domain) { test_domain=env_domain; } for(i=1;i<argc;++i){ if (strcmp(argv[i],"--verbose")==0){ belle_sip_set_log_level(BELLE_SIP_LOG_DEBUG); } else if (strcmp(argv[i],"--silent")==0){ belle_sip_set_log_level(BELLE_SIP_LOG_FATAL); } else if (strcmp(argv[i],"--log-file")==0){ CHECK_ARG("--log-file", ++i, argc); if (belle_sip_tester_set_log_file(argv[i]) < 0) return -2; } else if (strcmp(argv[i],"--domain")==0){ CHECK_ARG("--domain", ++i, argc); test_domain=argv[i]; }else if (strcmp(argv[i],"--auth-domain")==0){ CHECK_ARG("--auth-domain", ++i, argc); auth_domain=argv[i]; } else if (strcmp(argv[i], "--root-ca") == 0) { CHECK_ARG("--root-ca", ++i, argc); root_ca_path = argv[i]; }else { int ret = bc_tester_parse_args(argc, argv, i); if (ret>0) { i += ret - 1; continue; } else if (ret<0) { bc_tester_helper(argv[0], belle_sip_helper); } return ret; } } belle_sip_tester_set_root_ca_path(root_ca_path); pool=belle_sip_object_pool_push(); ret = bc_tester_start(argv[0]); belle_sip_tester_uninit(); return ret; }
int main (int argc, char *argv[]) { int i; int ret; const char *root_ca_path = NULL; const char *env_domain=getenv("TEST_DOMAIN"); belle_sip_tester_init(); if (env_domain) { test_domain=env_domain; } for(i=1;i<argc;++i){ if (strcmp(argv[i],"--verbose")==0){ belle_sip_set_log_level(BELLE_SIP_LOG_DEBUG); } else if (strcmp(argv[i],"--silent")==0){ belle_sip_set_log_level(BELLE_SIP_LOG_FATAL); } else if (strcmp(argv[i],"--log-file")==0){ CHECK_ARG("--log-file", ++i, argc); log_file=fopen(argv[i],"w"); if (!log_file) { belle_sip_error("Cannot open file [%s] for writing logs because [%s]",argv[i],strerror(errno)); return -2; } else { belle_sip_message("Redirecting traces to file [%s]",argv[i]); belle_sip_set_log_file(log_file); } } else if (strcmp(argv[i],"--domain")==0){ CHECK_ARG("--domain", ++i, argc); test_domain=argv[i]; }else if (strcmp(argv[i],"--auth-domain")==0){ CHECK_ARG("--auth-domain", ++i, argc); auth_domain=argv[i]; } else if (strcmp(argv[i], "--root-ca") == 0) { CHECK_ARG("--root-ca", ++i, argc); root_ca_path = argv[i]; }else { int ret = bc_tester_parse_args(argc, argv, i); if (ret>0) { i += ret - 1; continue; } else if (ret<0) { bc_tester_helper(argv[0], belle_sip_helper); } return ret; } } belle_sip_tester_set_root_ca_path(root_ca_path); pool=belle_sip_object_pool_push(); ret = bc_tester_start(); belle_sip_tester_uninit(); return ret; }
void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){ size_t pfd_size = ml->nsources * sizeof(belle_sip_pollfd_t); belle_sip_pollfd_t *pfd=(belle_sip_pollfd_t*)belle_sip_malloc0(pfd_size); int i=0; belle_sip_source_t *s; belle_sip_list_t *elem,*next; uint64_t min_time_ms=(uint64_t)-1; int duration=-1; int ret; uint64_t cur; belle_sip_list_t *to_be_notified=NULL; int can_clean=belle_sip_object_pool_cleanable(ml->pool); /*iterate might not be called by the thread that created the main loop*/ belle_sip_object_pool_t *tmp_pool=NULL; if (!can_clean){ /*Push a temporary pool for the time of the iterate loop*/ tmp_pool=belle_sip_object_pool_push(); } /*Step 1: prepare the pollfd table and get the next timeout value */ for(elem=ml->sources;elem!=NULL;elem=next){ next=elem->next; s=(belle_sip_source_t*)elem->data; if (!s->cancelled){ if (s->fd!=(belle_sip_fd_t)-1){ belle_sip_source_to_poll(s,pfd,i); ++i; } if (s->timeout>=0){ if (min_time_ms>s->expire_ms){ min_time_ms=s->expire_ms; } } } } if (min_time_ms!=(uint64_t)-1 ){ int64_t diff; /* compute the amount of time to wait for shortest timeout*/ cur=belle_sip_time_ms(); diff=min_time_ms-cur; if (diff>0) duration=(int)diff; else duration=0; } /* do the poll */ ret=belle_sip_poll(pfd,i,duration); if (ret==-1){ goto end; } /* Step 2: examine poll results and determine the list of source to be notified */ cur=belle_sip_time_ms(); for(elem=ml->sources;elem!=NULL;elem=elem->next){ unsigned revents=0; s=(belle_sip_source_t*)elem->data; if (!s->cancelled){ if (s->fd!=(belle_sip_fd_t)-1){ if (s->notify_required) { /*for testing purpose to force channel to read*/ revents=BELLE_SIP_EVENT_READ; s->notify_required=0; /*reset*/ } else { revents=belle_sip_source_get_revents(s,pfd); } s->revents=revents; } if (revents!=0 || (s->timeout>=0 && cur>=s->expire_ms)){ to_be_notified=belle_sip_list_append(to_be_notified,belle_sip_object_ref(s)); s->expired=TRUE; if (s->revents==0) s->revents=BELLE_SIP_EVENT_TIMEOUT; } }else to_be_notified=belle_sip_list_append(to_be_notified,belle_sip_object_ref(s)); } /* Step 3: notify those to be notified */ for(elem=to_be_notified;elem!=NULL;){ s=(belle_sip_source_t*)elem->data; next=elem->next; if (!s->cancelled){ char *objdesc=belle_sip_object_to_string((belle_sip_object_t*)s); if (s->timeout>0)/*to avoid too many traces*/ belle_sip_debug("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout); belle_sip_free(objdesc); ret=s->notify(s->data,s->revents); if (ret==BELLE_SIP_STOP || s->oneshot){ /*this source needs to be removed*/ belle_sip_main_loop_remove_source(ml,s); }else if (s->revents==BELLE_SIP_EVENT_TIMEOUT){ /*timeout needs to be started again */ s->expire_ms+=s->timeout; s->expired=FALSE; } }else belle_sip_main_loop_remove_source(ml,s); belle_sip_object_unref(s); belle_sip_free(elem); /*free just the element*/ elem=next; } if (can_clean) belle_sip_object_pool_clean(ml->pool); else if (tmp_pool) belle_sip_object_unref(tmp_pool); end: belle_sip_free(pfd); }
belle_sip_main_loop_t *belle_sip_main_loop_new(void){ belle_sip_main_loop_t*m=belle_sip_object_new(belle_sip_main_loop_t); m->pool=belle_sip_object_pool_push(); return m; }