CgTime cg_upnp_ssdprequest_getleasetime(CgUpnpSSDPRequest *ssdpReq)
{
	const char *cacheCtrl;

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

	cacheCtrl = cg_http_packet_getheadervalue((CgHttpPacket*)ssdpReq, CG_HTTP_CACHE_CONTROL);
	
	return cg_upnp_ssdp_getleasetime(cacheCtrl);

	cg_log_debug_l4("Leaving...\n");
}
Exemple #2
0
CgInt64 cg_http_packet_getheaderlonglong(CgHttpPacket *httpPkt, char* name)
{
	char *value;

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

	value = cg_http_packet_getheadervalue(httpPkt, name); 

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

	return (value != NULL) ? cg_str2longlong(value) : 0;
}
ssize_t cg_http_packet_getheaderssizet(CgHttpPacket *httpPkt, const char* name)
{
	const char *value;
  
	cg_log_debug_l4("Entering...\n");
  
	value = cg_http_packet_getheadervalue(httpPkt, name);
  
	cg_log_debug_l4("Leaving...\n");
  
	return (value != NULL) ? atol(value) : 0;
}
Exemple #4
0
int cg_http_packet_getheaderinteger(CgHttpPacket *httpPkt, char* name)
{
	char *value;

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

	value = cg_http_packet_getheadervalue(httpPkt, name); 

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

	return (value != NULL) ? atoi(value) : 0;
}
BOOL cg_http_packet_read_body(CgHttpPacket *httpPkt, CgSocket *sock, char *lineBuf, size_t lineBufSize)
{
	ssize_t readLen;
	ssize_t conLen;
	char *content;
	char readBuf[READBUF_LENGTH + 1];
	int tries = 0;

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

	conLen = cg_http_packet_getcontentlength(httpPkt);
	content = NULL;
	if (0 < conLen) {
		content = (char *)malloc(conLen+1);
		if (content == NULL)
		{
			cg_log_debug_s("Memory allocation problem!\n");
			return FALSE;
		}
		
		content[0] = '\0';
		readLen = 0;
		
		/* Read content until conLen is reached, or tired of trying */
		while (readLen < conLen && tries < 20)
		{
			readLen += cg_socket_read(sock, (content+readLen), (conLen-readLen));
			/* Fixed to increment the counter only when cg_socket_read() doesn't read data */
			if (readLen <= 0)
				tries++;
		}
		
		if (readLen <= 0)
			return TRUE;
		content[readLen] = '\0';
		cg_http_packet_setcontentpointer(httpPkt, content, readLen);
	}
	else if (cg_http_packet_getheadervalue(httpPkt, 
					CG_HTTP_CONTENT_LENGTH) == NULL)
	{
		/* header existance must be checked! otherwise packets which
		   rightly report 0 as content length, will jam the http */
		
		/* Check if we read chunked encoding */
		if (cg_http_packet_ischunked(httpPkt) == TRUE)
		{
			conLen = 0;
			do {
				readLen = cg_http_packet_read_chunk(httpPkt, sock, lineBuf, lineBufSize);
				conLen += readLen;
			} while (readLen > 0);
			
			cg_http_packet_setcontentlength(httpPkt,conLen);
		} else {
			readLen = 0;
			conLen = 0;
			while ((readLen = cg_socket_read(sock, readBuf, READBUF_LENGTH)) > 0)
			{
				cg_http_packet_appendncontent(httpPkt, readBuf, readLen);
				conLen += readLen;
			}

			cg_http_packet_setcontentlength(httpPkt, conLen);
		}
	}

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

	return TRUE;
}