예제 #1
0
파일: bfc.c 프로젝트: jx2zhou/bfc
int main(int argc, char* argv[]) {
    // Check arguments
    if (argc != 2)
        usage();

    // Open source (pun)
    FILE* source = fopen(argv[1], "r");
    if (source == NULL)
        error_404(argv[1]);

    // Initialize register
    for (int i = 0; i < SIZE; i++)
        reg[i] = DEFAULT;

    process(source);

    // Close source, exit
    fclose(source);
    return 0;
}
예제 #2
0
void BasicHttpRequest::req_GET() {
    // not found
    error_404();
}
예제 #3
0
int
cgiMain ()
{




    bzero (&main_dir, BLOCK - 1);
    strcpy (main_dir, "/www/default/foto_content");
    char query[BLOCK];




    //cgiWriteEnvironment("capcgi.dat");

    bzero (&dir, BLOCK - 1);
    bzero (&title, BLOCK - 1);


    if (strstr (cgiQueryString, "ajax")) {

        char *ptr = strstr (cgiQueryString, "&dir");
        char dirQ[BLOCK];
        char username[BLOCK];
        char message[BLOCK];
        char *ptr2;
        bzero (&dirQ, BLOCK);
        bzero (&username, BLOCK);
        bzero (&message, BLOCK);
        ptr += 5;
        ptr2 = strstr (ptr, "&");


        if (ptr2 == NULL) {
            strcpy (dirQ, ptr);
        }
        else if (ptr2 - ptr < BLOCK) {
            strncpy (dirQ, ptr, ptr2 - ptr);
        }
        else {
            error_404 ();
            return 0;
        }

        if(!checksafe(query)) {
            error_404();
            return 0;
        }

        bzero (&query, BLOCK - 1);

        if (!cgiFormString ("call", query, BLOCK - 1)
                && !strcmp (query, "print")) {

            struct stat buf;
            bzero (&buf, sizeof (struct stat));
            char path[BLOCK];
            bzero (&path, BLOCK);
            snprintf (path, BLOCK - 1, "%s/%s", main_dir, dirQ);
            stat (path, &buf);
            if (S_ISREG (buf.st_mode) || !strcmp (dirQ, "")) {
                printf ("Content-Type: text/plain; charset=windows-1251\n");
                printf ("A-Powered-Via: QTP 1.4.4\n\n");
                strcpy (dir, path);
                snprintf (path, BLOCK - 1, "%s/%s.txt", main_dir, dirQ);
                printGB (path);
                //print_env();
            }
            else {
                error_404 ();
                return 0;
            }
        }
        else if (!cgiFormString ("call", query, BLOCK - 1)
                 && !strcmp (query, "add")
                 && !cgiFormString ("gb_name", username, BLOCK - 1)
                 && !cgiFormString ("gb_text", message, BLOCK - 1)) {

            struct stat buf;
            bzero (&buf, sizeof (struct stat));
            char path[BLOCK];
            bzero (&path, BLOCK);
            snprintf (path, BLOCK - 1, "%s/%s", main_dir, dirQ);
            stat (path, &buf);
            if (S_ISREG (buf.st_mode) || !strcmp (dirQ, "")) {
                printf ("Content-Type: text/plain; charset=windows-1251\n");
                printf ("A-Powered-Via: QTP 1.4.4\n\n");
                strcpy (dir, path);
                snprintf (path, BLOCK - 1, "%s/%s.txt", main_dir, dirQ);

                addGB (path, username, message);
            }
            else {
                error_404 ();
                return 0;
            }


        }
        else {
            error_404 ();
            return 0;
        }

    }
    else {

        printf ("Content-Type: text/html; charset=windows-1251\n");
        printf ("A-Powered-Via: QTP 1.4.4\n");

        if (!cgiFormString ("action", query, BLOCK - 1)
                && !strcmp (query, "view")
                && !cgiFormString ("dir", query, BLOCK - 1) && strcmp (query, "")) {

            if(!checksafe(query)) {
                error_404();
                return 0;
            }

            strcpy (title, "view");
            struct stat buf;
            bzero (&buf, sizeof (struct stat));

            char path[BLOCK];
            bzero (&path, BLOCK);
            snprintf (path, BLOCK - 1, "%s/%s", main_dir, query);

            qcm_checker ("foto_view");
            qcm_set (NULL);
            qcm_set ("dir");
            cachef = qcm_open ("foto_view");
            if (!cachef)
                return 0;		// Сработал кэш, ничего делать больше не надо

            printf ("create:now\n");

            stat (path, &buf);
            if (S_ISREG (buf.st_mode)) {
                strcpy (dir, path);
                foto_view ();
            }
            else {
                error_404 ();
                return 0;
            }

            qcm_close (&cachef);
            qcm_checker ("foto_view");
            qcm_clear ();

        }
        else {


            struct stat buf;
            bzero (&buf, sizeof (struct stat));

            cgiFormString ("dir", query, BLOCK - 1);

            if(!checksafe(query)) {
                error_404();
                return 0;
            }

            qcm_checker ("foto_dir_checker");
            qcm_set (NULL);
            qcm_set ("dir");
            cachef = qcm_open ("foto_dir");
            if (!cachef)
                return 0;		// Сработал кэш, ничего делать больше не надо
            printf ("create:now\n");
//      strcpy(query,"2006");
            if (!strcmp (query, "")) {
                strcpy (title, "main");
                strcpy (dir, main_dir);
                foto_index ();
            } else {
                int qLen = strlen (query);
                if (query[qLen - 1] != '/') {
                    query[qLen] = '/';
                    query[qLen + 1] = '\0';
                }

                strcpy (title, query);
                char path[BLOCK];
                bzero (&path, BLOCK);
                snprintf (path, BLOCK - 1, "%s/%s", main_dir, query);
                stat (path, &buf);
                if (S_ISDIR (buf.st_mode)) {
                    strcpy (dir, path);
                    foto_index ();
                }
                else {
                    error_404 ();
                    return 0;
                }
            }

            qcm_close (&cachef);
            qcm_clear ();


        }
    }
//      CookieSet();
    /*	IDB pIDB = idb_open("/tmp/file.idb");
    	char *apoweredby;
    	if((apoweredby=idb_get(pIDB,"apoweredby")) == NULL) {
    		idb_put(pIDB,"apoweredby","QTP 1.4.4 QL");
    	}
    	idb_close(pIDB);*/

    return 0;
}