示例#1
0
文件: htcpcpd.c 项目: saljs/htcpcp
char* handleHeaders(char *request)
{
    char method[255] ;
    int i = 0;
    for(i = 0; request[i] != '\n' && request[i] != '\0'; i++)
    {
        method[i] = request[i];
    }
    method[i] = '\0';
    if(strcmp(method, "BREW") == 0 || strcmp(method, "POST") == 0 || strcmp(method, "GET") == 0)
    {
        if(brew() == 0)
        {
            return("HTCPCP/1.0 200 OK");
        }
        else
        {
            return("HTCPCP/1.0 510 Pot busy");
        }
    }
    else if(strcmp(method, "PROPFIND") == 0)
    {
        //server metadata
        if(potinfo.ready == 1)
        {
            return("HTCPCP/1.0 200 OK\nContent-type: message/coffeepot\nPot ready to brew");
        }
        else
        {
            return("HTCPCP/1.0 200 OK\nContent-type: message/coffeepot\nPot not ready to brew");
        }
    }
    else if(strcmp(method, "WHEN") == 0)
    {
        //err immidiatly
        return("HTCPCP/1.0 406 Not Acceptable\nAdditions-List:");
    }
    else
    {
        return ("HTCPCP/1.0 418 I'm a teapot");
    }
}
示例#2
0
 void prepare()
 {
     boilWater(amountWater());
     brew();
     pourInCup();
 }