int main() #endif { #if RUN_TEST_LOOP for(;;) #endif { tnet_startup(); /* Print copyright information */ printf("Doubango Project\nCopyright (C) 2009 - 2010 Mamadou Diop \n\n"); #if RUN_TEST_ALL || RUN_TEST_URI test_uri(); #endif #if RUN_TEST_ALL || RUN_TEST_PARSER test_parser(); #endif #if RUN_TEST_ALL || RUN_TEST_SESSION test_session(); #endif tnet_cleanup(); } }
/** * @fn tnet_startup * This is probably the most important function. You MUST call this function to initialize the network stack before calling any <b>tnet_*</b> function. * You MUST call @ref tnet_cleanup to cleanup the network stack. * * @sa @ref tnet_cleanup. * @return Zero if succeed and error code otherwise. **/ int tnet_startup() { int err = 0; short word = 0x4321; if(__tnet_started){ goto bail; } // rand() srand((unsigned int) tsk_time_epoch()); // endianness tnet_isBigEndian = ((*(int8_t *)&word) != 0x21); #if TNET_UNDER_WINDOWS if(tnet_isBigEndian){ TSK_DEBUG_ERROR("Big endian on Windows machine. Is it right?"); } #endif #if TNET_UNDER_WINDOWS { WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 2); err = WSAStartup(wVersionRequested, &wsaData); if (err != 0) { TSK_DEBUG_FATAL("WSAStartup failed with error: %d\n", err); return -1; } if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2){ TSK_DEBUG_FATAL("Could not find a usable version of Winsock.dll\n"); tnet_cleanup(); return -2; } else{ __tnet_started = tsk_true; TSK_DEBUG_INFO("The Winsock 2.2 dll was found okay\n"); } } #else __tnet_started = tsk_true; #endif /* TNET_UNDER_WINDOWS */ bail: return err; }
int main() #endif { tnet_startup(); #if RUN_TEST_LOOP for(;;) #endif { /* Print copyright information */ printf("Doubango Project\nCopyright (C) 2009 - 2010 Mamadou Diop \n\n"); #if RUN_TEST_ALL || RUN_TEST_MESSAGES test_messages(); #endif #if RUN_TEST_ALL || RUN_TEST_URI test_uri(); #endif #if RUN_TEST_ALL ||RUN_TEST_TRANSAC test_transac(); #endif #if RUN_TEST_ALL || RUN_TEST_STACK test_stack(); #endif #if RUN_TEST_ALL || RUN_TEST_IMS_AKA test_imsaka(); #endif } tnet_cleanup(); return 0; }
/* === entry point === */ int main(int argc, char** argv) { char cmdbuf[4096]; tsk_buffer_t* buffer = tsk_null; cmd_t* cmd = tsk_null; tsk_bool_t comment = tsk_false; int ret; int i, index; const char* start = tsk_null, *end = tsk_null; int a = 32 | 1 | 2; /* Copyright */ printf("Doubango Project (tinyDEMO)\nCopyright (C) 2009 - 2013 Mamadou Diop \n\n"); /* Initialize Network Layer ==> Mandatory */ tnet_startup(); /* Initialize Doubango Audio/Video Framework ==> will register all plugins(codecs and sessions) * Not mandatory if you have your own plugins*/ tdav_init(); /* Print Usage */ //cmd_print_help(); /* create user's ctx */ if(!(ctx = ctx_create()) || !ctx->stack){ TSK_DEBUG_ERROR("Failed to create user's ctx."); goto bail; } /* create new buffer */ if(!(buffer = tsk_buffer_create_null())){ TSK_DEBUG_ERROR("Failed to create new buffer."); goto bail; } /* initial args */ for(i=1 /* index zero contains the exe path */, index=0; i<argc && argv[i]; i++){ if(index){ tsk_buffer_append(buffer, " ", 1); } tsk_buffer_append(buffer, argv[i], tsk_strlen(argv[i])); } /* If initial args ==> parse it now */ if(buffer->size){ TSK_DEBUG_INFO("Initial command-line: %s", buffer->data); goto init_buffer; } /* always use fgets() instead of gets. gets() is considered to be unsafe.(Android and Mac OS X will warn) */ while(fgets(cmdbuf, sizeof(cmdbuf), stdin)){ TSK_DEBUG_INFO("Command-Line: %s", cmdbuf); tsk_buffer_cleanup(buffer); /* cannot read from console while executing scenario */ tsk_buffer_append(buffer, cmdbuf, tsk_strlen(cmdbuf)); init_buffer: start = buffer->data; //start = trim(start); end = start + buffer->size; if(start >= end){ TSK_DEBUG_INFO("Empty buffer"); continue; } parse_buffer: TSK_OBJECT_SAFE_FREE(cmd); /* Free old value */ cmd = cmd_parse(start, (end-start), &comment, ctx->params); if(cmd){ if(comment || cmd->type == cmd_none){ goto nex_line; } } else{ continue; } /* Load from scenario file? */ if(cmd->type == cmd_scenario){ FILE* file; const opt_t* opt; tsk_size_t read = 0; tsk_bool_t rm_lf = tsk_false; if((opt = opt_get_by_type(cmd->opts, opt_path)) && !tsk_strnullORempty(opt->value)){ /* --path option */ if((file = fopen(opt->value, "r"))){ memset(cmdbuf, '\0', sizeof(cmdbuf)), cmdbuf[0] = '\n'; read = fread(cmdbuf+1, sizeof(uint8_t), sizeof(cmdbuf)-1, file); fclose(file), file = tsk_null; if(read == 0){ TSK_DEBUG_ERROR("[%s] is empty.", opt->value); goto nex_line; } else if(read == sizeof(cmdbuf)-1){ TSK_DEBUG_ERROR("Buffer too short."); goto nex_line; } read++; /* \n */ /* repplace all '\' with spaces (easier than handling that in the ragel file) */ for(i=0; ((tsk_size_t)i)<read; i++){ if(cmdbuf[i] == '\\'){ cmdbuf[i] = ' '; rm_lf = tsk_true; } else if(rm_lf && cmdbuf[i] == '\n'){ cmdbuf[i] = ' '; rm_lf = tsk_false; } } cmdbuf[read] = '\n'; /* insert embedded scenario */ if((index = tsk_strindexOf(start, (end-start), "\n")) == -1){ /* ++sn line */ index = buffer->size; } else{ index += (start - ((const char*)buffer->data)); } if(tsk_buffer_insert(buffer, index, cmdbuf, read)){ continue; } else{ start = ((const char*)buffer->data) + index; // because insert use realloc() end = (((const char*)buffer->data) + buffer->size); goto nex_line; } } else{ TSK_DEBUG_ERROR("Failed to open scenario-file [%s].", opt->value); goto nex_line; } continue; } else{ TSK_DEBUG_ERROR("++scenario command must have --path option."); continue; } } /* execute current command */ switch(cmd->type){ case cmd_exit: TSK_DEBUG_INFO("Exit/Quit"); goto bail; default: ret = execute(cmd); break; } /* next line */ nex_line: if((index = tsk_strindexOf(start, (end - start), "\n")) !=-1){ start += index; while((start < end) && isspace(*start)){ start ++; } if((start + 2/*++*/) < end){ goto parse_buffer; /* next line */ } else{ continue; /* wait for new commands */ } } } /* while(buffer) */ bail: /* Free current command */ TSK_OBJECT_SAFE_FREE(cmd); /* Free buffer */ TSK_OBJECT_SAFE_FREE(buffer); /* Destroy the user's ctx */ TSK_OBJECT_SAFE_FREE(ctx); /* Deinitialize Doubango Audio/Video Framework ==> will unregister all plugins(codecs and sessions) * Not mandatory */ tdav_init(); /* Uninitilize Network Layer */ tnet_cleanup(); #if ANDROID exit(0); #endif return 0; }
int main() #endif { /* Startup the network stack. */ if(tnet_startup()){ return -1; } #if RUN_TEST_LOOP for(;;) #endif { #if RUN_TEST_ALL || RUN_TEST_SOCKETS test_sockets(); #endif #if RUN_TEST_ALL || RUN_TEST_TRANSPORT test_transport(); #endif #if RUN_TEST_ALL || RUN_TEST_AUTH test_auth(); #endif #if RUN_TEST_ALL || RUN_TEST_STUN test_stun(); #endif #if RUN_TEST_ALL || RUN_TEST_ICE test_ice(); #endif #if RUN_TEST_ALL || RUN_TEST_NAT test_nat(); #endif #if RUN_TEST_ALL || RUN_TEST_IFACES test_ifaces(); #endif #if RUN_TEST_ALL || RUN_TEST_DNS test_dns(); #endif #if RUN_TEST_ALL || RUN_TEST_DHCP test_dhcp(); #endif #if RUN_TEST_ALL || RUN_TEST_DHCP6 test_dhcp6(); #endif #if RUN_TEST_ALL || RUN_TEST_TLS test_tls(); #endif } /* Cleanup the network stack */ tnet_cleanup(); return 0; }
/** * @fn tnet_startup * This is probably the most important function. You MUST call this function to initialize the network stack before calling any <b>tnet_*</b> function. * You MUST call @ref tnet_cleanup to cleanup the network stack. * * @sa @ref tnet_cleanup. * @return Zero if succeed and error code otherwise. **/ int tnet_startup() { int err = 0; short word = 0x4321; if(__tnet_started){ goto bail; } // rand() srand((unsigned int) tsk_time_epoch()); // endianness tnet_isBigEndian = ((*(int8_t *)&word) != 0x21); #if TNET_UNDER_WINDOWS if(tnet_isBigEndian){ TSK_DEBUG_ERROR("Big endian on Windows machine. Is it right?"); } #endif #if TNET_UNDER_WINDOWS { WORD wVersionRequested; WSADATA wsaData; wVersionRequested = MAKEWORD(2, 2); err = WSAStartup(wVersionRequested, &wsaData); if (err != 0) { fprintf(stderr, "WSAStartup failed with error: %d\n", err); return -1; } if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2){ fprintf(stderr, "Could not find a usable version of Winsock.dll\n"); tnet_cleanup(); return -2; } else{ fprintf(stdout, "The Winsock 2.2 dll was found okay\n"); } } #endif /* TNET_UNDER_WINDOWS */ #if HAVE_OPENSSL //fprintf(stdout, "SSL is enabled :)\n"); SSL_library_init(); OpenSSL_add_all_algorithms(); SSL_load_error_strings(); //fprintf(stdout, "DTLS supported: %s\n", tnet_dtls_is_supported() ? "yes" : "no"); //fprintf(stdout, "DTLS-SRTP supported: %s\n", tnet_dtls_is_srtp_supported() ? "yes" : "no"); #else //fprintf(stderr, "SSL is disabled :(\n"); #endif __tnet_started = tsk_true; bail: return err; }