/** * 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; }
mUpnpHttpServer *mupnp_http_server_new() { mUpnpHttpServer *httpServer; mupnp_log_debug_l4("Entering...\n"); httpServer = (mUpnpHttpServer *)malloc(sizeof(mUpnpHttpServer)); if ( NULL != httpServer ) { mupnp_list_node_init((mUpnpList *)httpServer); httpServer->sock = NULL; httpServer->acceptThread = NULL; httpServer->listener = NULL; /**** Thanks for Makela Aapo (10/31/05) ****/ httpServer->clientThreads = NULL; mupnp_http_server_setuserdata(httpServer, NULL); mupnp_http_server_settimeout(httpServer, MUPNP_HTTP_SERVER_READ_TIMEOUT); /* Mutex */ httpServer->mutex = mupnp_mutex_new(); } mupnp_log_debug_l4("Leaving...\n"); return httpServer; }
BOOL mupnp_http_persistentconnection_init(void) { mupnp_log_debug_l4("Entering...\n"); if (cache == NULL) { persistent_connection_mutex = mupnp_mutex_new(); if (persistent_connection_mutex == NULL) { return FALSE; } mupnp_http_persistentconnection_lock(); cache = (mUpnpHttpPersistentConnectionList *)malloc(sizeof(mUpnpHttpPersistentConnectionList)); if (cache == NULL) { if (persistent_connection_mutex != NULL) { mupnp_http_persistentconnection_unlock(); mupnp_mutex_delete(persistent_connection_mutex); persistent_connection_mutex = NULL; } return FALSE; } mupnp_list_header_init((mUpnpList *)cache); cache->host = NULL; cache->port = 0; cache->cacheData = NULL; cache->timestamp = 0; mupnp_http_persistentconnection_unlock(); } return TRUE; mupnp_log_debug_l4("Leaving...\n"); }
/** * Multiplex log messages into different targets (streams), should be used via convenience macros * @param severity Message severity * @param file File name where the function is called * @param line_n Line number where the function is called * @param function Function name where this function is called * @param format Format string for the actual log message * @param ... Possible parameters for the format string */ void mupnp_log_print(int severity, const char *file, int line_n, const char *function, const char *format, ...) { va_list list; char log_line[MAX_LOG_STRING], *l_ptr, t_ptr[MAX_LOG_STRING]; int prefix_length = -1; struct fd_list *temp = NULL; size_t timestamp; struct tm *timestamp_human_readable; /* If output targets are empty, do return */ if (!descriptor_list) return; /* If logger is not initialized, do it now */ if (!initialized) log_init_with_defaults(); /* If separator is not set, do it now */ if (NULL == separator) mupnp_log_set_separator(" : "); /* Create a mutex */ if (!print_mutex) print_mutex = mupnp_mutex_new(); mupnp_mutex_lock(print_mutex); /* Create timestamp for the log prefix */ timestamp = time(NULL); timestamp_human_readable = localtime(×tamp); #if !defined(WIN32) strftime(t_ptr, MAX_LOG_STRING, "%c", timestamp_human_readable); #else snprintf(log_line, MAX_LOG_STRING, "%d-%d-%d %d:%d %d", timestamp_human_readable->tm_year + 1900, timestamp_human_readable->tm_mon + 1, timestamp_human_readable->tm_mday, timestamp_human_readable->tm_hour, timestamp_human_readable->tm_min, timestamp_human_readable->tm_sec); #endif /* Creating the full log prefix */ prefix_length = snprintf(log_line, MAX_LOG_STRING, "%s%s%s%s%s%s%d%s%s%s ", t_ptr, separator, map_severity(severity), separator, file, separator, line_n, separator, function, separator); /* Setting pointer where the actual message should start */ l_ptr = &log_line[prefix_length]; /* Filling out rest of the log message */ va_start(list, format); vsnprintf(log_line + prefix_length, MAX_LOG_STRING - prefix_length, format, list); va_end(list); /* Multiplexing the created message into targets */ for( temp = descriptor_list; temp; temp = temp->next ) { if ( severity == ( severity & temp->apply_mask ) ) { fputs(log_line, temp->fd); } } mupnp_mutex_unlock(print_mutex); }
mUpnpAvRenderer *mupnp_upnpav_dmr_new() { mUpnpAvRenderer *dmr; char *lastChange; dmr = (mUpnpAvRenderer *)malloc(sizeof(mUpnpAvRenderer)); dmr->dev = mupnp_device_new(); if (!dmr->dev) { free(dmr); return NULL; } if (mupnp_device_parsedescription(dmr->dev, CG_UPNPAV_DMR_DEVICE_DESCRIPTION, mupnp_strlen(CG_UPNPAV_DMR_DEVICE_DESCRIPTION)) == false) { mupnp_device_delete(dmr->dev); free(dmr); return NULL; } if (mupnp_upnpav_dmr_conmgr_init(dmr) == false) { mupnp_device_delete(dmr->dev); free(dmr); return NULL; } if (mupnp_upnpav_dmr_renderingctrl_init(dmr) == false) { mupnp_device_delete(dmr->dev); free(dmr); return NULL; } if (mupnp_upnpav_dmr_avtransport_init(dmr) == false) { mupnp_device_delete(dmr->dev); free(dmr); return NULL; } dmr->mutex = mupnp_mutex_new(); if (!dmr->mutex) { mupnp_upnpav_dmr_delete(dmr); return NULL; } mupnp_device_setactionlistener(dmr->dev, mupnp_upnpav_dmr_actionreceived); mupnp_device_setquerylistener(dmr->dev, mupnp_upnpav_dmr_queryreceived); mupnp_device_sethttplistener(dmr->dev, mupnp_upnpav_dmr_device_httprequestrecieved); mupnp_upnpav_dmr_setactionlistener(dmr, NULL); mupnp_upnpav_dmr_setquerylistener(dmr, NULL); mupnp_upnpav_dmr_sethttplistener(dmr, NULL); mupnp_device_setuserdata(dmr->dev, dmr); mupnp_device_updateudn(dmr->dev); dmr->protocolInfoList = mupnp_upnpav_protocolinfolist_new(); mupnp_upnpav_dmr_setavtransportlastchange(dmr, "<Event xmlns = "urn:schemas-upnp-org:metadata-1-0/AVT/"/>"); mupnp_upnpav_dmr_setsourceprotocolinfo(dmr, ""); mupnp_upnpav_dmr_setcurrentconnectionids(dmr, "0"); lastChange = "<Event xmlns = "urn:schemas-upnp-org:metadata-1-0/RCS/">" "<InstanceID val="0">" "<Volume val="100" channel="RF"/>" "<Volume val="100" channel="LF"/>" "</InstanceID>" "</Event>"; mupnp_upnpav_dmr_setrenderingcontrollastchange(dmr, lastChange); return dmr; }
mUpnpAvServer *mupnp_upnpav_dms_new() { mUpnpAvServer *dms; dms = (mUpnpAvServer *)malloc(sizeof(mUpnpAvServer)); dms->dev = mupnp_device_new(); if (!dms->dev) { free(dms); return NULL; } if (mupnp_device_parsedescription(dms->dev, CG_UPNPAV_DMS_DEVICE_DESCRIPTION, mupnp_strlen(CG_UPNPAV_DMS_DEVICE_DESCRIPTION)) == false) { mupnp_device_delete(dms->dev); free(dms); return NULL; } if (mupnp_upnpav_dms_conmgr_init(dms) == false) { mupnp_device_delete(dms->dev); free(dms); return NULL; } if (mupnp_upnpav_dms_condir_init(dms) == false) { mupnp_device_delete(dms->dev); free(dms); return NULL; } if (mupnp_upnpav_dms_medrec_init(dms) == false) { mupnp_device_delete(dms->dev); free(dms); return NULL; } dms->rootContent = mupnp_upnpav_content_new(); mupnp_upnpav_content_settype(dms->rootContent, CG_UPNPAV_CONTENT_CONTAINER); mupnp_upnpav_content_settitle(dms->rootContent, CG_UPNPAV_ROOT_CONTENT_TITLE); mupnp_upnpav_content_setid(dms->rootContent, CG_UPNPAV_ROOT_CONTENT_ID); mupnp_upnpav_content_setparentid(dms->rootContent, CG_UPNPAV_ROOT_CONTENT_PARENTID); if (!dms->rootContent) { mupnp_upnpav_dms_delete(dms); return NULL; } dms->mutex = mupnp_mutex_new(); if (!dms->mutex) { mupnp_upnpav_dms_delete(dms); return NULL; } dms->networkInterfaceList = mupnp_net_interfacelist_new(); if (!dms->networkInterfaceList) { mupnp_upnpav_dms_delete(dms); return NULL; } mupnp_device_setactionlistener(dms->dev, mupnp_upnpav_dms_actionreceived); mupnp_device_setquerylistener(dms->dev, mupnp_upnpav_dms_queryreceived); mupnp_device_sethttplistener(dms->dev, mupnp_upnpav_dms_device_httprequestrecieved); mupnp_upnpav_dms_setactionlistener(dms, NULL); mupnp_upnpav_dms_setquerylistener(dms, NULL); mupnp_upnpav_dms_sethttplistener(dms, NULL); mupnp_device_setuserdata(dms->dev, dms); mupnp_device_updateudn(dms->dev); dms->protocolInfoList = mupnp_upnpav_protocolinfolist_new(); return dms; }