Ejemplo n.º 1
0
void server_answer(db_t* self,list_t* list,http_request_t req, socket_t * clientSocket,lanser ** freelanser)
{
    if(strcmp(req.uri,"/Freelancer/api/?"))
    {
        server_Sort(req,clientSocket,self);
    }
    else if (!strcmp(req.uri, "/Freelancer-count"))
    {
        server_count(clientSocket,list);
    }
    else if (!strcmp(req.uri, "/Freelancer/api"))
    {
        if (!strcmp(req.method, "GET"))
            server_GET_all(req,clientSocket,list);
        else if(!strcmp(req.method, "DELETE"))
            server_DELETE_all(req,clientSocket,list);
        else
            socket_write_string(clientSocket, "Method not allowed!\n");

    }
    else if (strncmp(req.uri, "/Freelancer/api/",16)==0)
    {
        if(!strcmp(req.method,"GET"))
            server_GET_id(req,clientSocket,list);
        else if(!strcmp(req.method,"DELETE"))
            server_DELETE_id(req,clientSocket,list,self);
        else if(!strcmp(req.method,"POST"))
        {
            server_POST(req,clientSocket,list,self);
        }
    }
    else if(!strncmp(req.uri,"/Freelancer/delete/",19))
    {
        server_DELETE_id(req,clientSocket,list,self);
    }
    else  if(!strcmp(req.uri,"/Freelancer"))
    {
        server_start_page(clientSocket);
    }
    else if(!strcmp(req.uri,"/Freelancer/"))
    {
        server_GET_html(clientSocket,list);
    }
    else if(!strcmp(req.uri,"/Freelancer/paste"))
    {
        server_Paste_html(req,clientSocket,list);
    }
    else if(!strncmp(req.uri,"/Freelancer/",12))
    {
        server_GET_id_html(req,clientSocket,list);
    }
    else
        socket_write_string(clientSocket,"\nHTTP1.1 404 NOT FOUND\n"
                            "Content-Type: application/json\n"
                            "Content-Length: %i\r\n\r\n""Freelancer not found\n");
}
Ejemplo n.º 2
0
void server_answer(http_request_t req, socket_t * clientSocket,lanser ** freelanser)
{
    if (!strcmp(req.uri, "/info"))
    {
        server_info(clientSocket);
    }
    else
    if (!strcmp(req.uri, "/external"))
    {
        server_external();
    }
    else if (strncmp(req.uri, "/Freelancer/api/",16)==0)
    {
        if(!strcmp(req.method,"GET"))
            server_GET_id(req,clientSocket,freelanser);
        else if(!strcmp(req.method,"DELETE"))
            server_DELETE_id(req,clientSocket,freelanser);
        else if(!strcmp(req.method,"POST"))
        {
            puts("1");
            server_POST(req,clientSocket,freelanser);
        }
    }
    else if(!strncmp(req.uri,"/Freelancer/delete/",19))
    {
        server_DELETE_id(req,clientSocket,freelanser);
    }
    else  if(!strcmp(req.uri,"/Freelancer"))
    {
        server_start_page(clientSocket);
    }
    else if(!strcmp(req.uri,"/Freelancer/"))
    {
        server_GET_html(clientSocket,freelanser);
    }
    else if(!strcmp(req.uri,"/Freelancer/paste"))
    {
        server_Paste_html(req,clientSocket,freelanser);
    }
    else if(!strncmp(req.uri,"/Freelancer/",12))
    {
        server_GET_id_html(req,clientSocket,freelanser);
    }
}
void server_answer(http_request_t req, socket_t * clientSocket, sqlite3 * db) {
    puts(req.method);
    puts(req.uri);
    if (!strcmp(req.uri, "/Teacher-count"))
    {
        server_count(clientSocket, db);
    }
    else

        if (strncmp(req.uri, "/api/Teacher/", 13) == 0)
    {
        if(!strcmp(req.method, "GET"))
            server_GET_id(req, clientSocket, db);
        else if(!strcmp(req.method,"DELETE"))
            server_DELETE_id(req, clientSocket, db);
        else if(!strcmp(req.method,"POST"))
        {
            puts("1");
            server_POST(req, clientSocket, db);
        }
    }
    else


    if (!strncmp(req.uri, "/api/Teacher", 12))
    {
        if (!strcmp(req.method, "GET")) {
            if (!strncmp(req.uri, "/api/Teacher?", 13))  {
                int filtSubj, filtYears;
                char* str = req.uri;
                sscanf (str, "/api/Teacher?subjects=%i|years=%i", &filtSubj, &filtYears);
                server_GET_filt(req, clientSocket, db, filtSubj, filtYears);
            }
        else
            server_GET_all(req, clientSocket, db);
        }
        else if(!strcmp(req.method, "DELETE"))
            server_DELETE_all(req, clientSocket, db);
        else
            socket_write_string(clientSocket, "Method not allowed!\n");

    }
    else




    if(!strncmp(req.uri,"/Teacher/delete/",16))
    {
        server_DELETE_id(req, clientSocket, db);
    }
    else
    if (!strncmp(req.uri, "/Teacher?", 9)) {
        int filtSubj, filtYears;
        char* str = req.uri;
        sscanf (str, "/api/Teacher?subjects=%i|years=%i", &filtSubj, &filtYears);
        server_GET_filt_html(req, clientSocket, db, filtSubj, filtYears);
    }
    else  if(!strcmp(req.uri,"/Teacher"))
    {
        server_start_page(clientSocket);
    }
    else if(!strcmp(req.uri,"/Teacher/"))
    {
        server_GET_html(clientSocket, db);
    }
    else if(!strcmp(req.uri,"/Teacher/paste"))
    {
        server_Paste_html(req, clientSocket, db);
    }
    else if(!strncmp(req.uri, "/Teacher/", 9))
    {
        server_GET_id_html(req, clientSocket, db);
    }
    else
        socket_write_string(clientSocket,"\nHTTP1.1 404 NOT FOUND\n"
            "Content-Type: application/json\n"
            "Content-Length: %i\r\n\r\n""Teacher not found\n");
}