Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
CgXmlNode *cg_xml_node_new()
{
	CgXmlNode *node;
	
	cg_log_debug_l4("Entering...\n");

	node = (CgXmlNode *)malloc(sizeof(CgXmlNode));

	if ( NULL != node )
	{
		cg_list_node_init((CgList *)node);

		node->name = cg_string_new();
		node->value = cg_string_new();
		node->attrList = cg_xml_attributelist_new();
		node->nodeList = cg_xml_nodelist_new();
		node->parentNode = NULL;
		node->userData = NULL;
		node->userDataDestructorFunc = NULL;
	}

	cg_log_debug_l4("Leaving...\n");
	
	return node;
}
Ejemplo n.º 3
0
CgUpnpAvResourceData* cg_upnpav_resource_data_new()
{
  CgUpnpAvResourceData* resData;

  resData = (CgUpnpAvResourceData*)malloc(sizeof(CgUpnpAvResourceData));
  resData->mimeType = cg_string_new();
  resData->dlnaAttr = cg_string_new();

  return resData;
}
Ejemplo n.º 4
0
Archivo: curi.c Proyecto: 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;
}
Ejemplo n.º 5
0
BOOL cg_bittorrent_metainfo_save(CgBittorrentMetainfo *cbm, char *fileName)
{
	FILE *fp;
	CgString *str;

	if (!cbm)
		return FALSE;

	str = cg_string_new();
	if (!str)
		return FALSE;

	if (!cg_bittorrent_metainfo_tostring(cbm, str)) {
		cg_string_delete(str);
		return FALSE;
	}

	fp = fopen(fileName, "wb");
	if (fp) {
		fwrite(cg_string_getvalue(str), sizeof(char), cg_string_length(str), fp);
		fclose(fp);
	}

	cg_string_delete(str);

	return (fp ? TRUE : FALSE);
}
Ejemplo n.º 6
0
CgUpnpStateVariable *cg_upnp_statevariable_new()
{
	CgUpnpStateVariable *statVar;

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

	statVar = (CgUpnpStateVariable *)malloc(sizeof(CgUpnpStateVariable));

	if ( NULL != statVar )
	{
		cg_list_node_init((CgList *)statVar);
		
		statVar->parentService = NULL;
		statVar->stateVarNode = NULL;
		
		statVar->value = cg_string_new();
		statVar->upnpStatus = cg_upnp_status_new();
		
		cg_upnp_statevariable_setlistener(statVar, NULL);
		cg_upnp_statevariable_setuserdata(statVar, NULL);
	}
	
	cg_log_debug_l4("Leaving...\n");

	return statVar;
}
Ejemplo n.º 7
0
void  cg_xml_node_print(CgXmlNode *node)
{
	CgString *str = cg_string_new();
	cg_xml_node_tostring(node, TRUE, str);
	printf("%s", cg_string_getvalue(str));
	cg_string_delete(str);
}
Ejemplo n.º 8
0
BOOL cg_upnp_ssdpresponse_server_post(CgUpnpSSDPResponseServer *server, CgUpnpSSDPRequest *ssdpReq)
{
	CgUpnpHttpUSocket *httpuSock;
	char *ifAddr;
	const char *ssdpAddr;
	CgString *ssdpMsg;
	size_t sentLen = 0;
	
	cg_log_debug_l4("Entering...\n");

	httpuSock = cg_upnp_ssdpresponse_server_getsocket(server);
	
	ifAddr = cg_socket_getaddress(httpuSock);
	ssdpAddr = cg_upnp_ssdp_gethostaddress(ifAddr);
	cg_upnp_ssdprequest_sethost(ssdpReq, ssdpAddr, CG_UPNP_SSDP_PORT);
		
	ssdpMsg = cg_string_new();
	cg_upnp_ssdprequest_tostring(ssdpReq, ssdpMsg);

	sentLen = cg_socket_sendto(httpuSock, ssdpAddr, CG_UPNP_SSDP_PORT, cg_string_getvalue(ssdpMsg), cg_string_length(ssdpMsg));
	cg_string_delete(ssdpMsg);
	
	cg_log_debug_l4("Leaving...\n");

	return (sentLen > 0);
}
CgHttpPersistentConnection *cg_http_persistentconnection_new(void)
{
       CgHttpPersistentConnection *new_node;
       
       cg_log_debug_l4("Entering...\n");

       new_node = (CgHttpPersistentConnection *)malloc(sizeof(CgHttpPersistentConnection));

       if ( NULL != new_node )
       {
	       new_node->headFlag = FALSE;
	       new_node->next = NULL;
	       new_node->prev = NULL;

	       new_node->host = cg_string_new();
	       new_node->port = 0;
	       new_node->cacheData = NULL;

	       new_node->timestamp = 0;
       }

       return new_node;

	cg_log_debug_l4("Leaving...\n");
}
Ejemplo n.º 10
0
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);
}
Ejemplo n.º 11
0
void cg_http_packet_init(CgHttpPacket *httpPkt)
{
	cg_log_debug_l4("Entering...\n");

	httpPkt->headerList = cg_http_headerlist_new();
	httpPkt->content = cg_string_new();

	cg_log_debug_l4("Leaving...\n");
}
Ejemplo n.º 12
0
CgHttpHeader *cg_http_header_new()
{
    CgHttpHeader *header;

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

    header = (CgHttpHeader *)malloc(sizeof(CgHttpHeader));

    if ( NULL != header )
    {
        cg_list_node_init((CgList *)header);
        header->name = cg_string_new();
        header->value = cg_string_new();
    }

    return header;

    cg_log_debug_l4("Leaving...\n");
}
void cg_upnp_event_subscription_request_settimeout(void *subReq, long timeout)
{
    CgString *timeoutBuf;

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

    timeoutBuf = cg_string_new();
    cg_http_packet_setheadervalue(((CgHttpPacket*)subReq), CG_HTTP_TIMEOUT, cg_upnp_event_subscription_totimeoutheaderstring(timeout, timeoutBuf));
    cg_string_delete(timeoutBuf);

    cg_log_debug_l4("Leaving...\n");
}
void cg_upnp_event_subscription_response_settimeout(CgUpnpSubscriptionResponse *subRes, long value)
{
	CgString *buf;

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

	buf = cg_string_new();
	cg_http_packet_setheadervalue((CgHttpPacket*)subRes, CG_HTTP_TIMEOUT, cg_upnp_event_subscription_totimeoutheaderstring(value, buf));
	cg_string_delete(buf);

	cg_log_debug_l4("Leaving...\n");
}
Ejemplo n.º 15
0
CgDatagramPacket *cg_socket_datagram_packet_new()
{
	CgDatagramPacket *dgmPkt;

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

	dgmPkt = (CgDatagramPacket *)malloc(sizeof(CgDatagramPacket));

	if ( NULL != dgmPkt )
	{
		dgmPkt->data = cg_string_new();
		dgmPkt->localAddress = cg_string_new();
		dgmPkt->remoteAddress = cg_string_new();

		cg_socket_datagram_packet_setlocalport(dgmPkt, 0);
		cg_socket_datagram_packet_setremoteport(dgmPkt, 0);
	}
	
	return dgmPkt;

	cg_log_debug_l4("Leaving...\n");
}
Ejemplo n.º 16
0
CgNetworkInterface *cg_net_interface_new()
{
	CgNetworkInterface *netIf;

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

	netIf = (CgNetworkInterface *)malloc(sizeof(CgNetworkInterface));

	if ( NULL != netIf )
	{
		cg_list_node_init((CgList *)netIf);
		netIf->name = cg_string_new();
		netIf->ipaddr = cg_string_new();
		netIf->netmask = cg_string_new();
		cg_net_interface_setindex(netIf, 0);
		memset(netIf->macaddr, 0, (size_t)CG_NET_MACADDR_SIZE);
	}
	
	cg_log_debug_l4("Leaving...\n");

	return netIf;
}
Ejemplo n.º 17
0
Archivo: curi.c Proyecto: Deanzou/DLNA
CgDictionary *cg_net_uri_getquerydictionary(CgNetURI *uri)
{
	char *query;
	int queryOffset;
	int eqIdx, ampIdx;
	CgString *paramName;
	CgString *paramValue;

	if (NULL == uri->queryDictionary)
		uri->queryDictionary = cg_dictionary_new();

	paramName = cg_string_new();
	paramValue = cg_string_new();

	query = cg_net_uri_getquery(uri);
	queryOffset = 0;

	eqIdx = cg_strstr(query, "=");
	while (0 < eqIdx) {
		ampIdx = cg_strstr(query + queryOffset, "&");
		if (ampIdx <= 0) {
			ampIdx = cg_strstr(query + queryOffset, "#");
			if (ampIdx <= 0)
				ampIdx = cg_strlen(query + queryOffset);
		}
		if (ampIdx <= eqIdx)
			break;
		cg_string_setnvalue(paramName, query + queryOffset, eqIdx);
		cg_string_setnvalue(paramValue, query + queryOffset + eqIdx + 1, (ampIdx - eqIdx -1));
		cg_dictionary_setvalue(uri->queryDictionary, cg_string_getvalue(paramName), cg_string_getvalue(paramValue));
		queryOffset += ampIdx + 1;
		eqIdx = cg_strstr(query + queryOffset, "=");
	}

	cg_string_delete(paramName);
	cg_string_delete(paramValue);

	return uri->queryDictionary;
}
Ejemplo n.º 18
0
CgUpnpProperty *cg_upnp_property_new()
{
    CgUpnpProperty *prop;

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

    prop = (CgUpnpProperty *)malloc(sizeof(CgUpnpProperty));

    if ( NULL != prop )
    {
        cg_list_node_init((CgList *)prop);

        prop->name = cg_string_new();
        prop->value = cg_string_new();
        prop->sid = cg_string_new();

        cg_upnp_property_setseq(prop, 0);
    }

    return prop;

    cg_log_debug_l4("Leaving...\n");
}
Ejemplo n.º 19
0
/**
 * Create a new control point. Does not start any threads.
 *
 * @return A newly-created CgUpnpControlPoint
 */
CgUpnpControlPoint *cg_upnp_controlpoint_new()
{
	CgUpnpControlPoint *ctrlPoint;

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

	ctrlPoint = (CgUpnpControlPoint *)malloc(sizeof(CgUpnpControlPoint));

	if ( NULL != ctrlPoint )
	{
#ifdef CG_HTTP_USE_PERSISTENT_CONNECTIONS	
		cg_http_persistentconnection_init();
#endif
		ctrlPoint->mutex = cg_mutex_new();
		ctrlPoint->deviceRootNodeList = cg_xml_nodelist_new();
		ctrlPoint->deviceList = cg_upnp_devicelist_new();
		ctrlPoint->ssdpServerList = cg_upnp_ssdp_serverlist_new();
		ctrlPoint->ssdpResServerList = cg_upnp_ssdpresponse_serverlist_new();
		ctrlPoint->httpServerList = cg_http_serverlist_new();
		ctrlPoint->httpEventURI = cg_string_new();
		ctrlPoint->eventListeners = cg_upnp_eventlistenerlist_new();

		/* Expiration handling */
		ctrlPoint->expThread = cg_thread_new();
		cg_thread_setaction(ctrlPoint->expThread, cg_upnp_controlpoint_expirationhandler);
		cg_thread_setuserdata(ctrlPoint->expThread, ctrlPoint);
		ctrlPoint->expMutex = cg_mutex_new();
		ctrlPoint->expCond = cg_cond_new();
		
		ctrlPoint->ifCache = cg_net_interfacelist_new();
		
		cg_upnp_controlpoint_setssdplistener(ctrlPoint, NULL);
		cg_upnp_controlpoint_setssdpresponselistener(ctrlPoint, NULL);
		cg_upnp_controlpoint_sethttplistener(ctrlPoint, NULL);
		cg_upnp_controlpoint_setdevicelistener(ctrlPoint, NULL);
		
		cg_upnp_controlpoint_setssdpresponseport(ctrlPoint, CG_UPNP_CONTROLPOINT_SSDP_RESPONSE_DEFAULT_PORT);
		cg_upnp_controlpoint_setssdpsearchmx(ctrlPoint, CG_UPNP_CONTROLPOINT_SSDP_DEFAULT_SEARCH_MX);
		cg_upnp_controlpoint_seteventport(ctrlPoint, CG_UPNP_CONTROLPOINT_HTTP_EVENT_DEFAULT_PORT);
		cg_upnp_controlpoint_seteventsuburi(ctrlPoint, CG_UPNP_CONTROLPOINT_HTTP_EVENTSUB_URI);

		cg_upnp_controlpoint_setuserdata(ctrlPoint, NULL);
	}

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

	return ctrlPoint;
}
Ejemplo n.º 20
0
BOOL cg_upnp_ssdp_socket_postresponse(CgUpnpSSDPSocket *ssdpSock, CgUpnpSSDPResponse *ssdpRes, const char *host, int port)
{
	CgString *ssdpMsg;
  size_t ssdpMsgLen;
	BOOL postSuccess;

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

	ssdpMsg = cg_string_new();
	cg_upnp_ssdpresponse_tostring(ssdpRes, ssdpMsg);
  ssdpMsgLen = cg_string_length(ssdpMsg);
	postSuccess = (cg_socket_sendto(ssdpSock, host, port, cg_string_getvalue(ssdpMsg), ssdpMsgLen) == ssdpMsgLen) ? TRUE : FALSE;
	cg_string_delete(ssdpMsg);

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

	return postSuccess;
}
Ejemplo n.º 21
0
static BOOL cg_upnp_ssdp_socket_notify(CgUpnpSSDPSocket *ssdpSock, CgUpnpSSDPRequest *ssdpReq, const char *ssdpAddr)
{
	CgString *ssdpMsg;
	size_t sentLen;

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

	cg_upnp_ssdprequest_setmethod(ssdpReq, CG_HTTP_NOTIFY);
	
	ssdpMsg = cg_string_new();
	cg_upnp_ssdprequest_tostring(ssdpReq, ssdpMsg);

	sentLen = cg_socket_sendto(ssdpSock, ssdpAddr, CG_UPNP_SSDP_PORT, cg_string_getvalue(ssdpMsg), cg_string_length(ssdpMsg));
	cg_string_delete(ssdpMsg);
	
	cg_log_debug_l4("Leaving...\n");

	return (0 < sentLen) ? TRUE : FALSE;
}
Ejemplo n.º 22
0
void cg_upnpav_resource_updateattributes(CgUpnpAvResource *res)
{
    CgUpnpAvResourceData *nodeData;
    CgString *resAttr;
    char *mimeType;
    char *dlnaAttr;

    nodeData = (CgUpnpAvResourceData *)cg_xml_node_getuserdata(res);
    mimeType = (0 < cg_string_length(nodeData->mimeType)) ? cg_string_getvalue(nodeData->mimeType) : "*/*";
    dlnaAttr = (0 < cg_string_length(nodeData->dlnaAttr)) ? cg_string_getvalue(nodeData->dlnaAttr) : "*";

    resAttr = cg_string_new();
    cg_string_addvalue(resAttr, "http-get:*:");
    cg_string_addvalue(resAttr, mimeType);
    cg_string_addvalue(resAttr, ":");
    cg_string_addvalue(resAttr, dlnaAttr);
    cg_xml_node_setattribute(res, CG_UPNPAV_RESOURCE_PROTOCOLINFO, cg_string_getvalue(resAttr));
    cg_string_delete(resAttr);
}
Ejemplo n.º 23
0
Archivo: curi.c Proyecto: 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);
}
void cg_upnp_event_subscription_request_setsid(CgUpnpSubscriptionRequest *subReq, const char *sid)
{
    CgString *headerSID;
    ssize_t uuidIdx;

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

    headerSID = cg_string_new();

    uuidIdx = cg_strstr(sid, CG_UPNP_ST_UUID_DEVICE);
    if (uuidIdx < 0)
        cg_string_addvalue(headerSID, CG_UPNP_ST_UUID_DEVICE ":");
    cg_string_addvalue(headerSID, sid);

    cg_http_packet_setheadervalue(((CgHttpPacket*)subReq), CG_HTTP_SID, cg_string_getvalue(headerSID));

    cg_string_delete(headerSID);

    cg_log_debug_l4("Leaving...\n");
}
Ejemplo n.º 25
0
CgSocket *cg_socket_new(int type)
{
	CgSocket *sock;

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

	cg_socket_startup();

	sock = (CgSocket *)malloc(sizeof(CgSocket));

	if ( NULL != sock )
	{
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(ITRON)
		sock->id = INVALID_SOCKET;
#else
		sock->id = -1;
#endif

		cg_socket_settype(sock, type);
		cg_socket_setdirection(sock, CG_NET_SOCKET_NONE);

		sock->ipaddr = cg_string_new();

		cg_socket_setaddress(sock, "");
		cg_socket_setport(sock, -1);

#if defined(ITRON)
		sock->sendWinBuf = NULL;
		sock->recvWinBuf = NULL;
#endif

#if defined(CG_USE_OPENSSL)
		sock->ctx = NULL;
		sock->ssl = NULL;
#endif
	}

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

	return sock;
}
Ejemplo n.º 26
0
void cg_upnpav_dmr_addprotocolinfo(CgUpnpAvRenderer* dmr, CgUpnpAvProtocolInfo* info)
{
  CgString* protocolInfos;
  CgUpnpAvProtocolInfo* protocolInfo;
  CgUpnpService* service;
  CgUpnpStateVariable* stateVar;

  cg_upnpav_protocolinfolist_add(dmr->protocolInfoList, info);

  protocolInfos = cg_string_new();
  for (protocolInfo = cg_upnpav_dmr_getprotocolinfos(dmr); 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));
  }

  service = cg_upnp_device_getservicebyexacttype(dmr->dev, CG_UPNPAV_DMR_CONNECTIONMANAGER_SERVICE_TYPE);
  stateVar = cg_upnp_service_getstatevariablebyname(service, CG_UPNPAV_DMR_CONNECTIONMANAGER_SINKPROTOCOLINFO);
  cg_upnp_statevariable_setvalue(stateVar, cg_string_getvalue(protocolInfos));

  cg_string_delete(protocolInfos);
}
Ejemplo n.º 27
0
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;
}
Ejemplo n.º 28
0
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);
}
Ejemplo n.º 29
0
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);
}
Ejemplo n.º 30
0
Archivo: curi.c Proyecto: 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");
}