Exemple #1
1
int ewf_fastcgi_accept( void )
{
    if ( FCGI_Accept(  ) < 0 ) {
	return EWF_ERROR;
    }

    return EWF_SUCCESS;
}
int fcgi_accept()
{
#ifdef Q_OS_WIN
  if ( FCGX_IsCGI() )
    return FCGI_Accept();
  else
    return FCGX_Accept( &FCGI_stdin->fcgx_stream, &FCGI_stdout->fcgx_stream, &FCGI_stderr->fcgx_stream, &environ );
#else
  return FCGI_Accept();
#endif
}
Exemple #3
0
static int luafcgi_accept( lua_State * const L ) {
	const int rv = FCGI_Accept();

	lua_pushboolean( L, rv == 0 );

	return 1;
}
Exemple #4
0
int main(int argc, char **argv)
{
    QCoreApplication a(argc, argv);
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    qApp->addLibraryPath(qApp->applicationDirPath());
    google::InitGoogleLogging(argv[0]);
    qInstallMsgHandler(GlogHandler);

    SuggestService service;
    if (!service.init(argc, argv))
        return 1;
    else {
        LOG(INFO) << "SuggestService " << service.version() << " init ok";
    }

    while (FCGI_Accept() >= 0) {
        // Разрешаем заменить строку запроса параметром командной строки
        QString queryString = getenv("QUERY_STRING");
        if (queryString.isEmpty()) {
            for (int i = 1; i < argc; i++)
                if (QString(argv[i]).startsWith("q="))
                    queryString = argv[i];
        }

        QString result = service.processQuery(queryString);

        printf(	"Content-Type: text/html; charset=\"utf-8\"\r\n"
                "\r\n");
        printf("%s", result.toUtf8().data());
    }
}
Exemple #5
0
void http_thread(void *args)
{
    if(!init()) {
        print("http_init() failed\n");
        return;
    }

    while(FCGI_Accept() >= 0)
    {
        FCGI_printf("Content-type: text/html\r\nStatus: 200 OK\r\n\r\n");

        char *name = getenv("SCRIPT_NAME");
        _Bool q = 0;

        if(name[0] == '/' && name[1] == 'q') {
            if(name[2] == 0) {
                q = 1;
            } else if(strcmp(name + 2, "key") == 0) {
                uint8_t k[64];
                key_to_string(k, key.public);
                FCGI_fwrite(k, sizeof(k), 1, FCGI_stdout);
                continue;
            } else if(strcmp(name + 2, "stat") == 0) {
                FCGI_printf("Number of registered names: %u<br/>Number of successful Tox DNS requests: %u\n", stat.registered, stat.requests);
                continue;
            }
        }
Exemple #6
0
int main ()
{
    char **initialEnv = environ;

    g_cgi_cfg = new CCgiCfg("/data/server/cgi-bin/sh/cgi_cfg.txt");

    while (FCGI_Accept() >= 0)
    {
        CIfBase* ifobj = CIfFactory::getIfObj();
        if(ifobj == NULL)
        {
            LogError("error_env_platform", "");
            continue;
        }

        ifobj->SetServName(my_getenv("SERVER_NAME"));
        char* pszReq = my_getenv("QUERY_STRING");
        ifobj->login(pszReq);
        delete ifobj;
    }

    delete (CWorldBase*)g_pTheWorld;

    return 0;
}
int main() {
	Database *db = Database::getInstance();
	Session *session = Session::getInstance();

	while (FCGI_Accept() >= 0) {
		Json::FastWriter fw; 
		Json::Value root;
		string result("fail");
		string detail("");
		session->sessionInit();
		vector<unordered_map<string,string> >   query_result;
		if(session->checkSession() == false){
			detail = detail + "unlogin";

		}else{

			char query_buf[1024] = {0};
			string user_id;
			user_id = session->getValue("user_id");

<<<<<<< HEAD
			snprintf(query_buf,sizeof(query_buf),"select b.no_id, b.type, a.user_id, a.username, b.additional_message, b.created_time from users a INNER JOIN (select * from notification  where rece_id = %d and state = 0) b on a.user_id = b.rece_id union  select b.no_id, b.type, b.send_id, a.username, b.additional_message, b.created_time from users a INNER JOIN (select * from notification  where send_id = %d and state = 1) b on a.user_id = b.send_id",atoi(user_id.c_str()),atoi(user_id.c_str()));
=======
			snprintf(query_buf,sizeof(query_buf),"(SELECT no_id,type,send_id,notification.state,username,nickname,created_time,additional_message FROM notification inner join users on users.user_id=send_id where rece_id=%d and notification.state=0) union (SELECT no_id,type,rece_id as send_id,notification.state,username,nickname,created_time,additional_message FROM notification inner join users on users.user_id=rece_id where send_id=%d and notification.state=1)",atoi(user_id.c_str()),atoi(user_id.c_str()));
>>>>>>> 637973e20ec3876ad1a721cb4a71526d24d68c4f
Exemple #8
0
int main () {
    char * request_uri;

    /* Load the controller .so from this sub directory */
    route_import_controllers("controllers/");

    /* Initialize session system */
    session_init();

    while (FCGI_Accept() >= 0) {
      /* Record start time */
      gettimeofday(&start_time,NULL);

      request_uri = cleanrequest( getenv("REQUEST_URI"));

      /* Initialize session for this request */
      fprintf(stderr, "Request for %s\n", request_uri );

      /* Dispatch the request to the correct controller */
      route_dispatch(request_uri);
      free(request_uri);
     
      /* Calculate total runtime of the operation */
      gettimeofday(&end_time,NULL);
      timeval_diff( &difference_time, &end_time, &start_time );      

      printf("time: %ld.%06ld\n", difference_time.tv_sec, difference_time.tv_usec);

      FCGI_Finish();
    }

    fprintf(stderr, "FF Exiting\n");
    return 0;
}
Exemple #9
0
/*
 * Return an ExceptionReport as specified in OWS 1.1.0 specification
 */
void ows_error(ows * o, enum ows_error_code code, char *message, char *locator)
{
  assert(o);
  assert(message);
  assert(locator);

  assert(!o->exit);
  o->exit = true;

  ows_log(o, 1, message);

#if TINYOWS_FCGI
  if ((o->init && FCGI_Accept() >= 0) || !o->init) {
#endif
    fprintf(o->output, "Content-Type: application/xml\n\n");
    fprintf(o->output, "<?xml version='1.0' encoding='UTF-8'?>\n");
    fprintf(o->output, "<ows:ExceptionReport\n");
    fprintf(o->output, " xmlns='http://www.opengis.net/ows'\n");
    fprintf(o->output, " xmlns:ows='http://www.opengis.net/ows'\n");
    fprintf(o->output, " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n");
    fprintf(o->output, " xsi:schemaLocation='http://www.opengis.net/ows");
    fprintf(o->output, " http://schemas.opengis.net/ows/1.0.0/owsExceptionReport.xsd'\n");
    fprintf(o->output, " version='1.1.0' language='en'>\n");
    fprintf(o->output, " <ows:Exception exceptionCode='%s' locator='%s'>\n",
            ows_error_code_string(code), locator);
    fprintf(o->output, "  <ows:ExceptionText>%s</ows:ExceptionText>\n", message);
    fprintf(o->output, " </ows:Exception>\n");
    fprintf(o->output, "</ows:ExceptionReport>\n");

#if TINYOWS_FCGI
    fflush(o->output);
  }
#endif
}
Exemple #10
0
int main() {
	while (FCGI_Accept() >= 0) {
		printf("Content-type: text\r\n");
		printf("Set-Cookie: name=value with spaces; and a semicolon\r\n");
		printf("Set-Cookie: name2=value2\r\n\r\n");
		printf("Cookie:%s\n", getenv("COOKIE_STRING"));
	}
}
SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap* soap)
{
#ifndef WITH_FASTCGI
    unsigned int k = soap->max_keep_alive;
#endif

    do
    {
#ifdef WITH_FASTCGI
        if (FCGI_Accept() < 0)
        {
            soap->error = SOAP_EOF;
            return soap_send_fault(soap);
        }
#endif

        soap_begin(soap);

#ifndef WITH_FASTCGI
        if (soap->max_keep_alive > 0 && !--k)
            soap->keep_alive = 0;
#endif

        if (soap_begin_recv(soap))
        {
            if (soap->error < SOAP_STOP)
            {
#ifdef WITH_FASTCGI
                soap_send_fault(soap);
#else
                return soap_send_fault(soap);
#endif
            }
            soap_closesock(soap);

            continue;
        }

        if (soap_envelope_begin_in(soap)
                || soap_recv_header(soap)
                || soap_body_begin_in(soap)
                || soap_serve_request(soap)
                || (soap->fserveloop && soap->fserveloop(soap)))
        {
#ifdef WITH_FASTCGI
            soap_send_fault(soap);
#else
            return soap_send_fault(soap);
#endif
        }

#ifdef WITH_FASTCGI
        soap_destroy(soap);
        soap_end(soap);
    }
    while (1);
#else
    } while (soap->keep_alive);
Exemple #12
0
int main(int argc, char *argv)
{
	int count = 0;
	while (FCGI_Accept() >= 0) {
		FCGI_printf("Content-type: text/*\r\n\r\n");
		printf("Hi, I am Zhangpengpeng.\t %d %s \n", count++, getenv("SERVER_NAME"));
	}
	return 0;
}
Exemple #13
0
int main(void){
    pci_init();
#ifdef ENABLE_FASTCGI
    while(FCGI_Accept() >= 0) {
#endif
    qentry_t *req = qcgireq_parse(NULL, 0);
    
    char *name  = req->getstr(req, "username", true);
    if(name == NULL){
        qcgires_redirect(req, BAD_REGISTER);
        goto end;
    }

    char *admin = req->getstr(req, "adminpassword", true);
    if(admin == NULL){
    	qcgires_redirect(req, BAD_REGISTER);
    	free(name);
    	goto end;
    }

    if(strncmp(admin, ADMIN_SECRET, strlen(ADMIN_SECRET)) != 0){
    	fprintf(stderr, "%s%s\n", "Invalid Registration Attempt: ", admin);
    	qcgires_redirect(req, BAD_REGISTER);
    	free(name);
    	free(admin);
    	goto end;
    }

    if( create_user(name) == 1 ){   	
    	/* Log the User in */
    	qentry_t *sess = NULL;
		sess = qcgisess_init(req, NULL);
        qcgisess_settimeout(sess, SESSION_TIME);
		if(sess){
            sess->putstr(sess, "username", name, true);
            qcgisess_save(sess);
            sess->free(sess);            
        } 
        qcgires_redirect(req, APPLICATION);
    }else{
    	fprintf(stderr, "%s%s\n", "Could not create user: "******"text/html");
    // De-allocate memories
    req->free(req);
#ifdef ENABLE_FASTCGI
    }
#endif
    return 0;
}
Exemple #14
0
/********************************************************************
* FUNCTION main
*
* STDIN is input from the HTTP server through FastCGI wrapper 
*   (sent to ncxserver)
* STDOUT is output to the HTTP server (rcvd from ncxserver)
* 
* RETURNS:
*   0 if NO_ERR
*   1 if error connecting or logging into ncxserver
*********************************************************************/
int main (int argc, char **argv, char **envp)
{
    int status = 0;
    yang_api_profile_t  yang_api_profile;

    /* setup global vars used across all requests */
    status = yang_api_init(&yang_api_profile);

    if (status != OK) {
        printf("Content-type: text/html\r\n\r\n"
               "<html><head><title>YANG-API echo</title></head>"
               "<body><h1>YANG-API init failed</h1></body></html>\n");
    }

    /* temp: exit on all errors for now */
    while (status == OK && FCGI_Accept() >= 0) {
#ifdef DEBUG_TRACE
        printf("Content-type: text/html\r\n\r\n"
               "<html><head><title>YANG-API echo</title></head>"
               "<body><h1>YANG-API echo</h1>\n<pre>\n");
        PrintEnv("Request environment", environ);
#endif

        status = save_environment_vars(&yang_api_profile);
        if (status != OK) {
            continue;
        }

        status = setenv("REMOTE_USER", yang_api_profile.username, 0);
        if (status != 0) {
            continue;
        }

#ifdef DEBUG_TRACE
        printf("start invoke netconf-subsystem-pro\n");
#endif

        status = run_subsystem_ex(PROTO_ID_YANGAPI, 3, argc, argv, envp,
                                  read_yangapi_buff, send_yangapi_buff,
                                  yang_api_profile.content_length);
        if (status != OK) {
            continue;
        }

#ifdef DEBUG_TRACE
        printf("\n</pre></body></html>\n");
#endif

        cleanup_request(&yang_api_profile);
    } /* while */

    yang_api_cleanup(&yang_api_profile);

    return status;

}  /* main */
Exemple #15
0
int main(int argc, char **argv)
{
    initialize();

    while (FCGI_Accept() >= 0) {
        handle_request();
    }

    return 0;
}
Exemple #16
0
/*
 * A typical FastCGI main program: Initialize, then loop
 * calling FCGI_Accept and performing the accepted request.
 * Do cleanup operations incrementally between requests.
 */
void main(void)
{
    Initialize();
    while(FCGI_Accept() >= 0) {
        PerformRequest();
        FCGI_Finish();
        GarbageCollectStep();
        ConditionalCheckpoint();
    }
}
Exemple #17
0
static void fcgiwrap_main(void)
{
	signal(SIGCHLD, SIG_IGN);
	signal(SIGPIPE, SIG_IGN);

	inherited_environ = environ;

	while (FCGI_Accept() >= 0) {
		handle_fcgi_request();
	}
}
Exemple #18
0
int main(void)
{

 while(FCGI_Accept() >= 0)
 {
  printf("Content-type: text/html\r\nStatus: 200 OK\r\n\r\n");

 }

  return 0;
}
int dpws_discoveryService::serve()
{
#ifndef WITH_FASTCGI
	unsigned int k = this->max_keep_alive;
#endif
	do
	{	soap_begin(this);
#ifdef WITH_FASTCGI
		if (FCGI_Accept() < 0)
		{
			this->error = SOAP_EOF;
			return soap_send_fault(this);
		}
#endif

		soap_begin(this);

#ifndef WITH_FASTCGI
		if (this->max_keep_alive > 0 && !--k)
			this->keep_alive = 0;
#endif

		if (soap_begin_recv(this))
		{	if (this->error < SOAP_STOP)
			{
#ifdef WITH_FASTCGI
				soap_send_fault(this);
#else 
				return soap_send_fault(this);
#endif
			}
			soap_closesock(this);

			continue;
		}

		if (soap_envelope_begin_in(this)
		 || soap_recv_header(this)
		 || soap_body_begin_in(this)
		 || dispatch() || (this->fserveloop && this->fserveloop(this)))
		{
#ifdef WITH_FASTCGI
			soap_send_fault(this);
#else
			return soap_send_fault(this);
#endif
		}

#ifdef WITH_FASTCGI
		soap_destroy(this);
		soap_end(this);
	} while (1);
#else
	} while (this->keep_alive);
Exemple #20
0
int main(void)
{
#ifdef ENABLE_FASTCGI
    while(FCGI_Accept() >= 0) {
#endif
    qentry_t *req = qcgireq_parse(NULL, 0);

    // fetch queries
    time_t expire = (time_t)req->getint(req, "expire");
    char *mode  = req->getstr(req, "mode", false);
    char *name  = req->getstr(req, "name", false);
    char *value = req->getstr(req, "value", false);

    // start session.
    qentry_t *sess = qcgisess_init(req, NULL);

    // Mose case, you don't need to set timeout. this is just example
    if (expire > 0) qcgisess_settimeout(sess, expire);

    if (mode) {
        switch (mode[0]) {
            case 's': // set
                req->putstr(sess, name, value, true);
                break;
            case 'r': // remove
                req->remove(sess, name);
                break;
            case 'd': // destroy
                qcgisess_destroy(sess);
                qcgires_setcontenttype(req, "text/plain");
                printf("Session destroyed.\n");
#ifdef ENABLE_FASTCGI
                continue;
#else
                return 0;
#endif
            case 'v': // view
            default:
                break;
        }
    }
    // screen out
    qcgires_setcontenttype(req, "text/plain");
    req->print(sess, stdout, true);

    // save session & free allocated memories
    qcgisess_save(sess);
    sess->free(sess);
    req->free(req);
#ifdef ENABLE_FASTCGI
    }
#endif
    return 0;
}
Exemple #21
0
int main (){
    while (FCGI_Accept() >= 0) {
        printf("Content-type: text/html;charset=utf-8\r\n");

        cgiInit();
        
        run();

        destory();
    }
    return 0;
}
Exemple #22
0
void main(void)
{
    int count = 0;
    while(FCGI_Accept() >= 0) {
        printf("Content-type: text/html\r\n"
               "\r\n"
               "<title>FastCGI Hello! (C, fcgi_stdio library)</title>"
               "<h1>FastCGI Hello! (C, fcgi_stdio library)</h1>"
               "Request number %d running on host <i>%s</i>\n",
               ++count, getenv("SERVER_NAME"));
    }
}
Exemple #23
0
int main(void)
{
  
  while(FCGI_Accept() >= 0) {
    char *query = getenv("QUERY_STRING");
    char *root = getenv("DOCUMENT_ROOT");
    char *script = getenv("SCRIPT_NAME");
    char *request = getenv("REQUEST_URI");
    printf("Content-type: text/html\r\nStatus: 200 OK\r\n\r\n");
    printf("<pre>");
    printf("query:%s\ndoc_root:%s\nscript:%s\nrequest_uri:%s", query, root, script, request);
  }

  return 0;
}
Exemple #24
0
int main(int argc, char **argv)
{

	if (initiate(argv[0]) == -1)
		return -1;

	if (connect_2_analyze_server(&analyze_fd) == -1)
		analyze_broken = 1;
	else
		analyze_broken = 0;
	connect_2_backup_server(&backup_fd);

	store_result_t result;
	while( FCGI_Accept() >= 0) {
		//用cgic初始化获取post数据
		cgic_initiate(0, 0);
		FCGI_printf("Content-type:image/gif\r\n\r\n");
		//判断数据合法性,如合法则放入result中
		if( prepare_data(&result) == -1)
			goto continue_tag;

		//先发到缓存
		if (backup_fd == -1)
			connect_2_backup_server(&backup_fd);//重新连接
		if (backup_fd != -1)
			send_2_server(&result, &backup_fd, "backup", analyze_broken);


		//将数据发送出去
		if (analyze_fd == -1) {
			if (connect_2_analyze_server(&analyze_fd) == -1)//重新连接
				analyze_broken = 1;
			else
				analyze_broken = 0;
		}
		if(analyze_fd != -1)
			send_2_server(&result, &analyze_fd, "analyze", 0);

continue_tag:
		//释放cgic中取数据所分配的内存
		cgiFreeResources();
		FCGI_Finish();
	}
	close(analyze_fd);
	close(backup_fd);
	destroy();
	return 1;
}
Exemple #25
0
int main(void)
{   
    int count = 0;
    char url[MAX_URL_SIZE];
    while(FCGI_Accept() >= 0) {
		printf("Content-type: text/html\r\n"
           "\r\n"
           "<title>CGI Hello!</title>"
           "<h1>CGI Hello!</h1>"
           "Request number %d running on host <i>%s</i>.\n<br/>",
           ++count, getenv("SERVER_NAME"));
        strcpy(url, getenv("REQUEST_URI"));
        printf("The request URI is: %s.\n<br/>", url);
	}
    return 0;
}
Exemple #26
0
int main (int argc, char *argv[])
{
    char *query_string, *method, *len = 0x0;
    int count = 0;
    int i, ilen = 0;

    while (FCGI_Accept() >= 0)
    {
        printf("Content-type: text/html\r\n"
               "\r\n"
               "<title>FastCGI Hello!</title>"
               "<h1>FastCGI Hello!</h1>"
               "Request number %d running on host <i>%s</i>\n",
               ++count, getenv("SERVER_NAME"));

        printf("<p>If you have configured fastcgi correctly, then "
               "the request number should increment every time you "
               "hit reload on your browser.  You should also see "
               "\"%s\" (the name of this program) showing up in ps ax.\n",
               argv[0]);

        query_string = getenv ("QUERY_STRING");
        printf ("<p>The QUERY_STRING environment vairable is %s\n"
                "The other environment variables are:<p>", query_string);

        for (i = 0; environ[i]; i++)
        {
            printf ("<br>%s\n", environ[i]);
        }

        method = getenv ("REQUEST_METHOD");
        if (!strcmp (method, "POST"))
        {
            char * bufp;
            ilen = atoi (getenv ("CONTENT_LENGTH"));
            printf ("<P>This is a method=post request, "
                    "with content length=%d<P>\n", ilen);
            bufp = (char *) malloc (ilen);
            fread (bufp, ilen, 1, stdin);

            printf ("The POST data is<P>%s\n", bufp);
            free (bufp);
        }

    }
    return 0;
}
Exemple #27
0
int main(int argc, char* argv[]) {
	int count = 0;
	
	while (FCGI_Accept() >= 0) {
		printf(
			"Content-type: text/html\r\n"
			"\r\n"
			"<title>FastCGI Hello! (C, fcgi_stdio library)</title>\n"
			"<h1>FastCGI Hello! (C, fcgi_stdio library)</h1>\n"
			"Query: <i>%s</i>\r\n"
			"Request number %d running on host <i>%s</i>\n",
			getenv("QUERY_STRING"), ++count, getenv("SERVER_HOSTNAME")
		);
	};

	return 0;
}
Exemple #28
0
int main ()
{
    char **initialEnv = environ;
    int count = 0;

    while (FCGI_Accept() >= 0) {
        char *contentLength = getenv("CONTENT_LENGTH");
        int len;

	printf("Content-type: text/html\r\n"
	    "\r\n"
	    "<title>FastCGI echo</title>"
	    "<h1>FastCGI echo</h1>\n"
            "Request number %d,  Process ID: %d<p>\n", ++count, getpid());

        if (contentLength != NULL) {
            len = strtol(contentLength, NULL, 10);
        }
        else {
            len = 0;
        }

        if (len <= 0) {
	    printf("No data from standard input.<p>\n");
        }
        else {
            int i, ch;

	    printf("Standard input:<br>\n<pre>\n");
            for (i = 0; i < len; i++) {
                if ((ch = getchar()) < 0) {
                    printf("Error: Not enough bytes received on standard input<p>\n");
                    break;
		}
                putchar(ch);
            }
            printf("\n</pre><p>\n");
        }

        //PrintEnv("Request environment", environ);
        //PrintEnv("Initial environment", initialEnv);
    } /* while */

    return 0;
}
Exemple #29
0
int main(int argc, char * argv[])
{
    func p = wmain1;
    if (argc == 1) 
    {
       WebSession s("24", false);
        s.start(p);
        return 1;
    }
    else
    {
        FCGI_Accept();
        WebSession s("DEBUG", true);
        s.start(p);
        return 1;
    }

    return 0;
}
Exemple #30
0
int main(void)
{
    char *user, *password;

    user = getenv("USER");
    if (user == NULL) {
        user = "******";
    }

    password = getenv("PASSWORD");
    if (password == NULL) {
        password = "******";
    }
	FCGX_Init();
	FCGX_OpenSocket(":9000", 500);
    while (FCGI_Accept() >= 0) {
        char *remoteUser, *remotePassword;

        remoteUser = getenv("REMOTE_USER");
        remotePassword = getenv("REMOTE_PASSWD");
        if ((remoteUser == NULL) || (remotePassword == NULL)
             || strcmp(remoteUser, user) || strcmp(remotePassword, password))
        {
             printf("Status: 401 Unauthorized\r\n"
                 "WWW-Authenticate: Basic realm=\"Test\"\r\n"
                 "\r\n");
        }
        else {
            char *processId = getenv("QUERY_STRING");
            if (processId == NULL || strlen(processId) == 0) {
                processId = "0";
        }
            printf("Status: 200 OK\r\n"
                "Variable-AUTH_TYPE: Basic\r\n"
                "Variable-REMOTE_PASSWD:\r\n"
                "Variable-PROCESS_ID: %s\r\n"
                "\r\n", processId);
        }
    }

    return 0;
}