示例#1
0
/*
	TESTED
	short and long option return :-?
*/
Public _PI(char,getopt)( int c,const char**list,const char *optlist) {
    char ret=NULL,count=0,len=strlen(optlist);
    if( pos<c ) {
        if( *list[pos]=='-' ) {
            if( *(list[pos]+1)=='-' ) {
                ret='-';
                char epos=0,*pt2=(char*)(list[pos]+2);
                poopt=list[pos];
                if( !strChar(list[pos],'=') ) {
                    epos=posChar(pt2,'=');
                    pval=strcpy(val_buf,pt2+epos-- );             //
                } else {
                    epos=strlen(pt2);
                    pval=NULL;
                }
                popt=strncpy(opt_buf,pt2,epos);
                pos++;
                return ret;
            }
            else
            {
                char countshort=strlen(list[pos]+1);
                poopt=list[pos];
                if( !strChar(list[pos],'=' ) ) {
                    ret='-';
                    popt=strncpy
                         (opt_buf,list[pos]+1,
                          posChar(list[pos],'=')-2);
                    pval=strcpy
                         (val_buf,list[pos]+posChar(list[pos],'=') );
                    pos++;
                } else {
                    if(!strChar(optlist,*(list[pos]+elem)))
                        ret=*(list[pos]+elem);
                    else {
                        ret='?';
                        popt=list[pos]+elem;
                    }
                    if( elem>=countshort ) {
                        pos++;
                        elem=1;
                    }
                    else elem++;
                }
                return ret;
            }
        } else {
            popt=strcpy(opt_buf,list[pos++]);
            return ':';
        }
    }
    return NULL;
}
示例#2
0
/* TESTED
	check size of string value if zero return no
*/
Public _PI(char, OpthasValue)( void ) {
    if( !strChar(poopt,'=') ) {
        int size=strlen(poopt+posChar(poopt,'='));
        if( size!=0 )	return YES;
    }
    pval=NULL;
    return NO;
}
示例#3
0
void HTTPServerRequest::addParams(const std::string &params)
{
	std::vector<std::string> items;
	split(params, items, "&");
	
	std::vector<std::string>::iterator it = items.begin();
	std::vector<std::string>::iterator itEnd = items.end();
	for (; it != itEnd; ++it)
	{
		const std::string &item = *it;
		
		int sep = item.find("=");
		if (sep != -1)
		{
			std::string name = item.substr(0, sep);
			std::string value = item.substr(sep + 1);
			
			// convert hex encoding strings to native strings
			
			int nHex = 0;
			while ((nHex = value.find("%", nHex)) != -1)
			{
				std::string strHex = "0x" + value.substr(nHex + 1, 2);
				char cChar = static_cast<char>(strtol(strHex.c_str(), 0, 16));
				char szTemp[2];
				memset(szTemp, 0, 2);
				sprintf(szTemp, "%c", cChar);
				std::string strChar(szTemp);
				
				value.replace(nHex, 3, strChar);
			}

			// + to spaces

			int nSpace = 0;
			while ((nSpace = value.find("+", nSpace)) != -1)
			{
				value.replace(nSpace, 1, " ");
			}
			
			if (!name.empty() && !value.empty())
			{
				m_aParams[name] = value;
			}
		}
	}
}