コード例 #1
0
ファイル: chttp_request.c プロジェクト: dallasderk/DLNA
CgHttpRequest *cg_http_request_new()
{
    CgHttpRequest *httpReq;

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

    httpReq = (CgHttpRequest *)malloc(sizeof(CgHttpRequest));

    if ( NULL != httpReq )
    {
        cg_http_packet_init((CgHttpPacket *)httpReq);
        httpReq->method = cg_string_new();
        httpReq->version = cg_string_new();
        httpReq->uri = cg_string_new();
        httpReq->userAgent = cg_string_new();
        httpReq->httpRes = cg_http_response_new();
        httpReq->postURL = cg_net_url_new();

        cg_http_request_setversion(httpReq, CG_HTTP_VER11);
        cg_http_request_setuseragent(httpReq, CG_HTTP_USERAGENT_DEFAULT);

        cg_http_request_setsocket(httpReq, NULL);
        cg_http_request_setuserdata(httpReq, NULL);

        cg_http_request_settimeout(httpReq, CG_HTTP_CONN_TIMEOUT);
    }

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

    return httpReq;
}
コード例 #2
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");
}
コード例 #3
0
CgUpnpSSDPResponse *cg_upnp_ssdpresponse_new()
{
    CgUpnpSSDPResponse*ssdpRes;

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

    ssdpRes = cg_http_response_new();

    cg_http_response_setversion(ssdpRes, CG_HTTP_VER11);
    cg_http_response_setstatuscode(ssdpRes, CG_HTTP_STATUS_OK);

    return ssdpRes;

    cg_log_debug_l4("Leaving...\n");
}
コード例 #4
0
ファイル: chttp_request.c プロジェクト: dallasderk/DLNA
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
CgSoapResponse *cg_soap_response_new()
{
	CgSoapResponse *soapRes;

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

	soapRes = (CgSoapResponse *)malloc(sizeof(CgSoapResponse));

	if ( NULL != soapRes )
	{
		soapRes->rootNodeList = cg_xml_nodelist_new();

		soapRes->httpRes = cg_http_response_new();
		soapRes->isHttpResCreated = TRUE;
	
		cg_soap_response_setuserdata(soapRes, NULL);
	}

	return soapRes;

	cg_log_debug_l4("Leaving...\n");
}
コード例 #6
0
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
ファイル: clock_device.c プロジェクト: RbBtSn0w/CyberLink4C
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);
}