CgHttpServer *cg_http_server_new()
{
	CgHttpServer *httpServer;

	cg_log_debug_l4("Entering...\n");

	httpServer = (CgHttpServer *)malloc(sizeof(CgHttpServer));

	if ( NULL != httpServer )
	{
		cg_list_node_init((CgList *)httpServer);

		httpServer->sock = NULL;
		httpServer->acceptThread = NULL;
		httpServer->listener = NULL;

		/**** Thanks for Makela Aapo (10/31/05) ****/
		httpServer->clientThreads = NULL;

		cg_http_server_setuserdata(httpServer, NULL);

		cg_http_server_settimeout(httpServer, CG_HTTP_SERVER_READ_TIMEOUT);

		/* Mutex */
		httpServer->mutex = cg_mutex_new();
	}

	cg_log_debug_l4("Leaving...\n");

	return httpServer;
}
Beispiel #2
0
CgBittorrentClient *cg_bittorrent_client_new()
{
	CgBittorrentClient *cbc;
	CgBittorrentMetainfoList *cbmList;

	cbc = (CgBittorrentClient *)malloc(sizeof(CgBittorrentClient));
	if (!cbc)
		return NULL;

	/* Mutex */
	cbc->mutex = cg_mutex_new();
	if (!cbc->mutex) {
		free(cbc);
		return NULL;
	}

	/* Metainfo */
	cbmList = cg_bittorrent_metainfolist_new();
	if (!cbmList) {
		free(cbc);
		return NULL;
	}
	cg_bittorrent_client_setmetainfolist(cbc, cbmList);

	/* Socket Server */
	cbc->serverSock = cg_socket_stream_new();
	if (!cbc->serverSock) {
		free(cbc);
		return NULL;
	}
	cg_bittorrent_client_setserverport(cbc, CG_BITTORRENT_CLIENT_DEFAULT_SERVER_PORT);

	/* HTTP Server */
	cbc->httpServer = cg_http_server_new();
	if (!cbc->httpServer) {
		free(cbc);
		cg_socket_delete(cbc->serverSock );
		return NULL;
	}
	cg_http_server_setlistener(cbc->httpServer, cg_bittorrent_client_httplistener);
	cg_http_server_setuserdata(cbc->httpServer, cbc);
	cg_bittorrent_client_sethttpserverport(cbc, CG_BITTORRENT_CLIENT_DEFAULT_HTTP_PORT);

	/* Manager */
	cg_bittorrent_client_setfilemgr(cbc, NULL);
	cg_bittorrent_client_setstrategymgr(cbc, NULL);

	/* Other Settings */
	cg_bittorrent_client_setmaxuploadconnections(cbc, CG_BITTORRENT_CLIENT_DEFAULT_MAX_UPLOAD_CONNECTIONS);
	cg_bittorrent_client_setmaxdownloadconnections(cbc, CG_BITTORRENT_CLIENT_DEFAULT_MAX_DOWNLOAD_CONNECTIONS);

	/* Thread */
	cbc->acceptThread = NULL;
	cbc->clientThreads = NULL;

	return cbc;
}
void cg_http_serverlist_setuserdata(CgHttpServerList *httpServerList, void *value)
{
	CgHttpServer *httpServer;
	
	cg_log_debug_l4("Entering...\n");

	for (httpServer = cg_http_serverlist_gets(httpServerList); httpServer != NULL; httpServer = cg_http_server_next(httpServer))
		cg_http_server_setuserdata(httpServer, value);

	cg_log_debug_l4("Leaving...\n");
}