コード例 #1
0
void cg_upnp_property_clear(CgUpnpProperty *prop)
{
    cg_log_debug_l4("Entering...\n");

    cg_string_setvalue(prop->name, NULL);
    cg_string_setvalue(prop->value, NULL);
    cg_string_setvalue(prop->sid, NULL);

    cg_log_debug_l4("Leaving...\n");
}
コード例 #2
0
ファイル: curi.c プロジェクト: Deanzou/DLNA
CgNetURI *cg_net_uri_new()
{
	CgNetURI *uri;
	
	cg_log_debug_l4("Entering...\n");

	uri = (CgNetURI *)malloc(sizeof(CgNetURI));

	if  (NULL != uri)
	{
		uri->uri = cg_string_new();
		uri->protocol = cg_string_new();
		uri->user = cg_string_new();
		uri->password = cg_string_new();
		uri->host = cg_string_new();
		uri->port = 0;
		uri->path = cg_string_new();
		uri->query = cg_string_new();
		uri->fragment = cg_string_new();
		uri->request = NULL;
		uri->queryDictionary = NULL;
		
		/**** Thanks for Theo Beisch (2005/08/25) ****/
		cg_string_setvalue(uri->path, CG_NET_URI_DEFAULT_PATH);
	}
		
	cg_log_debug_l4("Leaving...\n");

	return uri;
}
コード例 #3
0
ファイル: curi.c プロジェクト: Deanzou/DLNA
void cg_net_uri_rebuild(CgNetURI *uri)
{
	char portStr[32];
	char *path;
	
	cg_log_debug_l4("Entering...\n");

	cg_string_setvalue(uri->uri, cg_net_uri_getprotocol(uri));
	cg_string_addvalue(uri->uri, CG_NET_URI_PROTOCOL_DELIM);
	cg_string_addvalue(uri->uri, cg_net_uri_gethost(uri));
	cg_string_addvalue(uri->uri, CG_NET_URI_COLON_DELIM);
	cg_string_addvalue(uri->uri, cg_int2str(cg_net_uri_getport(uri), portStr, sizeof(portStr)));
	if (0 < cg_strlen(cg_net_uri_getpath(uri))) {
		path = cg_net_uri_getpath(uri);
		if (path[0] != '/')
			cg_string_addvalue(uri->uri, CG_NET_URI_SLASH_DELIM);
		cg_string_addvalue(uri->uri, cg_net_uri_getpath(uri));
		if (cg_strchr(cg_net_uri_getpath(uri), "?", 1) == -1 && 0 < cg_strlen(cg_net_uri_getquery(uri))) {
			cg_string_addvalue(uri->uri, CG_NET_URI_QUESTION_DELIM);
			cg_string_addvalue(uri->uri, cg_net_uri_getquery(uri));
		}
	}
	
	cg_log_debug_l4("Leaving...\n");
}
コード例 #4
0
BOOL cg_socket_joingroup(CgSocket *sock, char *mcastAddr, char *ifAddr)
{
	struct ip_mreq ipmr;
	u_long ifInetAddr = ka_inet_addr(ifAddr);
	
	BOOL joinSuccess;
	int sockOptRetCode;
	
	cg_log_debug_l4("Entering...\n");

	joinSuccess = TRUE;
	
	ka_inet_pton( AF_INET, mcastAddr, &(ipmr.imr_multiaddr) );
	memcpy(&ipmr.imr_interface, &ifInetAddr, sizeof(struct in_addr));
	sockOptRetCode = ka_setsockopt(sock->id, IP_PROTOIP, IPO_ADD_MEMBERSHIP, (char *)&ipmr, sizeof(ipmr));

	if (sockOptRetCode != 0)
		joinSuccess = FALSE;

	cg_string_setvalue(sock->ipaddr, (joinSuccess == TRUE) ? ifAddr : NULL);

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

	return joinSuccess;
}
コード例 #5
0
const char *cg_upnp_event_subscription_totimeoutheaderstring(CgTime time, CgString *buf)
{
    char timeBuf[CG_STRING_LONG_BUFLEN];

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

    if (time != CG_UPNP_SUBSCRIPTION_INFINITE_VALUE) {
        cg_string_setvalue(buf, CG_UPNP_SUBSCRIPTION_TIMEOUT_HEADER);
        cg_string_addvalue(buf, cg_long2str(time, timeBuf, sizeof(timeBuf)));
    }
    else
        cg_string_setvalue(buf, CG_UPNP_SUBSCRIPTION_INFINITE_STRING);
    return cg_string_getvalue(buf);

    cg_log_debug_l4("Leaving...\n");
}
コード例 #6
0
ファイル: cstring.c プロジェクト: BelkinMike/CyberLink4C
char *cg_string_replace(CgString *str, char *fromStr[], char *toStr[], size_t fromStrCnt)
{
	char *orgValue = NULL;
	size_t orgValueLen = 0;
	int n = 0;
	int copyPos = 0;
	size_t *fromStrLen = NULL;
	CgString *repValue = NULL;
	BOOL isReplaced = FALSE;

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

	if (NULL == str )
		return NULL;
	
	repValue = cg_string_new();
	
	fromStrLen = (size_t *)malloc(sizeof(size_t) * fromStrCnt);

	if ( NULL == fromStrLen )
	{
        cg_string_delete(repValue);
		cg_log_debug_s("Memory allocation failure!\n");
		return NULL;
	}
	
	for (n=0; n<fromStrCnt; n++)
		fromStrLen[n] = cg_strlen(fromStr[n]);
	
	orgValue = cg_string_getvalue(str);
	orgValueLen = cg_string_length(str);
	
	copyPos = 0;
	while (copyPos<orgValueLen) {
		isReplaced = FALSE;
		for (n=0; n<fromStrCnt; n++) {
			if (strncmp(fromStr[n], orgValue + copyPos,  fromStrLen[n]) == 0) {
				cg_string_addvalue(repValue, toStr[n]);
				copyPos += fromStrLen[n];
				isReplaced = TRUE;
				continue;
			}
		}
		if (isReplaced == TRUE)
			continue;
		cg_string_naddvalue(repValue, orgValue + copyPos, 1);
		copyPos++;
	}
	
	free(fromStrLen);

	cg_string_setvalue(str, cg_string_getvalue(repValue));	

	cg_string_delete(repValue);
		
	cg_log_debug_l5("Leaving...\n");

	return cg_string_getvalue(str);
}
コード例 #7
0
ファイル: chttp_request.c プロジェクト: dallasderk/DLNA
void cg_http_request_seturi(CgHttpRequest *httpReq, char *value)
{
    cg_log_debug_l4("Entering...\n");

    cg_string_setvalue(httpReq->uri, value);

    cg_log_debug_l4("Leaving...\n");
}
コード例 #8
0
ファイル: cinterface.c プロジェクト: 76imagez/remote_ios_test
void cg_net_interface_setnetmask(CgNetworkInterface *netIf, char *value)
{
	cg_log_debug_l4("Entering...\n");

	cg_string_setvalue(netIf->netmask, value);

	cg_log_debug_l4("Leaving...\n");
}
コード例 #9
0
ファイル: cinterface.c プロジェクト: 76imagez/remote_ios_test
void cg_net_interface_setaddress(CgNetworkInterface *netIf, char *value)
{
	cg_log_debug_l4("Entering...\n");

	cg_string_setvalue(netIf->ipaddr, value);

	cg_log_debug_l4("Leaving...\n");
}
コード例 #10
0
ファイル: cinterface.c プロジェクト: 76imagez/remote_ios_test
void cg_net_interface_setname(CgNetworkInterface *netIf, char *name)
{
	cg_log_debug_l4("Entering...\n");

	cg_string_setvalue(netIf->name, name);

	cg_log_debug_l4("Leaving...\n");
}
コード例 #11
0
void cg_http_header_setvalue(CgHttpHeader *header, const char *value)
{
    cg_log_debug_l4("Entering...\n");

    cg_string_setvalue(header->value, value);

    cg_log_debug_l4("Leaving...\n");
}
コード例 #12
0
void cg_upnpav_resource_setdlnaattribute(CgUpnpAvResource *res, char *attr)
{
    CgUpnpAvResourceData *nodeData;

    nodeData = (CgUpnpAvResourceData *)cg_xml_node_getuserdata(res);
    cg_string_setvalue(nodeData->dlnaAttr, attr);

    cg_upnpav_resource_updateattributes(res);
}
コード例 #13
0
void cg_upnpav_resource_setmimetype(CgUpnpAvResource *res, char *mimeType)
{
    CgUpnpAvResourceData *nodeData;

    nodeData = (CgUpnpAvResourceData *)cg_xml_node_getuserdata(res);
    cg_string_setvalue(nodeData->mimeType, mimeType);

    cg_upnpav_resource_updateattributes(res);
}
コード例 #14
0
ファイル: chttp_packet.c プロジェクト: BelkinMike/CyberLink4C
void cg_http_packet_clear(CgHttpPacket *httpPkt)
{
	cg_log_debug_l4("Entering...\n");

	cg_http_headerlist_clear(httpPkt->headerList);
	cg_string_setvalue(httpPkt->content, NULL);

	cg_log_debug_l4("Leaving...\n");
}
コード例 #15
0
ファイル: cstring.c プロジェクト: BelkinMike/CyberLink4C
void cg_string_setlongvalue(CgString *str, long value)
{
	char buf[CG_STRING_LONG_BUFLEN];

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

	cg_string_setvalue(str, cg_long2str(value, buf, sizeof(buf)));

	cg_log_debug_l5("Leaving...\n");
}
コード例 #16
0
ファイル: cstring.c プロジェクト: BelkinMike/CyberLink4C
void cg_string_setintvalue(CgString *str, int value)
{
	char buf[CG_STRING_INTEGER_BUFLEN];

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

	cg_string_setvalue(str, cg_int2str(value, buf, sizeof(buf)));

	cg_log_debug_l5("Leaving...\n");
}
コード例 #17
0
ファイル: curi.c プロジェクト: Deanzou/DLNA
char *cg_net_uri_getrequest(CgNetURI *uri)
{
	cg_log_debug_l4("Entering...\n");

	if (cg_net_uri_hasquery(uri) == FALSE)
	{
		return cg_net_uri_getpath(uri);
	}
	
	if (uri->request == NULL) uri->request = cg_string_new();

	cg_string_setvalue(uri->request, cg_net_uri_getpath(uri));
	cg_string_addvalue(uri->request, CG_NET_URI_QUESTION_DELIM);
	cg_string_addvalue(uri->request, cg_net_uri_getquery(uri));
	
	cg_log_debug_l4("Leaving...\n");

	return cg_string_getvalue(uri->request);
}
コード例 #18
0
ファイル: cxml_node.c プロジェクト: 76imagez/remote_ios_test
static char *cg_xml_node_attribute_tostring(CgXmlNode *node, CgString *str)
{
	CgXmlAttribute *attr;
	char *name;
	char *value;
	CgString *valueStr;
	
	cg_log_debug_l4("Entering...\n");

	valueStr = cg_string_new();
	if (valueStr == NULL) return NULL;

	for (attr = cg_xml_node_getattributes(node); attr != NULL; attr = cg_xml_attribute_next(attr)) {
		name = cg_xml_attribute_getname(attr);
		value = cg_xml_attribute_getvalue(attr);
		
		cg_string_setvalue(valueStr, value);
		cg_xml_escapechars(valueStr);

		/* All the following functions return NULL only when memory 
		   allocation fails, so we can check them all */
		if (!cg_string_naddvalue(str, " ", 1) || 
		    !cg_string_addvalue(str, name) ||
		    !cg_string_naddvalue(str, "=\"", 2) ||
		    !cg_string_addvalue(str, cg_string_getvalue(valueStr)) ||
		    !cg_string_naddvalue(str, "\"", 1))
		{
			/* Memory allocation failed */
			cg_string_delete(valueStr);
			return NULL;
		}
	}
	cg_string_delete(valueStr);
	
	cg_log_debug_l4("Leaving...\n");

	return cg_string_getvalue(str);
}
コード例 #19
0
static void cg_upnp_statevariable_setvaluewithnotify(CgUpnpStateVariable *statVar, char *data, BOOL doNotify)
{
	CgUpnpService *service;

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

	cg_string_setvalue(statVar->value, data);

#if !defined(CG_UPNP_NOUSE_SUBSCRIPTION)
	/**** notify event ****/
	if (doNotify) {
		if (cg_upnp_statevariable_issendevents(statVar) == FALSE)
			return;

		service = cg_upnp_statevariable_getservice(statVar);
		if (service == NULL)
			return;

		cg_upnp_service_notify(service, statVar);
	}
#endif

	cg_log_debug_l4("Leaving...\n");
}
コード例 #20
0
BOOL cg_http_persistentconnection_put(char *host, int port, void *data)
{
       CgHttpPersistentConnection *new_node = NULL, *node = NULL;

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

       /* If we dont have cache, then just exit */
       if (cache == NULL) {
	       cg_log_debug("(put) No cache! Persistent connections not initialized?\n");
	       return FALSE;
       }

       /* Check if we already have this one cached */
       for (node = (CgHttpPersistentConnection*)cg_list_gets((CgList*)cache);
            node != NULL;
            node = (CgHttpPersistentConnection*)cg_list_next((CgList*)node))
       {
               if (cg_strcmp(cg_string_getvalue(node->host), host) == 0 &&
                   node->port == port)
               {
                       /* If also data is the same, then update just
                          timestamp */
                       if (node->cacheData == data)
                       {
                               node->timestamp = cg_getcurrentsystemtime();
                               return TRUE;
                       }

		      cg_log_debug_s("Found cached persistent connection for %s:%d\n",
			      cg_string_getvalue(node->host), node->port);
                       new_node = node;
                       cg_list_remove((CgList*)new_node);
                       break;
               }
       }

       /* We didn't find it */
       if (new_node == NULL)
       {
               /* Check if we have already too many cached things */
               if (cg_list_size((CgList*)cache) >= CG_HTTP_PERSISTENT_CACHE_SIZE)
               {
                       /* Take last node (not refreshed for a long time) */
                       new_node = (CgHttpPersistentConnection *)cg_list_next((CgList *)cache);
                       cg_list_remove((CgList*)new_node);
                       cg_http_persistentconnection_delete(new_node);
                       new_node = NULL;

		      cg_log_debug_s("Max persistent HTTP connection cache reached.\n");
               }

               if (new_node == NULL)
               {
                       if (data == NULL) return TRUE;

                       new_node = cg_http_persistentconnection_new();
                       if (new_node == NULL) return FALSE;

		      cg_log_debug_s("Adding persistent HTTP Connection %s:%d to cache\n",
			       host, port);
		      cg_log_debug_s("Persistent connections: %d\n", cg_list_size((CgList*)cache));
               }
       }

       if (data != NULL)
       {
               /* Set appropriate values for the node */
               cg_string_setvalue(new_node->host, host);
               new_node->port = port;
               new_node->cacheData = data;
               new_node->timestamp = cg_getcurrentsystemtime();

               cg_list_add((CgList*)cache, (CgList*)new_node);
       } else {
               /* remove and delete node */
               cg_http_persistentconnection_delete(new_node);
       }

       return TRUE;

	cg_log_debug_l4("Leaving...\n");
}
コード例 #21
0
ファイル: cresource_data.c プロジェクト: Coramo/mupnp
void cg_upnpav_resource_data_copy(CgUpnpAvResourceData* destResData, CgUpnpAvResourceData* srcResData)
{
  cg_string_setvalue(destResData->mimeType, cg_string_getvalue(srcResData->mimeType));
}
コード例 #22
0
ファイル: cxml_node.c プロジェクト: 76imagez/remote_ios_test
static char *cg_xml_node_tostring_indent(CgXmlNode *node, int indentLevel, BOOL withChildNode, CgString *str)
{
	char *name;
	char *value;
	CgString *valueStr;
	CgXmlNode *childNode;
	
	cg_log_debug_l4("Entering...\n");

	name = cg_xml_node_getname(node);
	value = cg_xml_node_getvalue(node);

	if (cg_xml_node_haschildnodes(node) == FALSE || withChildNode == FALSE) {
		cg_string_addrepvalue(str, CG_XML_INDENT_STRING, indentLevel);
		if (!cg_string_naddvalue(str, "<", 1) ||
		    !cg_string_addvalue(str, name) ||
		    !cg_xml_node_attribute_tostring(node, str))
			/* Memory allocation failed */
			return NULL;
		
		valueStr = cg_string_new();
		if (!valueStr)
			/* Memory allocation failed */
			return NULL;
		
		cg_string_setvalue(valueStr, value);
		cg_xml_escapechars(valueStr);

		if (!cg_string_naddvalue(str, ">", 1) ||
		    !cg_string_addvalue(str, cg_string_getvalue(valueStr)) ||
		    !cg_string_naddvalue(str, "</", 2) ||
		    !cg_string_addvalue(str, name) ||
		    !cg_string_naddvalue(str, ">", 1) ||
		    !cg_string_addvalue(str, "\n"))
		{
			/* Memory allocation failed */
			cg_string_delete(valueStr);
			return NULL;
		}

		cg_string_delete(valueStr);
		
		return cg_string_getvalue(str);
	}

	cg_string_addrepvalue(str, CG_XML_INDENT_STRING, indentLevel);
	if (!cg_string_naddvalue(str, "<", 1) ||
	    !cg_string_addvalue(str, name) ||
	    !cg_xml_node_attribute_tostring(node, str) ||
	    !cg_string_naddvalue(str, ">", 1) ||
	    !cg_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	for (childNode = cg_xml_node_getchildnodes(node); childNode != NULL; childNode = cg_xml_node_next(childNode))
		if (!cg_xml_node_tostring_indent(childNode, indentLevel+1, TRUE, str))
			/* Memory allocation failed */
			return NULL;

	cg_string_addrepvalue(str, CG_XML_INDENT_STRING, indentLevel);
	if (!cg_string_naddvalue(str, "</", 2) ||
	    !cg_string_addvalue(str, name) ||
	    !cg_string_naddvalue(str, ">", 1) ||
	    !cg_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	cg_log_debug_l4("Leaving...\n");
	
	return cg_string_getvalue(str);
}
コード例 #23
0
ファイル: chttp_request.c プロジェクト: dallasderk/DLNA
CgHttpResponse *cg_http_request_post(CgHttpRequest *httpReq, char *ipaddr, int port)
{
    CgHttpResponse *httpRes;
    BOOL newCurl = FALSE;
    CURL *curl;
    CgHttpHeader *reqHeader;
    struct curl_slist *curlHeaderList;
    CgString *headerStr;
    CURLcode res;
    char *uri, *method;
    char url[CG_NET_URI_MAXLEN];
    long retcode;
#ifdef CG_SHOW_TIMINGS
    struct timeval start_time, end_time, elapsed_time;
#endif

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

#ifdef CG_SHOW_TIMINGS
    gettimeofday(&start_time, NULL);
#endif

    httpRes = httpReq->httpRes;

    /* Clear the response data because new data will not
     * overwrite it, but it is appended to the end */
    cg_string_clear(httpRes->content);

    cg_log_debug_s("Posting HTTP request (Curl)\n");
    cg_http_request_print(httpReq);

    cg_http_persistentconnection_lock();
#ifdef CG_HTTP_USE_PERSISTENT_CONNECTIONS
    cg_log_debug_s("Looking for persistent connection to %s, port %d\n", ipaddr, port);
    curl = (CURL*)cg_http_persistentconnection_get(ipaddr, port);

    if (curl == NULL)
    {
        cg_log_debug_s("Persistent connection not found...\n");
#endif
        curl = curl_easy_init();
        if (curl == NULL)
        {
            cg_http_persistentconnection_unlock();
            return httpReq->httpRes;
        }
#ifdef CG_HTTP_USE_PERSISTENT_CONNECTIONS
        newCurl = TRUE;
    }
#endif
    method = cg_http_request_getmethod(httpReq);
    uri = cg_http_request_geturi(httpReq);

    /**** method ****/
    curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method);

    /**** url ****/
    if (uri && cg_strstr(uri, CG_NET_URI_PROTOCOL_DELIM) > 0)
    {
        curl_easy_setopt(curl, CURLOPT_URL, uri);
    }
    else
    {
        cg_net_gethosturl(ipaddr, port, uri, url, sizeof(url));
        curl_easy_setopt(curl, CURLOPT_URL, url);
        cg_log_debug_s("\n\nCURL: %s\n\n", url);
    }

    /**** header ****/
    curlHeaderList = NULL;
    headerStr = cg_string_new();
    for (reqHeader = cg_http_request_getheaders(httpReq); reqHeader; reqHeader = cg_http_header_next(reqHeader)) {
        cg_string_setvalue(headerStr, cg_http_header_getname(reqHeader));
        if (cg_string_addvalue(headerStr, CG_HTTP_COLON CG_HTTP_SP) &&
                cg_string_addvalue(headerStr, cg_http_header_getvalue(reqHeader)))
            curlHeaderList = curl_slist_append(curlHeaderList, cg_string_getvalue(headerStr));
    }
    cg_string_delete(headerStr);
    /* Disable Expect header because it causes IOP issues */
    curlHeaderList = curl_slist_append(curlHeaderList, "Expect:");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curlHeaderList);

    /**** content ****/
    /*if (cg_http_request_ispostrequest(httpReq) == TRUE) {*/
    if (cg_http_request_getcontentlength(httpReq) > 0) {
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, cg_http_request_getcontent(httpReq));
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, cg_http_request_getcontentlength(httpReq));
    }
    else
    {
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, 0);
    }

    /* This has to be enabled for progress callback to be called */
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS,
                     FALSE);

    /* Used for checking stack state during curl easy perform */
    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION,
                     cg_http_request_progress_callback);

    /**** response header callback ****/
    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION,
                     cg_http_request_header_callback);
    curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)httpRes);

    /**** response content callback ****/
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
                     cg_http_request_content_callback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)httpRes);

    /**** useragent ****/
    curl_easy_setopt(curl, CURLOPT_USERAGENT, cg_http_request_getuseragent(httpReq) );

    /**** Prohibit curl from using signals ****/
    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);

    /**** Set the connection timeout so we don't wait forever ****/
    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT,
                     CG_HTTP_CURL_CONNECTTIMEOUT);
    curl_easy_setopt(curl, CURLOPT_TIMEOUT,
                     CG_HTTP_CONN_TIMEOUT);
#ifdef CG_SHOW_TIMINGS
    cg_log_debug_s("\nRequest: %s%s%s\n", method, CG_HTTP_SP, url);
#endif

    /* Get the XML document with CURL */
    res = curl_easy_perform(curl);
    if (res != CURLE_OK)
        cg_log_debug_s("curl_easy_perform: %s\n",
                       curl_easy_strerror(res));

    /* Set the content length, if it wasn't said in the header */
    if (cg_http_response_getcontentlength(httpRes) <= 0)
    {
        cg_http_response_setcontentlength(httpRes,
                                          cg_string_length(httpRes->content));
    }

    curl_slist_free_all(curlHeaderList);

    curl_easy_getinfo (curl, CURLINFO_HTTP_CODE, &retcode);
    cg_http_response_setstatuscode(httpRes, retcode);

#ifdef CG_SHOW_TIMINGS
    gettimeofday(&end_time, NULL);
    timersub(&end_time, &start_time, &elapsed_time);
    cg_log_debug_s("Getting HTTP-response completed. Elapsed time: "
                   "%ld msec\n", ((elapsed_time.tv_sec*1000) +
                                  (elapsed_time.tv_usec/1000)));
    cg_total_elapsed_time += (elapsed_time.tv_sec*1000000)+
                             (elapsed_time.tv_usec);
#endif

#ifdef CG_HTTP_USE_PERSISTENT_CONNECTIONS
    if (newCurl)
    {
        cg_log_debug_s("Putting new connection into cache: %s %d\n", ipaddr, port);
        cg_http_persistentconnection_put(ipaddr, port, curl);
    }
#else
    curl_easy_cleanup(curl);
#endif
    cg_http_persistentconnection_unlock();

    cg_log_debug_s("Response for HTTP request (Curl)\n");
    cg_http_response_print(httpReq->httpRes);

    return httpReq->httpRes;

    cg_log_debug_l4("Leaving...\n");
}
コード例 #24
0
ファイル: curi.c プロジェクト: Deanzou/DLNA
void cg_net_uri_setvalue(CgNetURI *uri, char *value)
{
	char *protocol;
	int uriLen;
	int currIdx;
	int protoIdx;
	int atIdx;
	int colonIdx;
	int shashIdx;
	char *host;
	int eblacketIdx;
	CgString *hostStr;
	CgString *portStr;
	int hostLen;
	int sharpIdx;
	int questionIdx;
	int queryLen;
	
	cg_log_debug_l4("Entering...\n");

	uriLen = cg_strlen(value);
	cg_net_uri_clear(uri);
	cg_net_uri_seturi(uri, value);
		
	currIdx = 0;
	
	/*** Protocol ****/
	protoIdx = cg_strstr(value, CG_NET_URI_PROTOCOL_DELIM);
	if (0 < protoIdx) {
		cg_string_setnvalue(uri->protocol, value,  protoIdx);
		currIdx += protoIdx + cg_strlen(CG_NET_URI_PROTOCOL_DELIM);
	}

	/*** User (Password) ****/
	atIdx = cg_strstr(value+currIdx, CG_NET_URI_USER_DELIM);
	if (0 < atIdx) {
		colonIdx = cg_strstr(value+currIdx, CG_NET_URI_COLON_DELIM);
		/**** Thanks for Theo Beisch (2005/08/25) ****/
		if (0 < colonIdx && colonIdx<atIdx) {
			cg_string_setnvalue(uri->user, value+currIdx,  colonIdx);
			cg_string_setnvalue(uri->password, value+currIdx+colonIdx+1,  atIdx-(colonIdx+1));
		}
		else 
			cg_string_setnvalue(uri->user, value+currIdx,  atIdx - currIdx);
		currIdx += atIdx + 1;
	}

	/*** Host (Port) ****/
	shashIdx = cg_strstr(value+currIdx, CG_NET_URI_SLASH_DELIM);
	if (0 < shashIdx)
		cg_string_setnvalue(uri->host, value+currIdx,  shashIdx);
	else if (cg_net_uri_isabsolute(uri) == TRUE)
		cg_string_setnvalue(uri->host, value+currIdx, cg_strlen(value) - currIdx);
	host = cg_net_uri_gethost(uri);
	colonIdx = cg_strrchr(host, CG_NET_URI_COLON_DELIM, 1);
	eblacketIdx = cg_strrchr(host, CG_NET_URI_EBLACET_DELIM, 1);
	if (0 < colonIdx && eblacketIdx < colonIdx) {
		hostStr = cg_string_new();
		cg_string_setvalue(hostStr, host);
		hostLen = cg_string_length(hostStr);
		/**** host ****/
		cg_string_setnvalue(uri->host, cg_string_getvalue(hostStr),  colonIdx);
		host = cg_net_uri_gethost(uri);
		if (0 < hostLen) {
			if (host[0] == '[' && host[hostLen-1] == ']')
				cg_string_setnvalue(uri->host, cg_string_getvalue(hostStr)+1,  colonIdx-2);
		}
		/**** port ****/
		portStr = cg_string_new();
		cg_string_setnvalue(portStr, cg_string_getvalue(hostStr)+colonIdx+1,  hostLen- colonIdx-1);
		uri->port = atoi(cg_string_getvalue(portStr));
		cg_string_delete(portStr);
		cg_string_delete(hostStr);
	}
	else {
		uri->port = CG_NET_URI_KNKOWN_PORT;
		protocol = cg_net_uri_getprotocol(uri);
		if (cg_strcmp(protocol, CG_NET_URI_PROTOCOL_HTTP) == 0)
			uri->port = CG_NET_URI_DEFAULT_HTTP_PORT;
		if (cg_strcmp(protocol, CG_NET_URI_PROTOCOL_FTP) == 0)
			uri->port = CG_NET_URI_DEFAULT_FTP_PORT;
	}
	
	if (shashIdx > 0) currIdx += shashIdx;
	
	/*
		Handle relative URL
	*/
	if (cg_net_uri_isabsolute(uri) == FALSE)
	{
		cg_string_addvalue(uri->path, value);
		
	} else {
		/* First set path simply to the rest of URI */
		cg_string_setnvalue(uri->path, value+currIdx,  uriLen-currIdx);
	}
		
	/**** Path (Query/Fragment) ****/
	sharpIdx = cg_strstr(value+currIdx, CG_NET_URI_SHARP_DELIM);
	if (0 < sharpIdx) {
		cg_string_setnvalue(uri->path, value+currIdx,  sharpIdx);
		cg_string_setnvalue(uri->fragment, value+currIdx+sharpIdx+1,  uriLen-(currIdx+sharpIdx+1));
	}
	questionIdx = cg_strstr(value+currIdx, CG_NET_URI_QUESTION_DELIM);
	if (0 < questionIdx) {
		cg_string_setnvalue(uri->path, value+currIdx,  questionIdx);
		queryLen = uriLen-(currIdx+questionIdx+1);
		if (0 < sharpIdx)
			queryLen -= uriLen - (currIdx+sharpIdx);
		cg_string_setnvalue(uri->query, value+currIdx+questionIdx+1,  queryLen);
	}

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