• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ParseNameValue函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中ParseNameValue函数的典型用法代码示例。如果您正苦于以下问题:C++ ParseNameValue函数的具体用法?C++ ParseNameValue怎么用?C++ ParseNameValue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ParseNameValue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: UPNP_GetTotalPacketsReceived

MINIUPNP_LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalPacketsReceived(const char * controlURL,
						const char * servicetype)
{
	struct NameValueParserData pdata;
	char * buffer;
	int bufsize;
	unsigned int r = 0;
	char * p;
	if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
	                                "GetTotalPacketsReceived", 0, &bufsize))) {
		return UPNPCOMMAND_HTTP_ERROR;
	}
	ParseNameValue(buffer, bufsize, &pdata);
	/*DisplayNameValueList(buffer, bufsize);*/
	free(buffer); buffer = NULL;
	p = GetValueFromNameValueList(&pdata, "NewTotalPacketsReceived");
	r = my_atoui(p);
	ClearNameValueList(&pdata);
	return r;
}
开发者ID:Bluecoreg,项目名称:monero,代码行数:21,代码来源:upnpcommands.c


示例2: UPNP_GetExternalIPAddress

/* UPNP_GetExternalIPAddress() call the corresponding UPNP method.
 * if the third arg is not null the value is copied to it.
 * at least 16 bytes must be available
 *
 * Return values :
 * 0 : SUCCESS
 * NON ZERO : ERROR Either an UPnP error code or an unknown error.
 *
 * 402 Invalid Args - See UPnP Device Architecture section on Control.
 * 501 Action Failed - See UPnP Device Architecture section on Control.
 */
LIBSPEC int
UPNP_GetExternalIPAddress(const char * controlURL,
                          const char * servicetype,
                          char * extIpAdd)
{
    struct NameValueParserData pdata;
    char * buffer;
    int bufsize;
    char * p;
    int ret = UPNPCOMMAND_UNKNOWN_ERROR;

    if(!extIpAdd || !controlURL || !servicetype)
        return UPNPCOMMAND_INVALID_ARGS;

    if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
                                    "GetExternalIPAddress", 0, &bufsize))) {
        return UPNPCOMMAND_HTTP_ERROR;
    }
    /*DisplayNameValueList(buffer, bufsize);*/
    ParseNameValue(buffer, bufsize, &pdata);
    free(buffer);
    buffer = NULL;
    /*printf("external ip = %s\n", GetValueFromNameValueList(&pdata, "NewExternalIPAddress") );*/
    p = GetValueFromNameValueList(&pdata, "NewExternalIPAddress");
    if(p) {
        strncpy(extIpAdd, p, 16 );
        extIpAdd[15] = '\0';
        ret = UPNPCOMMAND_SUCCESS;
    } else
        extIpAdd[0] = '\0';

    p = GetValueFromNameValueList(&pdata, "errorCode");
    if(p) {
        ret = UPNPCOMMAND_UNKNOWN_ERROR;
        sscanf(p, "%d", &ret);
    }

    ClearNameValueList(&pdata);
    return ret;
}
开发者ID:wdmchaft,项目名称:Psybrus,代码行数:51,代码来源:upnpcommands.c


示例3: UPNP_DeletePortMapping

LIBSPEC int
UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
                       const char * extPort, const char * proto,
                       const char * remoteHost)
{
	/*struct NameValueParserData pdata;*/
	struct UPNParg * DeletePortMappingArgs;
	char buffer[4096];
	int bufsize = 4096;
	struct NameValueParserData pdata;
	const char * resVal;
	int ret;

	if(!extPort || !proto)
		return UPNPCOMMAND_INVALID_ARGS;

	DeletePortMappingArgs = calloc(4, sizeof(struct UPNParg));
	DeletePortMappingArgs[0].elt = "NewRemoteHost";
	DeletePortMappingArgs[0].val = remoteHost;
	DeletePortMappingArgs[1].elt = "NewExternalPort";
	DeletePortMappingArgs[1].val = extPort;
	DeletePortMappingArgs[2].elt = "NewProtocol";
	DeletePortMappingArgs[2].val = proto;
	simpleUPnPcommand(-1, controlURL, servicetype,
	                  "DeletePortMapping",
					  DeletePortMappingArgs, buffer, &bufsize);
	/*DisplayNameValueList(buffer, bufsize);*/
	ParseNameValue(buffer, bufsize, &pdata);
	resVal = GetValueFromNameValueList(&pdata, "errorCode");
	if(resVal) {
		ret = UPNPCOMMAND_UNKNOWN_ERROR;
		sscanf(resVal, "%d", &ret);
	} else {
		ret = UPNPCOMMAND_SUCCESS;
	}
	ClearNameValueList(&pdata);
	free(DeletePortMappingArgs);
	return ret;
}
开发者ID:ProfDrLuigi,项目名称:wired,代码行数:39,代码来源:upnpcommands.c


示例4: UPNP_GetStatusInfo

/* UPNP_GetStatusInfo() call the corresponding UPNP method
 * returns the current status and uptime */
void UPNP_GetStatusInfo(const char * controlURL,
												const char * servicetype,
												char * status, 
												unsigned int * uptime)
{
	struct NameValueParserData pdata;
	char buffer[4096];
	int bufsize = 4096;
	char * p;
	char* up;

	if(!status && !uptime)
		return;

	simpleUPnPcommand(-1, controlURL, servicetype, "GetStatusInfo", 0, buffer, &bufsize);
	ParseNameValue(buffer, bufsize, &pdata);
	/*DisplayNameValueList(buffer, bufsize);*/
	up = GetValueFromNameValueList(&pdata, "NewUptime");
	p = GetValueFromNameValueList(&pdata, "NewConnectionStatus");

	if(status)
	{
		if(p){
			strncpy(status, p, 64 );
			status[63] = '\0';
		}else
			status[0]= '\0';
	}

	if(uptime){
		if(p)
			sscanf(up,"%u",uptime);
		else
			uptime = 0;
	}

	ClearNameValueList(&pdata);
}
开发者ID:SupportSpace,项目名称:SupportCenter,代码行数:40,代码来源:upnpcommands.c


示例5: UPNP_GetPortMappingNumberOfEntries

LIBSPEC int
UPNP_GetPortMappingNumberOfEntries(const char * controlURL,
                                   const char * servicetype,
                                   unsigned int * numEntries)
{
    struct NameValueParserData pdata;
    char * buffer;
    int bufsize;
    char* p;
    int ret = UPNPCOMMAND_UNKNOWN_ERROR;
    if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
                                    "GetPortMappingNumberOfEntries", 0,
                                    &bufsize))) {
        return UPNPCOMMAND_HTTP_ERROR;
    }
#ifdef DEBUG
    DisplayNameValueList(buffer, bufsize);
#endif
    ParseNameValue(buffer, bufsize, &pdata);
    free(buffer);
    buffer = NULL;

    p = GetValueFromNameValueList(&pdata, "NewPortMappingNumberOfEntries");
    if(numEntries && p) {
        *numEntries = 0;
        sscanf(p, "%u", numEntries);
        ret = UPNPCOMMAND_SUCCESS;
    }

    p = GetValueFromNameValueList(&pdata, "errorCode");
    if(p) {
        ret = UPNPCOMMAND_UNKNOWN_ERROR;
        sscanf(p, "%d", &ret);
    }

    ClearNameValueList(&pdata);
    return ret;
}
开发者ID:wdmchaft,项目名称:Psybrus,代码行数:38,代码来源:upnpcommands.c


示例6: UPNP_GetConnectionTypeInfo

/* UPNP_GetConnectionTypeInfo() call the corresponding UPNP method
 * returns the connection type */
LIBSPEC int
UPNP_GetConnectionTypeInfo(const char * controlURL,
                           const char * servicetype,
                           char * connectionType)
{
    struct NameValueParserData pdata;
    char * buffer;
    int bufsize;
    char * p;
    int ret = UPNPCOMMAND_UNKNOWN_ERROR;

    if(!connectionType)
        return UPNPCOMMAND_INVALID_ARGS;

    if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
                                    "GetConnectionTypeInfo", 0, &bufsize))) {
        return UPNPCOMMAND_HTTP_ERROR;
    }
    ParseNameValue(buffer, bufsize, &pdata);
    free(buffer);
    buffer = NULL;
    p = GetValueFromNameValueList(&pdata, "NewConnectionType");
    /*p = GetValueFromNameValueList(&pdata, "NewPossibleConnectionTypes");*/
    /* PossibleConnectionTypes will have several values.... */
    if(p) {
        strncpy(connectionType, p, 64 );
        connectionType[63] = '\0';
        ret = UPNPCOMMAND_SUCCESS;
    } else
        connectionType[0] = '\0';
    p = GetValueFromNameValueList(&pdata, "errorCode");
    if(p) {
        ret = UPNPCOMMAND_UNKNOWN_ERROR;
        sscanf(p, "%d", &ret);
    }
    ClearNameValueList(&pdata);
    return ret;
}
开发者ID:wdmchaft,项目名称:Psybrus,代码行数:40,代码来源:upnpcommands.c


示例7: GetModuleHolder

//---------------------------------------------------------------------------
AnsiString TRsyncConfigAdapter::GetParamValue(AnsiString moduleName, AnsiString paramName){
    TModuleHolder* aHolder = GetModuleHolder(moduleName);

    if(aHolder == NULL){
        return "Invalid module name";
    }


    TStringList* params = aHolder->nvp;

    for(int i = 0; i < params->Count; i++){
        AnsiString oneLine = params->Strings[i];
        AnsiString sName, sValue;

        if(ParseNameValue(oneLine, sName, sValue)){
            if(sName == paramName){
                return sValue;
            }
        }

    }
    return "";
}
开发者ID:AndyHuang7601,项目名称:EpicGames-UnrealEngine,代码行数:24,代码来源:RSyncConfigAdapter.cpp


示例8: parse_form_encoded


//.........这里部分代码省略.........
                   len = atoi(slen+strlen("filelength=\""));
               }
               else 
               {
                   /*
                   if (-1 != fd)
                   {
                       char tt[1024];
                       snprintf(tt, 1024, "boundary file length=%s\n", "NULL");
                       write(fd, tt, strlen(tt));
                   }
                   */
                   slen = getenv("filelength");
                   if (NULL != slen)
                   {
                       /*
                       if (-1 != fd)
                       {
                           char tt[1024];
                           snprintf(tt, 1024, "env file length=%s\n", slen);
                           write(fd, tt, strlen(tt));
                       }
                       */
                       len = atoi(slen);
                   }
                   else
                   {
                       /*
                       if (-1 != fd)
                       {
                           char tt[1024];
                           snprintf(tt, 1024, "env file length=%s\n", "NULL");
                           write(fd, tt, strlen(tt));
                       }
                       */
                   }
               }
               if (len > 0 && len < content_length-oldpos-head_end_pos-head_end_len-boundlen-2)
               {
                   if (0 == memcmp(tmp+head_end_pos+head_end_len+len+2, step, boundlen))
                   {
                       isNewFormat = 1;
                       pos = head_end_pos+head_end_len+len+2;
                       /*
                       if (-1 != fd)
                       {
                           char tt[1024];
                           snprintf(tt, 1024, "new file format%s\n", "NULL");
                           write(fd, tt, strlen(tt));
                       }
                       */
                   }
               }
               //close(fd);
            }
            tmp[head_end_pos] = temp;
        }
        if (0 == isNewFormat)
        {
        pos = MYBF(buffer_file+oldpos,  content_length-oldpos, step, boundlen);
        if(-1 == pos)
        {
            int randlen = 2+boundlen+6; //const TCHAR c_szFormCompletionFormat[]  = _T("\r\n--%s--\r\n\r\n");
            if(oldpos+randlen< content_length)//兼容控件225最后一个为unicode分隔符
            {
                char *tmp = buffer_file + content_length - randlen;
                if (tmp[0] != '\r' || tmp[1] != 0 || tmp[2] != '\n' || tmp[3] != 0
                   || tmp[4] != '-' || tmp[5] != 0 || tmp[6] != '-' || tmp[7] != 0)
                {
                    break;
                }
                else
                {
                    pos = content_length-randlen-oldpos+2;
                    buffer_file[oldpos+pos-2]='\r';
                    buffer_file[oldpos+pos-1]='\n';
                    buffer_file[oldpos+pos+boundlen]='-';
                    buffer_file[oldpos+pos+boundlen+1]='-';
                }
            }
            else
            {
                break;
            }
        }
        }
        ParseNameValue(buffer_file+oldpos, pos, entries, &window);
        if (buffer_file[oldpos+pos+boundlen]=='-'&&buffer_file[oldpos+pos+boundlen+1]=='-')
        {
            break;
        }
        else if (buffer_file[oldpos+pos+boundlen]!='\r'||buffer_file[oldpos+pos+boundlen+1]!='\n')
        {
            break;
        }
        oldpos += pos+boundlen+2;
    }
	
	return numentries;
}
开发者ID:qiqisteve,项目名称:Athena,代码行数:101,代码来源:cgi-lib.c


示例9: UPNP_GetGenericPortMappingEntry

int UPNP_GetGenericPortMappingEntry(const char * controlURL,
                                     const char * servicetype,
									 const char * index,
									 char * extPort,
									 char * intClient,
									 char * intPort,
									 char * protocol,
									 char * desc,
									 char * enabled,
									 char * rHost,
									 char * duration)
{
	struct NameValueParserData pdata;
	struct UPNParg * GetPortMappingArgs;
	char buffer[4096];
	int bufsize = 4096;
	char * p;
	int r = -1;
	intClient[0] = '\0';
	intPort[0] = '\0';
	GetPortMappingArgs = calloc(2, sizeof(struct UPNParg));
	GetPortMappingArgs[0].elt = "NewPortMappingIndex";
	GetPortMappingArgs[0].val = index;
	simpleUPnPcommand(-1, controlURL, servicetype,
	                  "GetGenericPortMappingEntry",
					  GetPortMappingArgs, buffer, &bufsize);
	ParseNameValue(buffer, bufsize, &pdata);
	p = GetValueFromNameValueList(&pdata, "NewRemoteHost");
	if(p && rHost)
	{
		strncpy(rHost, p, 64);
		rHost[63] = '\0';
	}
	p = GetValueFromNameValueList(&pdata, "NewExternalPort");
	if(p && extPort)
	{
		strncpy(extPort, p, 6);
		extPort[5] = '\0';
		r = 0;
	}
	p = GetValueFromNameValueList(&pdata, "NewProtocol");
	if(p && protocol)
	{
		strncpy(protocol, p, 4);
		protocol[3] = '\0';
	}
	p = GetValueFromNameValueList(&pdata, "NewInternalClient");
	if(p && intClient)
	{
		strncpy(intClient, p, 16);
		intClient[15] = '\0';
		r = 0;
	}
	p = GetValueFromNameValueList(&pdata, "NewInternalPort");
	if(p && intPort)
	{
		strncpy(intPort, p, 6);
		intPort[5] = '\0';
	}
	p = GetValueFromNameValueList(&pdata, "NewEnabled");
	if(p && enabled)
	{
		strncpy(enabled, p, 4);
		enabled[3] = '\0';
	}
	p = GetValueFromNameValueList(&pdata, "NewPortMappingDescription");
	if(p && desc)
	{
		strncpy(desc, p, 80);
		desc[79] = '\0';
	}
	p = GetValueFromNameValueList(&pdata, "NewLeaseDuration");
	if(p && duration)
	{
		strncpy(duration, p, 16);
		duration[15] = '\0';
	}
	ClearNameValueList(&pdata);
	free(GetPortMappingArgs);
	return r;
}
开发者ID:SupportSpace,项目名称:SupportCenter,代码行数:81,代码来源:upnpcommands.c


示例10: image_get_jpeg_date_xmp

int
image_get_jpeg_date_xmp(const char * path, char ** date)
{
	FILE *img;
	unsigned char buf[8];
	char *data = NULL, *newdata;
	uint16_t offset;
	struct NameValueParserData xml;
	char * exif;
	int ret = 1;
	size_t nread;

	img = fopen(path, "r");
	if( !img )
		return(-1);

	nread = fread(&buf, 2, 1, img);
	if( (nread < 1) || (buf[0] != 0xFF) || (buf[1] != 0xD8) )
	{
		fclose(img);
		return(-1);
	}
	memset(&buf, 0, sizeof(buf));

	while( !feof(img) )
	{
		while( nread > 0 && buf[0] != 0xFF && !feof(img) )
			nread = fread(&buf, 1, 1, img);

		while( nread > 0 && buf[0] == 0xFF && !feof(img) )
			nread = fread(&buf, 1, 1, img);

		if( feof(img) )
			break;

		if( buf[0] == 0xE1 ) // APP1 marker
		{
			offset = 0;
			nread = fread(&buf, 2, 1, img);
			if( nread < 1 )
				break;
			memcpy(&offset, buf, 2);
			offset = SWAP16(offset) - 2;

			if( offset < 30 )
			{
				fseek(img, offset, SEEK_CUR);
				continue;
			}

			newdata = realloc(data, 30);
			if( !newdata )
				break;
			data = newdata;

			nread = fread(data, 29, 1, img);
			if( nread < 1 )
				break;
			offset -= 29;
			if( strcmp(data, "http://ns.adobe.com/xap/1.0/") != 0 )
			{
				fseek(img, offset, SEEK_CUR);
				continue;
			}

			newdata = realloc(data, offset+1);
			if( !newdata )
				break;
			data = newdata;
			nread = fread(data, offset, 1, img);
			if( nread < 1 )
				break;

			ParseNameValue(data, offset, &xml, 0);
			exif = GetValueFromNameValueList(&xml, "DateTimeOriginal");
			if( !exif )
			{
				ClearNameValueList(&xml);
				break;
			}
			*date = realloc(*date, strlen(exif)+1);
			strcpy(*date, exif);
			ClearNameValueList(&xml);

			ret = 0;
			break;
		}
		else
		{
			offset = 0;
			nread = fread(&buf, 2, 1, img);
			if( nread < 1 )
				break;
			memcpy(&offset, buf, 2);
			offset = SWAP16(offset) - 2;
			fseek(img, offset, SEEK_CUR);
		}
	}
	fclose(img);
	free(data);
//.........这里部分代码省略.........
开发者ID:schidler,项目名称:flyzjhz-rt-n56u,代码行数:101,代码来源:image_utils.c


示例11: ParseUPnPClient

void
ParseUPnPClient(char *location)
{
	char buf[8192];
	struct sockaddr_in dest;
	int s, n, do_headers = 0, nread = 0;
	struct timeval tv;
	char *addr, *path, *port_str;
	long port = 80;
	char *off = NULL, *p;
	int content_len = sizeof(buf);
	struct NameValueParserData xml;
	int client;
	enum client_types type = 0;
	uint32_t flags = 0;
	char *model, *serial, *name;

	if (strncmp(location, "http://", 7) != 0)
		return;
	path = location + 7;
	port_str = strsep(&path, "/");
	if (!path)
		return;
	addr = strsep(&port_str, ":");
	if (port_str)
	{
		port = strtol(port_str, NULL, 10);
		if (!port)
			port = 80;
	}

	memset(&dest, '\0', sizeof(dest));
	if (!inet_aton(addr, &dest.sin_addr))
		return;
	/* Check if the client is already in cache */
	dest.sin_family = AF_INET;
	dest.sin_port = htons(port);

	s = socket(PF_INET, SOCK_STREAM, 0);
	if( s < 0 )
		return;

	tv.tv_sec = 0;
	tv.tv_usec = 500000;
	setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
	setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));

	if( connect(s, (struct sockaddr*)&dest, sizeof(struct sockaddr_in)) < 0 )
		goto close;

	n = snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n"
	                               "HOST: %s:%ld\r\n\r\n",
	                               path, addr, port);
	if( write(s, buf, n) < 1 )
		goto close;

	while( (n = read(s, buf+nread, sizeof(buf)-nread-1)) > 0 )
	{
		nread += n;
		buf[nread] = '\0';
		n = nread;
		p = buf;

		while( !off && n-- > 0 )
		{
			if(p[0]=='\r' && p[1]=='\n' && p[2]=='\r' && p[3]=='\n')
			{
				off = p + 4;
				do_headers = 1;
			}
			p++;
		}
		if( !off )
			continue;

		if( do_headers )
		{
			p = buf;
			if( strncmp(p, "HTTP/", 5) != 0 )
				goto close;
			while(*p != ' ' && *p != '\t') p++;
			/* If we don't get a 200 status, ignore it */
			if( strtol(p, NULL, 10) != 200 )
				goto close;
			if( (p = strcasestr(p, "Content-Length:")) )
				content_len = strtol(p+15, NULL, 10);
			do_headers = 0;
		}
		if( buf + nread - off >= content_len )
			break;
	}
close:
	close(s);
	if( !off )
		return;
	nread -= off - buf;
	ParseNameValue(off, nread, &xml);
	model = GetValueFromNameValueList(&xml, "modelName");
	serial = GetValueFromNameValueList(&xml, "serialNumber");
	name = GetValueFromNameValueList(&xml, "friendlyName");
//.........这里部分代码省略.........
开发者ID:Shaaman,项目名称:minidlna,代码行数:101,代码来源:minissdp.c


示例12: parse_nfo

void
parse_nfo(const char *path, metadata_t *m)
{
	FILE *nfo;
	char buf[65536];
	struct NameValueParserData xml;
	struct stat file;
	size_t nread;
	char *val, *val2;

	if( stat(path, &file) != 0 ||
	    file.st_size > 65536 )
	{
		DPRINTF(E_INFO, L_METADATA, "Not parsing very large .nfo file %s\n", path);
		return;
	}
	DPRINTF(E_DEBUG, L_METADATA, "Parsing .nfo file: %s\n", path);
	nfo = fopen(path, "r");
	if( !nfo )
		return;
	nread = fread(&buf, 1, sizeof(buf), nfo);
	
	ParseNameValue(buf, nread, &xml, 0);

	//printf("\ttype: %s\n", GetValueFromNameValueList(&xml, "rootElement"));
	val = GetValueFromNameValueList(&xml, "title");
	if( val )
	{
		char *esc_tag = unescape_tag(val, 1);
		val2 = GetValueFromNameValueList(&xml, "episodetitle");
		if( val2 ) {
			char *esc_tag2 = unescape_tag(val2, 1);
			xasprintf(&m->title, "%s - %s", esc_tag, esc_tag2);
			free(esc_tag2);
		} else {
			m->title = escape_tag(esc_tag, 1);
		}
		free(esc_tag);
	}

	val = GetValueFromNameValueList(&xml, "plot");
	if( val ) {
		char *esc_tag = unescape_tag(val, 1);
		m->comment = escape_tag(esc_tag, 1);
		free(esc_tag);
	}

	val = GetValueFromNameValueList(&xml, "capturedate");
	if( val ) {
		char *esc_tag = unescape_tag(val, 1);
		m->date = escape_tag(esc_tag, 1);
		free(esc_tag);
	}

	val = GetValueFromNameValueList(&xml, "genre");
	if( val )
	{
		free(m->genre);
		char *esc_tag = unescape_tag(val, 1);
		m->genre = escape_tag(esc_tag, 1);
		free(esc_tag);
	}

	val = GetValueFromNameValueList(&xml, "mime");
	if( val )
	{
		free(m->mime);
		char *esc_tag = unescape_tag(val, 1);
		m->mime = escape_tag(esc_tag, 1);
		free(esc_tag);
	}

	ClearNameValueList(&xml);
	fclose(nfo);
}
开发者ID:PterX,项目名称:rt-n56u,代码行数:75,代码来源:metadata.c


示例13: ParseUPnPClient

void
ParseUPnPClient(char *location)
{
	char buf[8192];
	struct sockaddr_in dest;
	int s, n, do_headers = 0, nread = 0;
	struct timeval tv;
	char *addr, *path, *port_str;
	long port = 80;
	char *off = NULL, *p;
	int content_len = sizeof(buf);
	struct NameValueParserData xml;
	int client;
	int type = 0;
	char *model, *serial, *name;

	if (strncmp(location, "http://", 7) != 0)
		return;
	path = location + 7;
	port_str = strsep(&path, "/");
	if (!path)
		return;
	addr = strsep(&port_str, ":");
	if (port_str)
	{
		port = strtol(port_str, NULL, 10);
		if (!port)
			port = 80;
	}

	memset(&dest, '\0', sizeof(dest));
	if (!inet_aton(addr, &dest.sin_addr))
		return;
	/* Check if the client is already in cache */
	dest.sin_family = AF_INET;
	dest.sin_port = htons(port);

	s = socket(PF_INET, SOCK_STREAM, 0);
	if (s < 0)
		return;

	tv.tv_sec = 0;
	tv.tv_usec = 500000;
	setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
	setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));

	if (connect(s, (struct sockaddr*)&dest, sizeof(struct sockaddr_in)) < 0)
		goto close;

	n = snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n"
	                               "HOST: %s:%ld\r\n\r\n",
	                               path, addr, port);
	if (write(s, buf, n) < 1)
		goto close;

	while ((n = read(s, buf+nread, sizeof(buf)-nread-1)) > 0)
	{
		nread += n;
		buf[nread] = '\0';
		n = nread;
		p = buf;

		while (!off && (n-- > 0))
		{
			if (p[0] == '\r' && p[1] == '\n' && p[2] == '\r' && p[3] == '\n')
			{
				off = p + 4;
				do_headers = 1;
			}
			p++;
		}
		if (!off)
			continue;

		if (do_headers)
		{
			p = buf;
			if (strncmp(p, "HTTP/", 5) != 0)
				goto close;
			while (*p != ' ' && *p != '\t')
				p++;
			/* If we don't get a 200 status, ignore it */
			if (strtol(p, NULL, 10) != 200)
				goto close;
			p = strcasestr(p, "Content-Length:");
			if (p)
				content_len = strtol(p+15, NULL, 10);
			do_headers = 0;
		}
		if ((buf + nread - off) >= content_len)
			break;
	}
close:
	close(s);
	if (!off)
		return;
	nread -= off - buf;
	ParseNameValue(off, nread, &xml, 0);
	model = GetValueFromNameValueList(&xml, "modelName");
	serial = GetValueFromNameValueList(&xml, "serialNumber");
//.........这里部分代码省略.........
开发者ID:ashwing920,项目名称:minidlna,代码行数:101,代码来源:minissdp.c


示例14: UPNP_AddPortMapping

LIBSPEC int
UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
                    const char * extPort,
                    const char * inPort,
                    const char * inClient,
                    const char * desc,
                    const char * proto,
                    const char * remoteHost,
                    const char * leaseDuration)
{
    struct UPNParg * AddPortMappingArgs;
    char * buffer;
    int bufsize;
    struct NameValueParserData pdata;
    const char * resVal;
    int ret;

    if(!inPort || !inClient || !proto || !extPort)
        return UPNPCOMMAND_INVALID_ARGS;

    AddPortMappingArgs = calloc(9, sizeof(struct UPNParg));
    AddPortMappingArgs[0].elt = "NewRemoteHost";
    AddPortMappingArgs[0].val = remoteHost;
    AddPortMappingArgs[1].elt = "NewExternalPort";
    AddPortMappingArgs[1].val = extPort;
    AddPortMappingArgs[2].elt = "NewProtocol";
    AddPortMappingArgs[2].val = proto;
    AddPortMappingArgs[3].elt = "NewInternalPort";
    AddPortMappingArgs[3].val = inPort;
    AddPortMappingArgs[4].elt = "NewInternalClient";
    AddPortMappingArgs[4].val = inClient;
    AddPortMappingArgs[5].elt = "NewEnabled";
    AddPortMappingArgs[5].val = "1";
    AddPortMappingArgs[6].elt = "NewPortMappingDescription";
    AddPortMappingArgs[6].val = desc?desc:"libminiupnpc";
    AddPortMappingArgs[7].elt = "NewLeaseDuration";
    AddPortMappingArgs[7].val = leaseDuration?leaseDuration:"0";
    if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
                                    "AddPortMapping", AddPortMappingArgs,
                                    &bufsize))) {
        free(AddPortMappingArgs);
        return UPNPCOMMAND_HTTP_ERROR;
    }
    /*DisplayNameValueList(buffer, bufsize);*/
    /*buffer[bufsize] = '\0';*/
    /*puts(buffer);*/
    ParseNameValue(buffer, bufsize, &pdata);
    free(buffer);
    buffer = NULL;
    resVal = GetValueFromNameValueList(&pdata, "errorCode");
    if(resVal) {
        /*printf("AddPortMapping errorCode = '%s'\n", resVal); */
        ret = UPNPCOMMAND_UNKNOWN_ERROR;
        sscanf(resVal, "%d", &ret);
    } else {
        ret = UPNPCOMMAND_SUCCESS;
    }
    ClearNameValueList(&pdata);
    free(AddPortMappingArgs);
    return ret;
}
开发者ID:wdmchaft,项目名称:Psybrus,代码行数:61,代码来源:upnpcommands.c


示例15: while


//.........这里部分代码省略.........
            packetsSent = UPNP_GetTotalPacketsSent(urls.controlURL_CIF,
                                                   data.CIF.servicetype);

            if ((unsigned int)UPNPCOMMAND_HTTP_ERROR != packetsSent)
            {
                resultHash.insert(TotalPacketsSent, packetsSent);
            }


            packetsReceived = UPNP_GetTotalPacketsReceived(urls.controlURL_CIF,
                                                           data.CIF.servicetype);

            if ((unsigned int)UPNPCOMMAND_HTTP_ERROR != packetsReceived)
            {
                resultHash.insert(TotalPacketsReceived, packetsReceived);
            }


            char status[100];
            unsigned int uptime = 0;
            char lastConnectionError[128];

            if (UPNPCOMMAND_SUCCESS == UPNP_GetStatusInfo(urls.controlURL,
                                                          data.first.servicetype,
                                                          status,
                                                          &uptime,
                                                          lastConnectionError))
            {
                resultHash.insert(Status, status);
                resultHash.insert(Uptime, uptime);
                resultHash.insert(LastConnectionError, lastConnectionError);
            }

            quint32 num;

            if (UPNPCOMMAND_SUCCESS == UPNP_GetPortMappingNumberOfEntries(urls.controlURL,
                                                                          data.first.servicetype,
                                                                          &num))
            {
                resultHash.insert(NumberOfPortMappings, num);
            }

            // TODO GetListOfPortMappings do we need this?

            int firewallEnabled, inboundPinholeAllowed;

            if (UPNPCOMMAND_SUCCESS == UPNP_GetFirewallStatus(urls.controlURL,
                                                              data.first.servicetype,
                                                              &firewallEnabled,
                                                              &inboundPinholeAllowed))
            {
                resultHash.insert(FirewallEnabled, firewallEnabled);
                resultHash.insert(InboundPinholeAllowed, inboundPinholeAllowed);
            }

            int bufferSize = 0;

            if (char *buffer = (char *)miniwget(urls.rootdescURL, &bufferSize, 0))
            {
                NameValueParserData pdata;
                ParseNameValue(buffer, bufferSize, &pdata);
                free(buffer);
                buffer = NULL;

                QStringList modelName = GetValuesFromNameValueList(&pdata, "modelName");

                if (!modelName.isEmpty())
                {
                    resultHash.insert(ModelName, modelName.last());
                }

                QStringList manufacturer = GetValuesFromNameValueList(&pdata, "manufacturer");

                if (!manufacturer.isEmpty())
                {
                    resultHash.insert(Manufacturer, manufacturer.last());
                }

                QStringList friendlyName = GetValuesFromNameValueList(&pdata, "friendlyName");

                if (!friendlyName.isEmpty())
                {
                    resultHash.insert(FriendlyName, friendlyName.last());
                }

                ClearNameValueList(&pdata);
            }
        }

        FreeUPNPUrls(&urls);

        results.append(resultHash);
        devlist = devlist->pNext;
    }

    freeUPNPDevlist(devlistBegin);

    emit finished();
    return true; // TODO return false if something went wrong or if there are no results
}
开发者ID:glwu,项目名称:glimpse_client,代码行数:101,代码来源:upnp.cpp



注:本文中的ParseNameValue函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ParseParameters函数代码示例发布时间:2022-05-30
下一篇:
C++ ParseName函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap