int InitMutex(wolfSSL_Mutex* m) { if (rtp_sig_mutex_alloc(m, "wolfSSL Mutex") == -1) return BAD_MUTEX_E; else return 0; }
/************************************************************************ * Internal utility functions ************************************************************************/ unsigned _rtp_InitDebugOutput (void) { #ifdef RTP_DEBUG_MULTITHREAD if (!rtpDebugInitialized) { if (rtp_sig_mutex_alloc(&rtpDebugLock, 0) >= 0) { rtpDebugInitialized = 1; } } return (rtpDebugInitialized); #else return (1); #endif }
/*---------------------------------------------------------------------------*/ int rtp_timer_init (void) { if (rtpTimerInitialized == 0) { if (rtp_sig_mutex_alloc(&rtpTimerLock, 0) >= 0) { if (rtp_sig_semaphore_alloc(&rtpTimerSignal, 0) >= 0) { RTP_THREAD newThread; DLLIST_INIT(&rtpTimerNewList); DLLIST_INIT(&rtpTimerActiveList); rtpTimerNextToProcess = 0; if (rtp_thread_spawn (&newThread, _rtp_timer_thread, 0, 0, 2, 0) >= 0) { rtpTimerInitialized = 1; return (0); } rtp_sig_semaphore_free(rtpTimerSignal); } else { rtp_printf("rtp_timer_init - rtp_sig_semaphore_alloc failed!\n"); } rtp_sig_mutex_free(rtpTimerLock); } else { rtp_printf("rtp_timer_init - rtp_sig_mutex_alloc failed!"); } return (-1); } rtpTimerInitialized++; return (0); }
/*---------------------------------------------------------------------------*/ int rtp_queue_init (RTPMessageQueue *queue, int queueSize, long msgSize, void *messages) { tc_memset(queue, 0, sizeof(RTPMessageQueue)); if (rtp_sig_mutex_alloc(&queue->lock, 0) < 0) { return (-1); } if (rtp_sig_semaphore_alloc(&queue->sem, 0) < 0) { rtp_sig_mutex_free(queue->lock); return (-1); } queue->queueSize = queueSize; queue->msgSize = msgSize; queue->first = 0; queue->last = 0; queue->messages = messages; return (0); }
int rtsmb_client_config(void) { int i, j; if (rtsmb_client_config_initialized) { return 1; } #if ALLOC_FROM_HEAP else { RTSMB_CLI_SESSION * sessions = safemalloc(sizeof(RTSMB_CLI_SESSION ) * CFG_RTSMB_CLI_MAX_SESSIONS); RTSMB_CLI_SESSION_JOB * jobs = safemalloc(sizeof(RTSMB_CLI_SESSION_JOB ) * CFG_RTSMB_CLI_MAX_SESSIONS * CFG_RTSMB_CLI_MAX_JOBS_PER_SESSION); RTSMB_CLI_SESSION_SHARE * shares = safemalloc(sizeof(RTSMB_CLI_SESSION_SHARE ) * CFG_RTSMB_CLI_MAX_SESSIONS * CFG_RTSMB_CLI_MAX_SHARES_PER_SESSION); RTSMB_CLI_SESSION_FID * fids = safemalloc(sizeof(RTSMB_CLI_SESSION_FID ) * CFG_RTSMB_CLI_MAX_SESSIONS * CFG_RTSMB_CLI_MAX_FIDS_PER_SESSION); RTSMB_CLI_SESSION_SEARCH * searches = safemalloc(sizeof(RTSMB_CLI_SESSION_SEARCH ) * CFG_RTSMB_CLI_MAX_SESSIONS * CFG_RTSMB_CLI_MAX_SEARCHES_PER_SESSION); RTSMB_CLI_SESSION_SSTAT * share_search_stats = safemalloc(sizeof(RTSMB_CLI_SESSION_SSTAT ) * CFG_RTSMB_CLI_MAX_SESSIONS * CFG_RTSMB_CLI_MAX_SHARES_PER_SEARCH); RTSMB_CLI_SESSION_DSTAT * file_search_stats = safemalloc(sizeof(RTSMB_CLI_SESSION_DSTAT ) * CFG_RTSMB_CLI_MAX_SESSIONS * CFG_RTSMB_CLI_MAX_SEARCHES_PER_SESSION * CFG_RTSMB_CLI_MAX_FILES_PER_SEARCH); byte * wire_temp_buffers = safemalloc(sizeof(byte ) * CFG_RTSMB_CLI_MAX_SESSIONS * CFG_RTSMB_CLI_BUFFER_SIZE); RTSMB_CLI_WIRE_BUFFER * wire_buffers = safemalloc(sizeof(RTSMB_CLI_WIRE_BUFFER ) * CFG_RTSMB_CLI_MAX_SESSIONS * CFG_RTSMB_CLI_MAX_BUFFERS_PER_WIRE); byte * wire_buffer_buffers = safemalloc(sizeof(byte ) * CFG_RTSMB_CLI_MAX_SESSIONS * CFG_RTSMB_CLI_MAX_BUFFERS_PER_WIRE * CFG_RTSMB_CLI_BUFFER_SIZE); RTSMB_CLI_SESSION_SERVER_SEARCH * server_search_results = safemalloc(sizeof(RTSMB_CLI_SESSION_SERVER_SEARCH) * CFG_RTSMB_CLI_MAX_SERVER_SEARCHES); BBOOL * server_search_in_use = safemalloc(sizeof(BBOOL ) * CFG_RTSMB_CLI_MAX_SERVER_SEARCHES); RTSMB_CHAR16 * server_search_names = safemalloc(sizeof(RTSMB_CHAR16 ) * CFG_RTSMB_CLI_MAX_SERVER_SEARCHES * CFG_RTSMB_CLI_MAX_SERVERS_PER_SEARCH * RTSMB_NB_NAME_SIZE); #if (INCLUDE_RTSMB_CLIENT_EZ) RTSMB_CLI_EZ_SEARCH * ez_share_searches = safemalloc(sizeof(RTSMB_CLI_EZ_SEARCH ) * CFG_RTSMB_CLI_MAX_SESSIONS); RTSMB_CLI_EZ_SEARCH * ez_server_searches = safemalloc(sizeof(RTSMB_CLI_EZ_SEARCH ) * CFG_RTSMB_CLI_MAX_SERVER_SEARCHES); RTSMB_CLI_SESSION_SRVSTAT * ez_server_stats = safemalloc(sizeof(RTSMB_CLI_SESSION_SRVSTAT ) * CFG_RTSMB_CLI_MAX_SERVER_SEARCHES); RTSMB_CLI_EZ_THREAD * ez_threads = safemalloc(sizeof(RTSMB_CLI_EZ_THREAD ) * CFG_RTSMB_CLI_MAX_SUPPORTED_THREADS); #endif } #endif #ifdef INCLUDE_RTSMB_THREADSAFE if (rtp_sig_mutex_alloc((RTP_MUTEX *) &prtsmb_cli_ctx->sessions_mutex, 0) < 0) { return 0; } if (rtp_sig_mutex_alloc((RTP_MUTEX *) &prtsmb_cli_ctx->server_search_mutex, 0) < 0) { rtp_sig_mutex_free(prtsmb_cli_ctx->sessions_mutex); return 0; } #if (INCLUDE_RTSMB_CLIENT_EZ) if (rtp_sig_mutex_alloc((RTP_MUTEX *) &prtsmb_cli_ctx->ez_threads_mutex, 0) < 0) { rtp_sig_mutex_free(prtsmb_cli_ctx->server_search_mutex); rtp_sig_mutex_free(prtsmb_cli_ctx->sessions_mutex); return 0; } #endif #endif /* INCLUDE_RTSMB_THREADSAFE */ prtsmb_cli_ctx->max_sessions = CFG_RTSMB_CLI_MAX_SESSIONS; prtsmb_cli_ctx->max_searches_per_session = CFG_RTSMB_CLI_MAX_SEARCHES_PER_SESSION; prtsmb_cli_ctx->max_fids_per_session = CFG_RTSMB_CLI_MAX_FIDS_PER_SESSION; prtsmb_cli_ctx->max_shares_per_session = CFG_RTSMB_CLI_MAX_SHARES_PER_SESSION; prtsmb_cli_ctx->max_jobs_per_session = CFG_RTSMB_CLI_MAX_JOBS_PER_SESSION; prtsmb_cli_ctx->max_buffers_per_wire = CFG_RTSMB_CLI_MAX_BUFFERS_PER_WIRE; prtsmb_cli_ctx->buffer_size = CFG_RTSMB_CLI_BUFFER_SIZE; prtsmb_cli_ctx->max_shares_per_search = CFG_RTSMB_CLI_MAX_SHARES_PER_SEARCH; prtsmb_cli_ctx->max_server_searches = CFG_RTSMB_CLI_MAX_SERVER_SEARCHES; prtsmb_cli_ctx->max_servers_per_search = CFG_RTSMB_CLI_MAX_SERVERS_PER_SEARCH; prtsmb_cli_ctx->max_files_per_search = CFG_RTSMB_CLI_MAX_FILES_PER_SEARCH; prtsmb_cli_ctx->max_supported_threads = CFG_RTSMB_CLI_MAX_SUPPORTED_THREADS; prtsmb_cli_ctx->sessions = sessions; prtsmb_cli_ctx->server_search_results = server_search_results; prtsmb_cli_ctx->server_search_in_use = server_search_in_use; #if (INCLUDE_RTSMB_CLIENT_EZ) prtsmb_cli_ctx->ez_share_searches = ez_share_searches; prtsmb_cli_ctx->ez_server_searches = ez_server_searches; prtsmb_cli_ctx->ez_server_stats = ez_server_stats; prtsmb_cli_ctx->ez_threads = ez_threads; #endif #if (INCLUDE_RTSMB_CLIENT_EZ) for (i = 0; i < prtsmb_cli_ctx->max_supported_threads; i++) { prtsmb_cli_ctx->ez_threads[i].in_use = FALSE; } #endif for (i = 0; i < prtsmb_cli_ctx->max_server_searches; i++) { #if (INCLUDE_RTSMB_CLIENT_EZ) prtsmb_cli_ctx->ez_server_stats[i].sid = -1; #endif prtsmb_cli_ctx->server_search_results[i].srvstats = &server_search_names[i * prtsmb_cli_ctx->max_servers_per_search * RTSMB_NB_NAME_SIZE]; } for (i = 0; i < prtsmb_cli_ctx->max_sessions; i++) { sessions[i].state = CSSN_STATE_UNUSED; sessions[i].jobs = &jobs [i * prtsmb_cli_ctx->max_jobs_per_session]; sessions[i].shares = &shares [i * prtsmb_cli_ctx->max_shares_per_session]; sessions[i].fids = &fids [i * prtsmb_cli_ctx->max_fids_per_session]; sessions[i].searches = &searches [i * prtsmb_cli_ctx->max_searches_per_session]; sessions[i].wire.temp_buffer = &wire_temp_buffers [(dword)i * prtsmb_cli_ctx->buffer_size]; sessions[i].wire.buffers = &wire_buffers [i * prtsmb_cli_ctx->max_buffers_per_wire]; /* default to TCP over ethernet payload size */ sessions[i].wire.physical_packet_size = 1460; sessions[i].share_search.sstats = &share_search_stats [i * prtsmb_cli_ctx->max_shares_per_search]; for (j = 0; j < prtsmb_cli_ctx->max_buffers_per_wire; j++) { sessions[i].wire.buffers[j].buffer = &wire_buffer_buffers [(dword)(i * prtsmb_cli_ctx->max_buffers_per_wire + j) * prtsmb_cli_ctx->buffer_size]; } for (j = 0; j < prtsmb_cli_ctx->max_searches_per_session; j++) { sessions[i].searches[j].dstats = &file_search_stats [(i * prtsmb_cli_ctx->max_searches_per_session + j) * prtsmb_cli_ctx->max_files_per_search]; } } rtsmb_client_config_initialized = 1; return 1; }
/** @memo Initialize a UPnPRuntime @doc Initializes the given \Ref{UPnPRuntime} struct, and sets up an HTTP server instance to receive control/event messages. This function must be called before any other function in the UPnP SDK. @return error code */ int UPnP_RuntimeInit ( UPnPRuntime* rt, /** pointer to uninitialized \Ref{UPnPRuntime} struct */ UPNP_UINT8* serverAddr, /** ip address to bind HTTP server to (NULL for IP_ADDR_ANY) */ UPNP_UINT16 serverPort, /** port to bind HTTP server to (0 for ANY_PORT) */ UPNP_INT16 ipType, /** type of ip version used (ipv4 or ipv6), (RTP_NET_TYPE_IPV4 for v4 and RTP_NET_TYPE_IPV6 for v6) */ UPNP_CHAR* wwwRootDir, /** HTTP root dir on local file system */ UPNP_INT16 maxConnections, /** the maximum limit on simultaneous HTTP server connections */ UPNP_INT16 maxHelperThreads /** if UPNP_MULTITHREAD is defined, the max number of helper threads to spawn */ ) { HTTPServerConnection* connectCtxArray; rt->ipType = ipType; connectCtxArray = (HTTPServerConnection*) rtp_malloc(sizeof(HTTPServerConnection) * maxConnections); if (connectCtxArray) { if (HTTP_ServerInit ( &rt->httpServer, UPNP_SERVER_NAME, // name wwwRootDir, // rootDir "index.html", // defaultFile 1, // httpMajorVersion 1, // httpMinorVersion serverAddr, // ipAddr serverPort, // port, ipType, // ipversion type(4 or 6) 0, // allowKeepAlive connectCtxArray, // connectCtxArray maxConnections, // maxConnections maxHelperThreads // maxHelperThreads ) >= 0) { if (SSDP_ServerInit ( &rt->ssdpContext, serverAddr, ipType, "RTPlatform/1.0, UPnP/1.0, EBS UPnPSDK/2.9", UPnP_SSDPCallback, rt ) >= 0) { #ifdef UPNP_MULTITHREAD if (rtp_sig_mutex_alloc(&rt->mutex, 0) >= 0) { rt->daemonState = UPNP_DAEMON_STOPPED; #endif /* UPNP_MULTITHREAD */ rt->deviceRuntime = 0; rt->controlPoint = 0; return (0); #ifdef UPNP_MULTITHREAD } #endif /* UPNP_MULTITHREAD */ SSDP_ServerDestroy(&rt->ssdpContext); } HTTP_ServerDestroy(&rt->httpServer, &connectCtxArray); } rtp_free(connectCtxArray); } return (-1); }
int rtsmb_server_config(void) { int i; prtsmb_srv_ctx = &rtsmb_srv_cfg_core; #if ALLOC_FROM_HEAP unsigned char * bigBuffers = safemalloc(sizeof(unsigned char ) * CFG_RTSMB_BIG_BUFFER_SIZE * CFG_RTSMB_NUM_BIG_BUFFERS); char * bigBufferInUse = safemalloc(sizeof(char ) * CFG_RTSMB_NUM_BIG_BUFFERS); NET_THREAD_T * threads = safemalloc(sizeof(NET_THREAD_T ) * (CFG_RTSMB_MAX_THREADS + 1)); char * threadsInUse = safemalloc(sizeof(char ) * (CFG_RTSMB_MAX_THREADS + 1)); NET_SESSIONCTX_T * sessions = safemalloc(sizeof(NET_SESSIONCTX_T) * CFG_RTSMB_MAX_SESSIONS); char * sessionsInUse = safemalloc(sizeof(char ) * CFG_RTSMB_MAX_SESSIONS); unsigned long * activeSessions = safemalloc(sizeof(unsigned long ) * CFG_RTSMB_MAX_SESSIONS); USER_T * uids = safemalloc(sizeof(USER_T ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_UIDS_PER_SESSION); SEARCH_T * searches = safemalloc(sizeof(SEARCH_T ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_UIDS_PER_SESSION * CFG_RTSMB_MAX_SEARCHES_PER_UID); PFID * uid_fids = safemalloc(sizeof(PFID ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_UIDS_PER_SESSION * CFG_RTSMB_MAX_FIDS_PER_UID); TREE_T * trees = safemalloc(sizeof(TREE_T ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_TREES_PER_SESSION); PFID * tree_fids = safemalloc(sizeof(PFID ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_TREES_PER_SESSION * CFG_RTSMB_MAX_FIDS_PER_TREE); FID_T * fids = safemalloc(sizeof(FID_T ) * CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_FIDS_PER_SESSION); PNET_SESSIONCTX * sessionList = safemalloc(sizeof(PNET_SESSIONCTX ) * (CFG_RTSMB_MAX_THREADS + 1) * CFG_RTSMB_MAX_SESSIONS); byte * inBuffer = safemalloc(sizeof(byte ) * (CFG_RTSMB_MAX_THREADS + 1) * CFG_RTSMB_SMALL_BUFFER_SIZE); byte * outBuffer = safemalloc(sizeof(byte ) * (CFG_RTSMB_MAX_THREADS + 1) * CFG_RTSMB_SMALL_BUFFER_SIZE); byte * tmpBuffer = safemalloc(sizeof(byte ) * (CFG_RTSMB_MAX_THREADS + 1) * CFG_RTSMB_SMALL_BUFFER_SIZE); byte * namesrvBuffer = safemalloc(sizeof(byte ) * CFG_RTSMB_SMALL_BUFFER_SIZE); byte * client_buffer = safemalloc(sizeof(byte ) * CFG_RTSMB_SMALL_BUFFER_SIZE); SR_RESOURCE_T * shareTable = safemalloc(sizeof(SR_RESOURCE_T ) * CFG_RTSMB_MAX_SHARES); USERDATA_T * users = safemalloc(sizeof(USERDATA_T ) * CFG_RTSMB_MAX_USERS); BBOOL * user_groups = safemalloc(sizeof(BBOOL ) * CFG_RTSMB_MAX_USERS * CFG_RTSMB_MAX_GROUPS); byte * access_table = safemalloc(sizeof(byte ) * ((CFG_RTSMB_MAX_SHARES * BITS_PER_TABLE_ENTRY / 8) + 1) * CFG_RTSMB_MAX_GROUPS); ACCESS_TABLE_T * groups = safemalloc(sizeof(ACCESS_TABLE_T ) * CFG_RTSMB_MAX_GROUPS); char * local_master = safemalloc(sizeof(char ) * (RTSMB_NB_NAME_SIZE + 1)); RTSMB_BROWSE_SERVER_INFO * server_table = safemalloc(sizeof(RTSMB_BROWSE_SERVER_INFO) * CFG_RTSMB_BROWSE_MAX_SERVER_INFOS); RTSMB_BROWSE_SERVER_INFO * domain_table = safemalloc(sizeof(RTSMB_BROWSE_SERVER_INFO) * CFG_RTSMB_BROWSE_MAX_DOMAIN_INFOS); RTSMB_BROWSE_SERVER_INFO * enum_results = safemalloc(sizeof(RTSMB_BROWSE_SERVER_INFO) * MAX(CFG_RTSMB_BROWSE_MAX_SERVER_INFOS, CFG_RTSMB_BROWSE_MAX_DOMAIN_INFOS)); #endif prtsmb_srv_ctx->max_threads = CFG_RTSMB_MAX_THREADS; prtsmb_srv_ctx->max_sessions = CFG_RTSMB_MAX_SESSIONS; prtsmb_srv_ctx->max_uids_per_session = CFG_RTSMB_MAX_UIDS_PER_SESSION; prtsmb_srv_ctx->max_fids_per_tree = CFG_RTSMB_MAX_FIDS_PER_TREE; prtsmb_srv_ctx->max_searches_per_uid = CFG_RTSMB_MAX_SEARCHES_PER_UID; prtsmb_srv_ctx->max_shares = CFG_RTSMB_MAX_SHARES; prtsmb_srv_ctx->max_groups = CFG_RTSMB_MAX_GROUPS; prtsmb_srv_ctx->max_users = CFG_RTSMB_MAX_USERS; prtsmb_srv_ctx->small_buffer_size = CFG_RTSMB_SMALL_BUFFER_SIZE; prtsmb_srv_ctx->big_buffer_size = CFG_RTSMB_BIG_BUFFER_SIZE; prtsmb_srv_ctx->num_big_buffers = CFG_RTSMB_NUM_BIG_BUFFERS; prtsmb_srv_ctx->max_fids_per_uid = CFG_RTSMB_MAX_FIDS_PER_UID; prtsmb_srv_ctx->max_fids_per_session = CFG_RTSMB_MAX_FIDS_PER_SESSION; prtsmb_srv_ctx->max_trees_per_session = CFG_RTSMB_MAX_TREES_PER_SESSION; prtsmb_srv_ctx->server_table_size = CFG_RTSMB_BROWSE_MAX_SERVER_INFOS; prtsmb_srv_ctx->domain_table_size = CFG_RTSMB_BROWSE_MAX_DOMAIN_INFOS; prtsmb_srv_ctx->enum_results_size = MAX (CFG_RTSMB_BROWSE_MAX_DOMAIN_INFOS, CFG_RTSMB_BROWSE_MAX_SERVER_INFOS); rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->bufsem, (const char*)0); rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->authsem, (const char*)0); rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->sharesem, (const char*)0); rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->printersem, (const char*)0); rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->cachesem, (const char*)0); rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->mailPDCNameSem, (const char*)0); rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->netsem, (const char*)0); rtp_sig_mutex_alloc ((RTP_MUTEX *) &prtsmb_srv_ctx->enum_results_mutex, (const char*)0); #if CFG_RTSMB_NUM_BIG_BUFFERS prtsmb_srv_ctx->bigBuffers = bigBuffers; prtsmb_srv_ctx->bigBufferInUse = bigBufferInUse; #endif prtsmb_srv_ctx->threads = threads; prtsmb_srv_ctx->threadsInUse = threadsInUse; prtsmb_srv_ctx->sessions = sessions; prtsmb_srv_ctx->sessionsInUse = sessionsInUse; prtsmb_srv_ctx->activeSessions = activeSessions; prtsmb_srv_ctx->namesrvBuffer = namesrvBuffer; prtsmb_srv_ctx->client_buffer = client_buffer; prtsmb_srv_ctx->shareTable = shareTable; prtsmb_srv_ctx->userList.users = users; prtsmb_srv_ctx->groupList.groups = groups; prtsmb_srv_ctx->local_master = local_master; prtsmb_srv_ctx->server_table = server_table; prtsmb_srv_ctx->domain_table = domain_table; prtsmb_srv_ctx->enum_results = enum_results; for (i = 0; i < CFG_RTSMB_MAX_GROUPS; i++) { prtsmb_srv_ctx->groupList.groups[i].table = &access_table[i * ((CFG_RTSMB_MAX_SHARES * BITS_PER_TABLE_ENTRY / 8) + 1)]; } for (i = 0; i < CFG_RTSMB_MAX_USERS; i++) { prtsmb_srv_ctx->userList.users[i].groups = &user_groups[i * CFG_RTSMB_MAX_GROUPS]; } for (i = 0; i < CFG_RTSMB_MAX_SESSIONS; i++) { rtp_sig_mutex_alloc((RTP_MUTEX *) &prtsmb_srv_ctx->activeSessions[i], (const char*)0); prtsmb_srv_ctx->sessions[i].smbCtx.uids = &uids [i * CFG_RTSMB_MAX_UIDS_PER_SESSION]; prtsmb_srv_ctx->sessions[i].smbCtx.trees = &trees [i * CFG_RTSMB_MAX_TREES_PER_SESSION]; prtsmb_srv_ctx->sessions[i].smbCtx.fids = &fids [i * CFG_RTSMB_MAX_FIDS_PER_SESSION]; } for (i=0; i < CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_UIDS_PER_SESSION; i++) { uids[i].searches = &searches [i * CFG_RTSMB_MAX_SEARCHES_PER_UID]; uids[i].fids = &uid_fids [i * CFG_RTSMB_MAX_FIDS_PER_UID]; } for (i=0; i < CFG_RTSMB_MAX_SESSIONS * CFG_RTSMB_MAX_TREES_PER_SESSION; i++) { trees[i].fids = &tree_fids [i * CFG_RTSMB_MAX_FIDS_PER_TREE]; } for (i=0; i < CFG_RTSMB_MAX_THREADS + 1; i++) { threads[i].sessionList = &sessionList [i * CFG_RTSMB_MAX_SESSIONS]; threads[i].inBuffer = &inBuffer [i * CFG_RTSMB_SMALL_BUFFER_SIZE]; threads[i].outBuffer = &outBuffer [i * CFG_RTSMB_SMALL_BUFFER_SIZE]; threads[i].tmpBuffer = &tmpBuffer [i * CFG_RTSMB_SMALL_BUFFER_SIZE]; } tc_strcpy (prtsmb_srv_ctx->local_master, ""); prtsmb_srv_ctx->enum_results_in_use = FALSE; for (i = 0; i < prtsmb_srv_ctx->server_table_size; i++) { prtsmb_srv_ctx->server_table[i].type = 0; } for (i = 0; i < prtsmb_srv_ctx->domain_table_size; i++) { prtsmb_srv_ctx->domain_table[i].type = 0; } return 1; }
int HTTP_ServerInit (HTTPServerContext *server, /** pointer to uninitialized \Ref{HTTPServerContext} struct */ const HTTP_CHAR *name, /** Server name. Sent in HTTP header. */ const HTTP_CHAR *rootDir, /** Path to the root directory for content. */ const HTTP_CHAR *defaultFile, /** Default Filename if "\" or "path\" is passed with no file name. */ HTTP_INT8 httpMajorVersion, /** Normally 1 for HTTP 1.1 */ HTTP_INT8 httpMinorVersion, /** Normally 1 for HTTP 1.1 */ HTTP_UINT8 *ipAddr, /** V4/V6 examples: ipaddr[4] = {192, 168, 0, 6}; ipAddr = "fe80::20b:dbff:fe2f:c162"; */ HTTP_INT16 port, /** port number (80) usually */ HTTP_INT16 ipType, /** ipversion 4 or 6 */ HTTP_BOOL allowKeepAlive, /** If HTTP version < 1.1 enables keep-alive support. For 1,1 and greater keep-alive is the default.*/ HTTPServerConnection* connectCtxArray, /** pointer to uninitialized bytes, must be (sizeof(HTTPServerConnection) * maxConnections)) bytes. */ HTTP_INT16 maxConnections, /** The maximum limit on simultaneous HTTP server connections */ HTTP_INT16 maxHelperThreads /** If HTTP_SERVER_MULTITHREAD is defined, the max number of helper threads to spawn */ ) { rtp_memset((unsigned char *) server, 0, sizeof(HTTPServerContext)); if (rtp_net_socket_stream_dual(&server->serverSocket, ipType) >= 0) { if (rtp_net_bind_dual(server->serverSocket, RTP_NET_STREAM, ipAddr, port, ipType) >= 0 && rtp_net_listen(server->serverSocket, maxConnections) >= 0) { if (!ipAddr) { if (rtp_net_getsockname(server->serverSocket, server->serverAddress.ipAddr, &server->serverAddress.port, &server->serverAddress.type) < 0) { rtp_memset(server->serverAddress.ipAddr, 0, RTP_NET_IP_ALEN); } } else { rtp_memcpy(server->serverAddress.ipAddr, ipAddr, RTP_NET_IP_ALEN); server->serverAddress.port = port; } if (name) { rtp_strncpy(server->serverName, name, HTTP_SERVER_NAME_LEN-1); } else { rtp_strncpy(server->serverName, HTTP_SERVER_NAME_STRING, HTTP_SERVER_NAME_LEN-1); } server->httpMajorVersion = httpMajorVersion; server->httpMinorVersion = httpMinorVersion; if (rootDir) { rtp_strncpy(server->rootDir, rootDir, HTTP_SERVER_PATH_LEN-1); } else { /* default to the current working directory */ server->rootDir[0] = '.'; server->rootDir[1] = 0; } if (defaultFile) { rtp_strncpy(server->defaultFile, defaultFile, HTTP_SERVER_DEFAULT_FILE_LEN-1); } else { rtp_strncpy(server->defaultFile, HTTP_SERVER_DEFAULT_FILE, HTTP_SERVER_DEFAULT_FILE_LEN-1); } if (!allowKeepAlive || (server->httpMajorVersion == 1 && server->httpMinorVersion > 0) || (server->httpMajorVersion > 1)) { server->allowKeepAlive = allowKeepAlive; server->maxConnections = maxConnections; DLLIST_INIT(&server->pathList); DLLIST_INIT(&server->realmList); server->allowedClientList = 0; server->numAllowedClients = 0; server->blockedClientList = 0; server->numBlockedClients = 0; #ifdef HTTP_SERVER_KEEP_ALIVE DLLIST_INIT(&server->openConnections); #endif /* HTTP_SERVER_KEEP_ALIVE */ #ifdef HTTP_SERVER_MULTITHREAD server->connectionContextArray = connectCtxArray; server->maxHelperThreads = maxHelperThreads; /* allocate the server lock */ if (rtp_sig_mutex_alloc(&server->lock, 0) >= 0) { RTP_MUTEX helperThreadMutex; RTP_SEMAPHORE helperThreadSemaphore; /* initialize the session queue */ if (rtp_sig_mutex_alloc(&helperThreadMutex, 0) >= 0) { if (rtp_sig_semaphore_alloc(&helperThreadSemaphore, 0) >= 0) { if (rtp_helper_thread_ctx_init ( &server->helperContext, helperThreadMutex, helperThreadSemaphore ) >= 0) { int n; // initialize the free job list server->jobFreeList = connectCtxArray; for (n = 0; n < maxConnections-1; n++) { connectCtxArray[n].job.next = &(connectCtxArray[n+1].job); connectCtxArray[n].job.execute = _HTTP_ServerExecuteJob; connectCtxArray[n].server = server; } connectCtxArray[n].job.next = 0; connectCtxArray[n].job.execute = _HTTP_ServerExecuteJob; connectCtxArray[n].server = server; server->status = HTTP_SERVER_INITIALIZED; return (0); } rtp_sig_semaphore_free(helperThreadSemaphore); } rtp_sig_mutex_free(helperThreadMutex); } rtp_sig_mutex_free(server->lock); } #else /* HTTP_SERVER_MULTITHREAD */ //server->queueFirst = 0; //server->queueLast = 0; server->status = HTTP_SERVER_INITIALIZED; return (0); #endif /* HTTP_SERVER_MULTITHREAD */ } } rtp_net_closesocket(server->serverSocket); } return (-1); }