Копал по инету в находке готового решения, вот нашел вроде неплохой вариант, может кому пригодится.
http://site/cgi-bin/prog.cgi?name=myName&action=Vse+chto+vam+ugodno------------------------
main.cpp
#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
#include "parse.h"
int main()
{
char *query_str = getenv("QUERY_STRING");
Parse list( query_str );
cout << "Content-Type: text/plain; charset=utf-8" << endl << endl;
cout << "name = " << list.get_item_n( "name" ) << endl;
cout << "action= " << list.get_item_n( "action" ) << endl;
}
----- class Parse -----
parse.h
#ifndef CLASS_PARSE
#define CLASS_PARSE
class Parse
{
public:
Parse( char [] );
~Parse();
void set( char [] );
char *get_item( char [], int pos=1, bool=false );
char *get_item_n( char [], int pos=1, bool=false );
protected:
void remove_escape(char []); // Символов Газа избежать
int hex( char ); // Возвратное значение hex
char *map_uname( char [] ); // процесс ~uname -> home path
private:
enum { SEP = '&' }; // Сепаратор для полей
char *the_str; // Строка разбора
int the_length; // Длина строки
};
#endif
parse.cpp
#ifndef CLASS_PARSE_IMP
#define CLASS_PARSE_IMP
#include "parse.h"
#include <string.h>
#include <ctype.h>
#ifndef NO_MAP
# include <pwd.h>
#endif
Parse::Parse( char list[] )
{
the_str = NULL;
set( list );
}
Parse::~Parse()
{
if ( the_str != NULL ) { // Выпуск хранения
delete [] the_str;
}
}
void Parse::set( char list[] )
{
if ( the_str != NULL ) { // Выпуск хранения
delete [] the_str;
}
the_length = strlen( list ); // Длина строки
the_str = new char[the_length+1]; // Выделить область
strcpy( the_str, list ); // копию
}
char *Parse::get_item( char name[], int pos, bool file )
{
int len = strlen( name );
int cur_tag = 1;
for( int i=0; i<the_length-len; i++ )
{
if ( the_str[i] == name[0] &&
strncmp( &the_str[i], name, len ) == 0 )
{
if ( the_str[i+len] == '=' )
{
if ( cur_tag == pos )
{
int start = i+len+1; int j = start;
while ( the_str[j] != SEP && the_str[j] != '\0' ) j++;
int str_len = j-start;
char *mes = new char[ str_len+1 ];
strncpy( mes, &the_str[start], str_len );
mes[str_len] = '\0';
remove_escape( mes );
# ifndef NO_MAP
return file ? map_uname(mes) : mes;
# else
return file ? mes : mes;
# endif
} else {
cur_tag++;
}
}
}
}
return NULL;
}
char *Parse::get_item_n( char name[], int pos, bool file )
{
char *res = get_item( name, pos, file );
return res == NULL ? (char*)"----" : res;
}
void Parse::remove_escape(char str[])
{
char * from = &str[0];
char * to = &str[0];
while ( *from != '\0' )
{
char ch = *from++;
switch ( ch )
{
case '%' :
ch = (hex(*from++)<<4) | hex(*from++);
break;
case '+' :
ch = ' '; break;
}
*to++ = ch;
}
*to = '\0';
}
int Parse::hex( char c )
{
if ( isdigit( c ) )
return c-'0';
if ( isalpha( c ) )
return tolower(c)-'a'+10;
return 0;
}
char* Parse::map_uname( char *path )
{
#ifndef NO_MAP
if ( path[0] == '~' )
{
char uname[255]; // Постановил имя пользователя
char *rest = &path[1]; // # пропускать ~
char *p = &uname[0]; // # пользователь
while ( *rest != '/' && *rest != '\0' )
{
*p++ = *rest++;
}
*p = '\0'; // Терминатор
char *root = uname; // Если не удается
passwd *pw = getpwnam( uname ); // Структура о пользователе
if ( pw != NULL )
{
root = pw->pw_dir; // Домашнем каталоге пользователя
}
int len_root = strlen(root);
int len_path = len_root + strlen(rest);
char *new_path = new char[len_path+1]; // Динамические строки
strcpy( &new_path[0], root ); // abs пользователю путь
strcpy( &new_path[len_root], rest ); // остаток
return new_path;
} else {
return path;
}
#endif
return path;
}
#endif
Взято
отсюда