Exemplo n.º 1
0
bool mupnp_http_server_start(mUpnpHttpServer *httpServer)
{
	mupnp_log_debug_l4("Entering...\n");

	if (httpServer->acceptThread != NULL)
		return false;

	httpServer->acceptThread = mupnp_thread_new();
	mupnp_thread_setaction(httpServer->acceptThread, mupnp_http_server_thread);
	mupnp_thread_setuserdata(httpServer->acceptThread, httpServer);

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

	if (mupnp_thread_start(httpServer->acceptThread) == false) {
		mupnp_thread_delete(httpServer->acceptThread);
		httpServer->acceptThread = NULL;

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

		return false;
	}

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

	return true;
}
Exemplo n.º 2
0
void mupnp_service_createnotifyallthread(mUpnpService* service, mUpnpTime waitTime)
{
  mUpnpThread* thread;

  thread = mupnp_thread_new();
  mupnp_thread_setaction(thread, mupnp_service_notifyall_thread);
  mupnp_thread_setuserdata(thread, service);

  mupnp_wait(waitTime);
  mupnp_thread_start(thread);
}
Exemplo n.º 3
0
/**
 * Create a new control point. Does not start any threads.
 *
 * @return A newly-created mUpnpControlPoint
 */
mUpnpControlPoint *mupnp_controlpoint_new()
{
	mUpnpControlPoint *ctrlPoint;

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

	ctrlPoint = (mUpnpControlPoint *)malloc(sizeof(mUpnpControlPoint));

	if ( NULL != ctrlPoint )
	{
#ifdef MUPNP_HTTP_USE_PERSISTENT_CONNECTIONS	
		mupnp_http_persistentconnection_init();
#endif
		ctrlPoint->mutex = mupnp_mutex_new();
		ctrlPoint->deviceRootNodeList = mupnp_xml_nodelist_new();
		ctrlPoint->deviceList = mupnp_devicelist_new();
		ctrlPoint->ssdpServerList = mupnp_ssdp_serverlist_new();
		ctrlPoint->ssdpResServerList = mupnp_ssdpresponse_serverlist_new();
		ctrlPoint->httpServerList = mupnp_http_serverlist_new();
		ctrlPoint->httpEventURI = mupnp_string_new();
		ctrlPoint->eventListeners = mupnp_eventlistenerlist_new();

		/* Expiration handling */
		ctrlPoint->expThread = mupnp_thread_new();
		mupnp_thread_setaction(ctrlPoint->expThread, mupnp_controlpoint_expirationhandler);
		mupnp_thread_setuserdata(ctrlPoint->expThread, ctrlPoint);
		ctrlPoint->expMutex = mupnp_mutex_new();
		ctrlPoint->expCond = mupnp_cond_new();
		
		ctrlPoint->ifCache = mupnp_net_interfacelist_new();
		
		mupnp_controlpoint_setssdplistener(ctrlPoint, NULL);
		mupnp_controlpoint_setssdpresponselistener(ctrlPoint, NULL);
		mupnp_controlpoint_sethttplistener(ctrlPoint, NULL);
		mupnp_controlpoint_setdevicelistener(ctrlPoint, NULL);
		
		mupnp_controlpoint_setssdpresponseport(ctrlPoint, MUPNP_CONTROLPOINT_SSDP_RESPONSE_DEFAULT_PORT);
		mupnp_controlpoint_setssdpsearchmx(ctrlPoint, MUPNP_CONTROLPOINT_SSDP_DEFAULT_SEARCH_MX);
		mupnp_controlpoint_seteventport(ctrlPoint, MUPNP_CONTROLPOINT_HTTP_EVENT_DEFAULT_PORT);
		mupnp_controlpoint_seteventsuburi(ctrlPoint, MUPNP_CONTROLPOINT_HTTP_EVENTSUB_URI);

		mupnp_controlpoint_setuserdata(ctrlPoint, NULL);
	}

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

	return ctrlPoint;
}
Exemplo n.º 4
0
bool mupnp_ssdpresponse_server_start(mUpnpSSDPResponseServer* server)
{
  mupnp_log_debug_l4("Entering...\n");

  if (server->recvThread != NULL)
    return false;

  server->recvThread = mupnp_thread_new();
  mupnp_thread_setaction(server->recvThread, mupnp_ssdpresponse_server_thread);
  mupnp_thread_setuserdata(server->recvThread, server);
  if (mupnp_thread_start(server->recvThread) == false) {
    mupnp_thread_delete(server->recvThread);
    server->recvThread = NULL;
    return false;
  }

  return true;

  mupnp_log_debug_l4("Leaving...\n");
}
Exemplo n.º 5
0
static void mupnp_http_server_thread(mUpnpThread *thread)
{
	mUpnpHttpServer *httpServer;
	mUpnpThread *httpClientThread;
	mUpnpHttpServerClientData *clientData;
	mUpnpSocket *serverSock;
	mUpnpSocket *clientSock;

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

	httpServer = (mUpnpHttpServer *)mupnp_thread_getuserdata(thread);

	if (mupnp_http_server_isopened(httpServer) == false)
		return;

	serverSock = httpServer->sock;
	while (mupnp_thread_isrunnable(thread) == true) {
		clientSock = mupnp_socket_stream_new();
		if (mupnp_socket_accept(serverSock, clientSock) == false) {
			mupnp_socket_delete(clientSock);
			break;
		}

		mupnp_socket_settimeout(clientSock, mupnp_http_server_gettimeout(httpServer));
		clientData = mupnp_http_server_clientdata_new(httpServer, clientSock);
		httpClientThread = mupnp_thread_new();
		mupnp_thread_setaction(httpClientThread, mupnp_http_server_clientthread);
		mupnp_thread_setuserdata(httpClientThread, clientData);

		/**** Thanks for Makela Aapo (10/31/05) ****/
		mupnp_http_server_lock(httpServer);
		mupnp_threadlist_add(httpServer->clientThreads, httpClientThread);
		mupnp_http_server_unlock(httpServer);

		mupnp_thread_start(httpClientThread);
	}

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