Esempio n. 1
0
void Convertor::run()
{
    while(std::getline(mInput,mTempLine))
    {
        initializeNewLoop();

        if(commentTesterOpen())
        {
            commentTesterClose();
            continue;
        }

        if(firstCheck())
            continue;
		if(handleNamespace())
	    	continue;
        if(handleStruct())
            continue;
        if(cutLine())
            continue;
        if(secondCheck())
            continue;
        handlePost();
        if(mType == Type::None)
            handleCtor();
        if(mType == Type::None)
            handleDtor();
        if(mType == Type::None)
            handleVoid();
        if(mType == Type::None)
            mType = Type::Return;

        write();
    }
}
Esempio n. 2
0
void *Service_Request(void *f) {

	int conn = (intptr_t)f;
    FILE *resource;
	struct ReqInfo  reqinfo;

    InitReqInfo(&reqinfo);
    
    /*  Get HTTP request  */
    if ( Get_Request(conn, &reqinfo) < 0 ) printf("error");
	//return -1;


	if (reqinfo.method == POST){
		handlePost(conn,&reqinfo);
	}
	if (strlen(reqinfo.resource) == 1) sprintf(reqinfo.resource,"/index.html");

/*  Check whether resource exists, whether we have permission
	to access it, and update status code accordingly.          */
	if ( reqinfo.status == 200 ){
		if ( (resource = Check_Resource(&reqinfo)) < 0 ) {
			if ( errno == EACCES )
			reqinfo.status = 401;
			else
			reqinfo.status = 404;
		}
	}
    /*  Output HTTP response headers if we have a full request  */

    if ( reqinfo.type == FULL )
	Output_HTTP_Headers(conn, &reqinfo);
    /*  Service the HTTP request  */
    if ( reqinfo.status == 200 ) {
		if ( Return_Resource(conn, resource, &reqinfo) ) syslog(LOG_NOTICE,"Something wrong returning resource.");
    }
    else Return_Error_Msg(conn, &reqinfo);

    if ( resource > 0 )
	if ( fclose(resource) < 0 ) syslog(LOG_NOTICE,"Error closing resource.");
    FreeReqInfo(&reqinfo);
	close(conn);
}
Esempio n. 3
0
        void handleRESTRequest( const char *rq, // the full request
                                string url,
                                string& responseMsg,
                                int& responseCode,
                                vector<string>& headers // if completely empty, content-type: text/html will be added
                              ) {

            string::size_type first = url.find( "/" , 1 );
            if ( first == string::npos ) {
                responseCode = 400;
                return;
            }

            string method = parseMethod( rq );
            string dbname = url.substr( 1 , first - 1 );
            string coll = url.substr( first + 1 );
            string action = "";

            map<string,string> params;
            if ( coll.find( "?" ) != string::npos ) {
                parseParams( params , coll.substr( coll.find( "?" ) + 1 ) );
                coll = coll.substr( 0 , coll.find( "?" ) );
            }

            string::size_type last = coll.find_last_of( "/" );
            if ( last == string::npos ) {
                action = coll;
                coll = "_defaultCollection";
            }
            else {
                action = coll.substr( last + 1 );
                coll = coll.substr( 0 , last );
            }

            for ( string::size_type i=0; i<coll.size(); i++ )
                if ( coll[i] == '/' )
                    coll[i] = '.';

            string fullns = dbname + "." + coll;

            headers.push_back( (string)"x-action: " + action );
            headers.push_back( (string)"x-ns: " + fullns );
            headers.push_back( "Content-Type: text/plain;charset=utf-8" );

            stringstream ss;

            if ( method == "GET" ) {
                responseCode = 200;
                handleRESTQuery( fullns , action , params , responseCode , ss  );
            }
            else if ( method == "POST" ) {
                responseCode = 201;
                handlePost( fullns , body( rq ) , params , responseCode , ss  );
            }
            else {
                responseCode = 400;
                headers.push_back( "X_err: bad request" );
                ss << "don't know how to handle a [" << method << "]";
                out() << "don't know how to handle a [" << method << "]" << endl;
            }

            responseMsg = ss.str();
        }