예제 #1
0
int main() {
    lib_init();
    socket_t * server = socket_new();
    socket_bind(server, 5000);
    socket_listen(server);
	
   char buf[10000];
    char pathBuf[256];
    socket_t * client = NULL;

    while(1) {
		client = socket_accept(server);
        socket_read(client, buf, sizeof(buf));
		if (strlen(buf) == 0)
			continue;
        printf(">> Got request:\n%s\n", buf);

        http_getPath(buf, pathBuf, sizeof(pathBuf));

        http_request_t request = http_request_parse(buf);

        if (strcmp(request.uri, "/") == 0) {
            server_homepage(client);
        } else if (strcmp(request.uri, "/database") == 0) {
            server_students(client, &request);
        }  
        else if (strcmp(request.uri, "/info") == 0) {
            server_info(client);
        }
        else if (strcmp(request.uri, "/filename") == 0) {
            server_file_parse(client);
        }
        else {
            server_notFound(client);
        }
		socket_free(client);
    }
    socket_free(server);
    lib_free();
    return 0;
}
예제 #2
0
파일: main.c 프로젝트: antonmazun/gogog
int main() {
    lib_init();
    socket_t * server = socket_new();
    socket_bind(server, 5000);
    socket_listen(server);

   char buf[10000];
    char pathBuf[256];
    socket_t * client = NULL;

    while(1) {
		client = socket_accept(server);
        socket_read(client, buf, sizeof(buf));
		if (strlen(buf) == 0)
			continue;
        printf(">> Got request:\n%s\n", buf);

        http_getPath(buf, pathBuf, sizeof(pathBuf));

        http_request_t request = http_request_parse(buf);

        if (strcmp(request.uri, "/") == 0) {
            server_homepage(client);
        } else if (strcmp(request.uri, "/api/admins") == 0) {
			server_database(client);
		} else if (strcmp(request.uri, "/api/admins/") > 0) {
			server_database_id(client, &request);
		} else {
            error_massage(client, "404 - NOT FOUND!");
        }
		socket_free(client);
    }
    socket_free(server);
    lib_free();
    return 0;
}