示例#1
0
void cg_upnp_ssdpresponse_delete(CgUpnpSSDPResponse *ssdpRes)
{
    cg_log_debug_l4("Entering...\n");

    cg_http_response_delete(ssdpRes);

    cg_log_debug_l4("Leaving...\n");
}
示例#2
0
void cg_soap_response_sethttpresponse(CgSoapResponse *soapRes, CgHttpResponse *httpRes)
{
	cg_log_debug_l4("Entering...\n");

	if (soapRes->isHttpResCreated == TRUE)
		cg_http_response_delete(soapRes->httpRes);
	soapRes->httpRes = httpRes;
	soapRes->isHttpResCreated = FALSE;

	cg_log_debug_l4("Leaving...\n");
}
示例#3
0
void cg_soap_response_clear(CgSoapResponse *soapRes)
{
	cg_log_debug_l4("Entering...\n");

	cg_xml_nodelist_clear(soapRes->rootNodeList);

	if (soapRes->isHttpResCreated == TRUE)
		cg_http_response_delete(soapRes->httpRes);
	soapRes->httpRes = cg_http_response_new();
	soapRes->isHttpResCreated = TRUE;

	cg_log_debug_l4("Leaving...\n");
}
示例#4
0
BOOL cg_http_request_poststatuscode(CgHttpRequest *httpReq, int httpStatCode)
{
    CgHttpResponse *httpRes;
    BOOL postRet;

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

    httpRes = cg_http_response_new();
    cg_http_response_setstatuscode(httpRes, httpStatCode);
    cg_http_response_setcontentlength(httpRes, 0);
    postRet = cg_http_request_postresponse(httpReq, httpRes);
    cg_http_response_delete(httpRes);

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

    return postRet;
}
示例#5
0
void cg_http_request_delete(CgHttpRequest *httpReq)
{
    cg_log_debug_l4("Entering...\n");

    cg_http_packet_clean((CgHttpPacket *)httpReq);
    cg_string_delete(httpReq->method);
    cg_string_delete(httpReq->version);
    cg_string_delete(httpReq->uri);
    /* ADD Fabrice Fontaine Orange 23/04/2007 */
    /* Memory leak correction */
    cg_string_delete(httpReq->userAgent);
    /* ADD END Fabrice Fontaine Orange 23/04/2007 */
    cg_http_response_delete(httpReq->httpRes);
    cg_net_url_delete(httpReq->postURL);

    free(httpReq);

    cg_log_debug_l4("Leaving...\n");
}
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);
}
示例#7
0
void upnp_clock_device_httprequestrecieved(CgHttpRequest *httpReq)
{
    CgTime currTime;
    CgUpnpDevice *dev;
    char *uri;
    char content[2048];
    char sysTimeStr[SYSTEM_TIME_BUF_LEN];
    char serverName[CG_UPNP_SEVERNAME_MAXLEN];
    CgHttpResponse *httpRes;
    BOOL postRet;

    dev = (CgUpnpDevice *)cg_http_request_getuserdata(httpReq);

    uri = cg_http_request_geturi(httpReq);
    if (strcmp(uri, "/presentation") != 0) {
        cg_upnp_device_httprequestrecieved(httpReq);
        return;
    }

    currTime = cg_getcurrentsystemtime();

#if defined(HAVE_SNPRINTF)
    snprintf(content, sizeof(content),
#else
    sprintf(content,
#endif
             "<HTML>"
             "<HEAD>"
             "<TITLE>UPnP Clock Sample</TITLE>"
             "</HEAD>"
             "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=/presentation\">"
             "<BODY><CENTER>"
             "<H1>UPnP Clock Sample</H1>"
             "<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
             "<TR>"
             "<TD style=\"width: 50px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
             "<TD style=\"background-color: rgb(176, 176, 176);\"></TD>"
             "<TD style=\"width: 50px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
             "</TR>"
             "<TR>"
             "<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
             "<TD style=\"height: 50px; background-color: rgb(221, 236, 245);\" align=\"center\"><H1>"
             "%s"
             "</H1></TD>"
             "<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
             "</TR>"
             "<TR>"
             "<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
             "<TD style=\"height: 50px; background-color: rgb(221, 236, 245);\" align=\"center\"><H3>"
             "Server : %s"
             "</H3></TD>"
             "<TD style=\"height: 30px; background-color: rgb(176, 176, 176);\"></TD>"
             "</TR>"
             "<TR>"
             "<TD style=\"width: 30px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
             "<TD style=\"background-color: rgb(176, 176, 176);\"></TD>"
             "<TD style=\"width: 30px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
             "</TR>"
             "</TABLE>"
             "<CENTER></BODY>"
             "</HTML>",
             GetSystemTimeString(currTime, sysTimeStr),
             cg_upnp_getservername(serverName, sizeof(serverName)));

    httpRes = cg_http_response_new();
    cg_http_response_setstatuscode(httpRes, CG_HTTP_STATUS_OK);
    cg_http_response_setcontent(httpRes, content);
    cg_http_response_setcontenttype(httpRes, "text/html");
    cg_http_response_setcontentlength(httpRes, strlen(content));
    postRet = cg_http_request_postresponse(httpReq, httpRes);
    cg_http_response_delete(httpRes);
}