Esempio n. 1
0
const char* mupnp_event_subscription_totimeoutheaderstring(mUpnpTime time, mUpnpString* buf)
{
  char timeBuf[MUPNP_STRING_LONG_BUFLEN];

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

  if (time != MUPNP_SUBSCRIPTION_INFINITE_VALUE) {
    mupnp_string_setvalue(buf, MUPNP_SUBSCRIPTION_TIMEOUT_HEADER);
    mupnp_string_addvalue(buf, mupnp_long2str(time, timeBuf, sizeof(timeBuf)));
  }
  else
    mupnp_string_setvalue(buf, MUPNP_SUBSCRIPTION_INFINITE_STRING);
  return mupnp_string_getvalue(buf);

  mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 2
0
void mupnp_http_response_setversion(mUpnpHttpResponse* httpRes, const char* value)
{
  mupnp_log_debug_l4("Entering...\n");

  mupnp_string_setvalue(httpRes->version, value);

  mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 3
0
void mupnp_http_response_setreasonphrase(mUpnpHttpResponse* httpRes, const char* value)
{
  mupnp_log_debug_l4("Entering...\n");

  mupnp_string_setvalue(httpRes->reasonPhrase, value);

  mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 4
0
void mupnp_net_interface_setname(mUpnpNetworkInterface *netIf, char *name)
{
	mupnp_log_debug_l4("Entering...\n");

	mupnp_string_setvalue(netIf->name, name);

	mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 5
0
void mupnp_net_interface_setaddress(mUpnpNetworkInterface *netIf, char *value)
{
	mupnp_log_debug_l4("Entering...\n");

	mupnp_string_setvalue(netIf->ipaddr, value);

	mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 6
0
void mupnp_http_header_setvalue(mUpnpHttpHeader* header, const char* value)
{
  mupnp_log_debug_l4("Entering...\n");

  mupnp_string_setvalue(header->value, value);

  mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 7
0
char *mupnp_upnpav_protocolinfo_getstring(mUpnpAvProtocolInfo *info)
{
	char protocolInfoBuf[CG_UPNPAV_PROTOCOLINFO_MAXSIZE];

#if defined(WIN32)
	_snprintf(
#else
	snprintf(
#endif
			protocolInfoBuf,
			sizeof(protocolInfoBuf),
			"%s:%s:%s:%s",
		mupnp_upnpav_protocolinfo_getprotocol(info),
		mupnp_upnpav_protocolinfo_getnetwork(info),
		mupnp_upnpav_protocolinfo_getmimetype(info),
		mupnp_upnpav_protocolinfo_getadditionainfo(info));

	mupnp_string_setvalue(info->string, protocolInfoBuf);

	return mupnp_string_getvalue(info->string);
}
Esempio n. 8
0
static char *mupnp_xml_node_attribute_tostring(mUpnpXmlNode *node, mUpnpString *str)
{
	mUpnpXmlAttribute *attr;
	const char *name;
	const char *value;
	mUpnpString *valueStr;
	
	mupnp_log_debug_l4("Entering...\n");

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

	for (attr = mupnp_xml_node_getattributes(node); attr != NULL; attr = mupnp_xml_attribute_next(attr)) {
		name = mupnp_xml_attribute_getname(attr);
		value = mupnp_xml_attribute_getvalue(attr);
		
		mupnp_string_setvalue(valueStr, value);
		mupnp_xml_escapechars(valueStr);

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

	return mupnp_string_getvalue(str);
}
Esempio n. 9
0
static char *mupnp_xml_node_tostring_indent(mUpnpXmlNode *node, int indentLevel, bool withChildNode, mUpnpString *str)
{
	char *name;
	char *value;
	mUpnpString *valueStr;
	mUpnpXmlNode *childNode;
	
	mupnp_log_debug_l4("Entering...\n");

	name = mupnp_xml_node_getname(node);
	value = mupnp_xml_node_getvalue(node);

	if (mupnp_xml_node_haschildnodes(node) == false || withChildNode == false) {
		mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel);
		if (!mupnp_string_naddvalue(str, "<", 1) ||
		    !mupnp_string_addvalue(str, name) ||
		    !mupnp_xml_node_attribute_tostring(node, str))
			/* Memory allocation failed */
			return NULL;
		
		valueStr = mupnp_string_new();
		if (!valueStr)
			/* Memory allocation failed */
			return NULL;
		
		mupnp_string_setvalue(valueStr, value);
		mupnp_xml_escapechars(valueStr);

		if (!mupnp_string_naddvalue(str, ">", 1) ||
		    !mupnp_string_addvalue(str, mupnp_string_getvalue(valueStr)) ||
		    !mupnp_string_naddvalue(str, "</", 2) ||
		    !mupnp_string_addvalue(str, name) ||
		    !mupnp_string_naddvalue(str, ">", 1) ||
		    !mupnp_string_addvalue(str, "\n"))
		{
			/* Memory allocation failed */
			mupnp_string_delete(valueStr);
			return NULL;
		}

		mupnp_string_delete(valueStr);
		
		return mupnp_string_getvalue(str);
	}

	mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel);
	if (!mupnp_string_naddvalue(str, "<", 1) ||
	    !mupnp_string_addvalue(str, name) ||
	    !mupnp_xml_node_attribute_tostring(node, str) ||
	    !mupnp_string_naddvalue(str, ">", 1) ||
	    !mupnp_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	for (childNode = mupnp_xml_node_getchildnodes(node); childNode != NULL; childNode = mupnp_xml_node_next(childNode))
		if (!mupnp_xml_node_tostring_indent(childNode, indentLevel+1, true, str))
			/* Memory allocation failed */
			return NULL;

	mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel);
	if (!mupnp_string_naddvalue(str, "</", 2) ||
	    !mupnp_string_addvalue(str, name) ||
	    !mupnp_string_naddvalue(str, ">", 1) ||
	    !mupnp_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	mupnp_log_debug_l4("Leaving...\n");
	
	return mupnp_string_getvalue(str);
}
Esempio n. 10
0
BOOL mupnp_http_persistentconnection_put(char *host, int port, void *data)
{
       mUpnpHttpPersistentConnection *new_node = NULL, *node = NULL;

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

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

       /* Check if we already have this one cached */
       for (node = (mUpnpHttpPersistentConnection*)mupnp_list_gets((mUpnpList*)cache);
            node != NULL;
            node = (mUpnpHttpPersistentConnection*)mupnp_list_next((mUpnpList*)node))
       {
               if (mupnp_strcmp(mupnp_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 = mupnp_getcurrentsystemtime();
                               return TRUE;
                       }

		      mupnp_log_debug_s("Found cached persistent connection for %s:%d\n",
			      mupnp_string_getvalue(node->host), node->port);
                       new_node = node;
                       mupnp_list_remove((mUpnpList*)new_node);
                       break;
               }
       }

       /* We didn't find it */
       if (new_node == NULL)
       {
               /* Check if we have already too many cached things */
               if (mupnp_list_size((mUpnpList*)cache) >= CG_HTTP_PERSISTENT_CACHE_SIZE)
               {
                       /* Take last node (not refreshed for a long time) */
                       new_node = (mUpnpHttpPersistentConnection *)mupnp_list_next((mUpnpList *)cache);
                       mupnp_list_remove((mUpnpList*)new_node);
                       mupnp_http_persistentconnection_delete(new_node);
                       new_node = NULL;

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

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

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

		      mupnp_log_debug_s("Adding persistent HTTP Connection %s:%d to cache\n",
			       host, port);
		      mupnp_log_debug_s("Persistent connections: %d\n", mupnp_list_size((mUpnpList*)cache));
               }
       }

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

               mupnp_list_add((mUpnpList*)cache, (mUpnpList*)new_node);
       } else {
               /* remove and delete node */
               mupnp_http_persistentconnection_delete(new_node);
       }

       return TRUE;

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