コード例 #1
0
ファイル: main.c プロジェクト: adamsch1/ff
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;
}
コード例 #2
0
ファイル: main.c プロジェクト: TVilaboa/InvestigacionC
/*
 * 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();
    }
}
コード例 #3
0
ファイル: bbserr.c プロジェクト: caidongyun/fbbs
/**
 * Print HTTP error message with status code set.
 * @param status HTTP status code
 * @param prompt description of the error
 * @return 0
 */
static int http_fatal2(int status, const char *prompt)
{
	printf("Content-type: text/html; charset=%s\nStatus: %d\n\n",
			CHARSET, status);
	//% printf("<html><head><title>发生错误</title></head><body><div>%s</div>"
	printf("<html><head><title>\xb7\xa2\xc9\xfa\xb4\xed\xce\xf3</title></head><body><div>%s</div>"
			//% "<a href=javascript:history.go(-1)>快速返回</a></body></html>",
			"<a href=javascript:history.go(-1)>\xbf\xec\xcb\xd9\xb7\xb5\xbb\xd8</a></body></html>",
			prompt);
	FCGI_Finish();
	return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: Zhanyin/taomee
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;
}
コード例 #5
0
ファイル: hello3.c プロジェクト: nizarklai/gnucash-1
int
main (int argc, char *argv[])
{
    int err, fake_argc = 1;
    char * fake_argv[] = {"hello", 0};
    QofBook *book;
    Account *root;
    char *bufp;
    int rc, sz;

    /* intitialize the engine */
    gnc_engine_init (fake_argc, fake_argv);

    /* contact the database, which is a flat file for this demo */
    book = qof_book_new ();

    rc = gnc_book_begin (book, "file:/tmp/demo.gnucash", FALSE);
    if (!rc) goto bookerrexit;

    rc = gnc_book_load (book);
    if (!rc) goto bookerrexit;

    /* the root pointer points to our local cache of the data */
    root = gnc_book_get_root_account (book);

    /* --------------------------------------------------- */
    /* done with initialization, go into event loop */

    while (FCGI_Accept() >= 0)
    {
        GList *split_list;
        Query *q = NULL;
        char *request_method;
        int read_len = 0;

        /* get the request method */
        request_method = getenv ("REQUEST_METHOD");

        /* Lets pretend that method=get means user has logged
         * in.  Send the user the accounts and currencies,
         * but not the transactions/splits. */
        if (!strcmp ("GET", request_method))
        {
            gncxml_write_account_tree_to_buf(root, &bufp, &sz);

            /* print the HTTP header */
            printf("Content-type: text/gnc-xml\r\n"
                   "Content-Length: %d\r\n"
                   "\r\n", sz);

            /* send the xml to the client */
            printf ("%s", bufp);
            free (bufp);

            /* wait for the next request */
            continue;
        }


        if (!strcmp ("POST", request_method))
        {
            char * content_length = getenv("CONTENT_LENGTH");
            read_len = atoi (content_length);

            /* read 'read_len' bytes from stdin ... */
            bufp = (char *) malloc (read_len);
            fread (bufp, read_len, 1, stdin);

            /* conver the xml input into a gnucash query structure... */
            q = gncxml_read_query (bufp, read_len);
            xaccQuerySetGroup (q, root);

            /* hack -- limit to 30 splits ... */
            xaccQuerySetMaxSplits (q, 30);
            split_list = xaccQueryGetSplits (q);

            xaccFreeQuery (q);

            /* wait for the next request */
            continue;
        }

        /* if we got to here, an error -- unknown method */
        printf("Content-type: text/plain\r\n"
               "\r\n"
               "unknown request type \n");


    }

bookerrexit:

    err = gnc_book_get_error (book);

    /* 500 Server Error */
    FCGI_SetExitStatus (500);

    printf("Content-type: text/plain\r\n\r\n"
           "error was %s\n", strerror (err));

    FCGI_Finish();

    /* close the book */
    qof_book_destroy (book);

    /* shut down the engine */
    gnc_engine_shutdown ();

    sleep (1);

    return 0;
}
コード例 #6
0
ファイル: fastcgi_wrappers.c プロジェクト: JoshCheek/clisp
void fcgi_finish_wrapper() {
  FCGI_Finish();
}
コード例 #7
0
ファイル: gnc-server.c プロジェクト: cstim/gnucash-svn
int
main (int argc, char *argv[])
{
    int err, fake_argc = 1;
    char * fake_argv[] = {"hello", 0};
    QofBook *book;
    Account *root;
    char *request_bufp, *reply_bufp;
    int rc, sz;

    /* intitialize the engine */
    gnc_engine_init (fake_argc, fake_argv);

    /* contact the database, which is a flat file for this demo */
    /* this should really be an SQL server */
    book = qof_book_new ();

    rc = gnc_book_begin (book, "file:/tmp/demo.xac", FALSE);
    if (!rc) goto bookerrexit;

    rc = gnc_book_load (book);
    if (!rc) goto bookerrexit;

    /* the root pointer points to our local cache of the data */
    root = gnc_book_get_root_account (book);

    /* --------------------------------------------------- */
    /* done with initialization, go into event loop */

    while (FCGI_Accept() >= 0)
    {
        GList *split_list;
        Query *q = NULL;
        const char *request_method;
        const char *user_agent;
        const char *auth_string;
        const char *content_length;
        int read_len = 0;
        int send_accts = 0;

        /* get the user agent; reject if wrong agent */
        user_agent = getenv ("HTTP_USER_AGENT");
        if (strncmp ("gnucash", user_agent, 7))
        {
            reject_user_agent (user_agent);
            continue;
        }

        /* get the request method */
        request_method = getenv ("REQUEST_METHOD");
        if (strcmp ("POST", request_method))
        {
            /* method=post is the only spported method*/
            reject_method(request_method);
            continue;
        }

        /* ----------------------------------------------- */
        /* look for an authentication cookie */
        auth_string = find_cookie ("gnc-server");

        /* found the cookie, lets make sure that it is valid */
        if (auth_string)
        {
            gboolean valid_session;
            valid_session = have_session (auth_string);
            if (!valid_session)
            {

                /* XXX invalid sessions are a sign of hacking;
                 * this event should be noted in a security log
                 * and the server admin contacted.
                 */
                reject_session (auth_string);
                continue;
            }
        }

        /* go ahead and read the message body.
         * we'll need this soon enough */
        content_length = getenv("CONTENT_LENGTH");
        read_len = atoi (content_length);

        /* read 'read_len' bytes from stdin ... */
        request_bufp = (char *) g_malloc (read_len);
        fread (request_bufp, read_len, 1, stdin);

        /* if no previously authenticated session,
         * authenticate now */
        if (!auth_string)
        {
            char *name = NULL, *passwd = NULL;
            parse_for_login (request_bufp, &name, &passwd);

            auth_string = auth_user (name, passwd);
            if (!auth_string)
            {
                reject_auth();
                g_free (request_bufp);
                continue;
            }
            send_accts = 1;
        }

        /* ----------------------------------------------- */
        /* send only the accounts to the user */
        if (send_accts)
        {
            /* print the HTTP header */
            printf("Content-type: text/gnc-xml\r\n"
                   "Set-Cookie: %s\r\n"
                   "Content-Length: %d\r\n"
                   "\r\n",
                   auth_string, sz);

            /* since this is the first time the user is logging
             * in, send them the full set of accounts.
             * (Do not send them any transactions yet).
             */
            gncxml_write_account_tree_to_buf(root, &reply_bufp, &sz);

            /* send the xml to the client */
            printf ("%s", reply_bufp);
            g_free (request_bufp);

            /* wait for the next request */
            continue;
        }

        /* ----------------------------------------------- */
        /* If we got to here, then the ser should be sending
         * us a query xml.
         * we should somehow error check that what we got
         * is really a valid query
         */

        /* conver the xml input into a gnucash query structure... */
        q = gncxml_read_query (request_bufp, read_len);
        xaccQuerySetGroup (q, root);

        /* hack -- limit to 30 splits ... */
        xaccQuerySetMaxSplits (q, 30);
        split_list = xaccQueryGetSplits (q);

        /* poke those splits into an ccount group structure */
        /* XXX not implemented */

        /* send the account group structure back to the user */
        /* XXX not implemented */

        xaccFreeQuery (q);
        g_free (request_bufp);

    }

bookerrexit:

    err = gnc_book_get_error (book);

    /* 500 Server Error */
    FCGI_SetExitStatus (500);

    printf("Content-type: text/plain\r\n\r\n"
           "error was %s\n", strerror (err));

    FCGI_Finish();

    /* close the book */
    qof_book_destroy (book);

    /* shut down the engine */
    gnc_engine_shutdown ();

    sleep (1);

    /* must return a non-zero error code, otherwise fastcgi
     * attempts to respawn this daemon. */
    return 500;
}