void cg_upnpav_dmr_device_httprequestrecieved(CgHttpRequest* httpReq) { CgUpnpAvRenderer* dmr; CgUpnpDevice* dev; CG_UPNPAV_HTTP_LISTENER userHttpListener; dev = (CgUpnpDevice*)cg_http_request_getuserdata(httpReq); if (!dev) { cg_upnp_device_httprequestrecieved(httpReq); return; } dmr = (CgUpnpAvRenderer*)cg_upnp_device_getuserdata(dev); if (!dmr) { cg_upnp_device_httprequestrecieved(httpReq); return; } userHttpListener = cg_upnpav_dmr_gethttplistener(dmr); if (userHttpListener) { if (userHttpListener(httpReq)) return; } cg_upnp_device_httprequestrecieved(httpReq); }
BOOL cg_upnpav_dms_queryreceived(CgUpnpStateVariable *statVar) { CgUpnpDevice *dev; CgUpnpService *service; CgUpnpAvServer *dms; CG_UPNPAV_STATEVARIABLE_LISTNER userQueryListener; service = cg_upnp_statevariable_getservice(statVar); if (!service) return FALSE; dev = (CgUpnpDevice *)cg_upnp_service_getdevice(service); if (!dev) return FALSE; dms = (CgUpnpAvServer *)cg_upnp_device_getuserdata(dev); if (!dms) return FALSE; userQueryListener = cg_upnpav_dms_getquerylistener(dms); if (userQueryListener) { if (userQueryListener(statVar)) return TRUE; } if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMS_CONTENTDIRECTORY_SERVICE_TYPE)) return cg_upnpav_dms_condir_queryreceived(statVar); return FALSE; }
BOOL cg_upnpav_dms_conmgr_actionreceived(CgUpnpAction* action) { CgUpnpAvServer* dms; CgUpnpDevice* dev; char* actionName; CgUpnpArgument* arg; CgString* protocolInfos; CgUpnpAvProtocolInfo* protocolInfo; actionName = (char*)cg_upnp_action_getname(action); if (cg_strlen(actionName) <= 0) return FALSE; dev = (CgUpnpDevice*)cg_upnp_service_getdevice(cg_upnp_action_getservice(action)); if (!dev) return FALSE; dms = (CgUpnpAvServer*)cg_upnp_device_getuserdata(dev); if (!dms) return FALSE; /* GetProtocolInfo*/ if (cg_streq(actionName, CG_UPNPAV_DMS_CONNECTIONMANAGER_GET_PROTOCOL_INFO)) { arg = cg_upnp_action_getargumentbyname(action, CG_UPNPAV_DMS_CONNECTIONMANAGER_SOURCE); if (!arg) return FALSE; protocolInfos = cg_string_new(); for (protocolInfo = cg_upnpav_dms_getprotocolinfos(dms); protocolInfo; protocolInfo = cg_upnpav_protocolinfo_next(protocolInfo)) { if (0 < cg_string_length(protocolInfos)) cg_string_addvalue(protocolInfos, ","); cg_string_addvalue(protocolInfos, cg_upnpav_protocolinfo_getstring(protocolInfo)); } cg_upnp_argument_setvalue(arg, cg_string_getvalue(protocolInfos)); cg_string_delete(protocolInfos); return TRUE; } return FALSE; }
BOOL cg_upnpav_dmr_queryreceived(CgUpnpStateVariable* statVar) { CgUpnpDevice* dev; CgUpnpService* service; CgUpnpAvRenderer* dmr; CG_UPNPAV_STATEVARIABLE_LISTNER userQueryListener; service = cg_upnp_statevariable_getservice(statVar); if (!service) return FALSE; dev = (CgUpnpDevice*)cg_upnp_service_getdevice(service); if (!dev) return FALSE; dmr = (CgUpnpAvRenderer*)cg_upnp_device_getuserdata(dev); if (!dmr) return FALSE; userQueryListener = cg_upnpav_dmr_getquerylistener(dmr); if (userQueryListener) { if (userQueryListener(statVar)) return TRUE; } if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMR_AVTRANSPORT_SERVICE_TYPE)) return cg_upnpav_dmr_avtransport_queryreceived(statVar); if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMR_RENDERINGCONTROL_SERVICE_TYPE)) return cg_upnpav_dmr_renderingctrl_queryreceived(statVar); if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMR_CONNECTIONMANAGER_SERVICE_TYPE)) return cg_upnpav_dmr_conmgr_queryreceived(statVar); return FALSE; }
BOOL cg_upnpav_dmr_actionreceived(CgUpnpAction* action) { CgUpnpDevice* dev; CgUpnpService* service; CgUpnpAvRenderer* dmr; CG_UPNPAV_ACTION_LISTNER userActionListener; service = cg_upnp_action_getservice(action); if (!service) return FALSE; dev = (CgUpnpDevice*)cg_upnp_service_getdevice(service); if (!dev) return FALSE; dmr = (CgUpnpAvRenderer*)cg_upnp_device_getuserdata(dev); if (!dmr) return FALSE; userActionListener = cg_upnpav_dmr_getactionlistener(dmr); if (userActionListener) { if (userActionListener(action)) return TRUE; } if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMR_AVTRANSPORT_SERVICE_TYPE)) return cg_upnpav_dmr_avtransport_actionreceived(action); if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMR_RENDERINGCONTROL_SERVICE_TYPE)) return cg_upnpav_dmr_renderingctrl_actionreceived(action); if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMR_CONNECTIONMANAGER_SERVICE_TYPE)) return cg_upnpav_dmr_conmgr_actionreceived(action); return FALSE; }
BOOL cg_upnpav_dms_actionreceived(CgUpnpAction *action) { CgUpnpDevice *dev; CgUpnpService *service; CgUpnpAvServer *dms; CG_UPNP_ACTION_LISTNER userActionListener; service = cg_upnp_action_getservice(action); if (!service) return FALSE; dev = (CgUpnpDevice *)cg_upnp_service_getdevice(service); if (!dev) return FALSE; dms = (CgUpnpAvServer *)cg_upnp_device_getuserdata(dev); if (!dms) return FALSE; userActionListener = cg_upnpav_dms_getactionlistener(dms); if (userActionListener) { if (userActionListener(action)) return TRUE; } if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMS_CONTENTDIRECTORY_SERVICE_TYPE)) return cg_upnpav_dms_condir_actionreceived(action); if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMS_MEDIARECEIVER_SERVICE_TYPE)) return cg_upnpav_dms_medrec_actionreceived(action); if (cg_streq(cg_upnp_service_getservicetype(service), CG_UPNPAV_DMS_CONNECTIONMANAGER_SERVICE_TYPE)) return cg_upnpav_dms_conmgr_actionreceived(action); return FALSE; }
void cg_upnp_dms_youtube_http_listener(CgHttpRequest *httpReq) { CgUpnpMediaServer *dms; CgUpnpDevice *dev; char *httpURI; int contentMD5Idx; char *contentMd5; CgHttpResponse *httpRes; CgSocket *sock; char chunkedChar[32]; BOOL isHeadRequest; struct stat fileStat; off_t fileSize; FILE *fp; char readBuf[CG_FILE_READ_CHUNK_SIZE]; off_t nRead; off_t nReadCnt; off_t nWroteCnt; char contentFile[CG_MD5_STRING_BUF_SIZE+8]; dev = (CgUpnpDevice *)cg_http_request_getuserdata(httpReq); if (!dev) { cg_http_request_postbadrequest(httpReq); return; } dms = (CgUpnpMediaServer *)cg_upnp_device_getuserdata(dev); if (!dms) { cg_http_request_postbadrequest(httpReq); return; } httpURI = cg_http_request_geturi(httpReq); if (cg_strlen(httpURI) <= 0) { cg_http_request_postbadrequest(httpReq); return; } if (cg_strstr(httpURI, CG_UPNP_MEDIA_YOUTUBE_RESURL_PATH) < 0) { cg_upnp_device_httprequestrecieved(httpReq); return; } contentMD5Idx = cg_strrchr(httpURI, "/", 1); if (contentMD5Idx < 0) { cg_http_request_postbadrequest(httpReq); return; } contentMd5 = httpURI + contentMD5Idx + 1; cg_strcpy(contentFile, contentMd5); cg_strcat(contentFile, "." CG_UPNP_MEDIA_YOUTUBE_TRANSCODE_FILEEXT); cg_upnp_dms_lock(dms); isHeadRequest = cg_http_request_isheadrequest(httpReq); httpRes = cg_http_response_new(); #if defined(CG_USE_CHUNKED_STREAM) cg_http_response_setversion(httpRes, CG_HTTP_VER11); #else cg_http_response_setversion(httpRes, CG_HTTP_VER10); #endif cg_http_response_setstatuscode(httpRes, CG_HTTP_STATUS_OK); cg_http_response_setcontenttype(httpRes, CG_UPNP_MEDIA_YOUTUBE_CONTENT_MIMETYPE); sock = cg_http_request_getsocket(httpReq); cg_socket_settimeout(sock, 0); fileSize = 0; if (stat(contentFile, &fileStat) == 0) fileSize = fileStat.st_size; #if defined(CG_USE_CHUNKED_STREAM) cg_http_packet_setheadervalue((CgHttpPacket*)httpRes, "Transfer-Encoding", "chunked"); #else cg_http_response_setcontentlength(httpRes, fileSize); #endif cg_http_request_postresponse(httpReq, httpRes); if (0 < fileSize) { nReadCnt = 0; nWroteCnt = 0; fp = fopen(contentFile, "rb"); if (fp) { nRead = fread(readBuf, sizeof(char), CG_FILE_READ_CHUNK_SIZE, fp); while (nReadCnt < fileSize && 0 < nRead) { nReadCnt += nRead; #if defined(CG_USE_CHUNKED_STREAM) sprintf(chunkedChar, "%x%s", nRead, CG_HTTP_CRLF); cg_socket_write(sock, chunkedChar, cg_strlen(chunkedChar)); #endif nWroteCnt += cg_socket_write(sock, readBuf, nRead); #if defined(CG_USE_CHUNKED_STREAM) cg_socket_write(sock, CG_HTTP_CRLF, sizeof(CG_HTTP_CRLF)-1); #endif nRead = fread(readBuf, sizeof(char), CG_FILE_READ_CHUNK_SIZE, fp); } fclose(fp); } } #if defined(CG_USE_CHUNKED_STREAM) sprintf(chunkedChar, "%x%s", 0, CG_HTTP_CRLF); cg_socket_write(sock, chunkedChar, cg_strlen(chunkedChar)); #endif cg_socket_close(sock); cg_http_response_delete(httpRes); cg_upnp_dms_unlock(dms); }