taskrambler  0.1.9
Web server and task management solution.
response.h File Reference
#include <time.h>
#include <sys/types.h>
#include "class.h"
#include "http/message.h"
#include "session.h"
#include "user.h"
#include "asset.h"
+ Include dependency graph for response.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 CLASS (HttpResponse)
 
HttpResponse httpResponse304 (const char *, size_t, const char *, size_t, const char *, size_t)
 
HttpResponse httpResponse403 ()
 
HttpResponse httpResponse404 ()
 
HttpResponse httpResponse500 ()
 
HttpResponse httpResponseJson (const char *, size_t)
 
HttpResponse httpResponseAsset (const char *, size_t, time_t)
 

Detailed Description

Represents one HTTP response.

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file response.h.

Function Documentation

CLASS ( HttpResponse  )

Definition at line 37 of file response.h.

References EXTENDS.

37  {
38  EXTENDS(HttpMessage);
39 
40  unsigned int status;
41  char * reason;
42 };
#define EXTENDS(parent)
Definition: class/class.h:49
HttpResponse httpResponse304 ( const char *  ,
size_t  ,
const char *  ,
size_t  ,
const char *  ,
size_t   
)

Definition at line 35 of file 304.c.

References CSTRA, and hashAdd().

Referenced by httpWorkerGetAsset().

39 {
40  HttpResponse response;
41  HttpMessage message;
42 
43  response = new(HttpResponse, "HTTP/1.1", 304, "Not Modified");
44  message = (HttpMessage)response;
45 
46  message->nbody = 0;
47  message->body = NULL;
48 
49  hashAdd(message->header,
50  new(HttpHeader, CSTRA("Content-Type"), mime, nmime));
51  hashAdd(message->header,
52  new(HttpHeader, CSTRA("ETag"), etag, netag));
53  hashAdd(message->header,
54  new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime));
55 
56  return response;
57 }
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
void * hashAdd(Hash, void *)
Definition: add.c:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HttpResponse httpResponse403 ( )

Definition at line 36 of file 403.c.

37 {
38  HttpResponse response;
39  HttpMessage message;
40 
41  response = new(HttpResponse, "HTTP/1.1", 403, "Forbidden");
42  message = (HttpMessage)response;
43 
44  message->nbody = 0;
45  message->body = NULL;
46 
47  return response;
48 }
HttpResponse httpResponse404 ( )

Definition at line 47 of file 404.c.

References CSTRA, hashAdd(), memMalloc(), and RESP_DATA.

Referenced by httpWorkerGetAsset(), httpWorkerProcess(), and routerRoute().

48 {
49  HttpResponse response;
50  HttpMessage message;
51 
52  response = new(HttpResponse, "HTTP/1.1", 404, "Not Found");
53  message = (HttpMessage)response;
54 
55  hashAdd(message->header,
56  new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html")));
57 
58  message->nbody = sizeof(RESP_DATA) - 1;
59  message->body = memMalloc(sizeof(RESP_DATA));
60  memcpy(message->body, RESP_DATA, sizeof(RESP_DATA));
61 
62  return response;
63 }
void * memMalloc(size_t)
Definition: memory.c:783
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
#define RESP_DATA
Definition: 404.c:37
void * hashAdd(Hash, void *)
Definition: add.c:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HttpResponse httpResponse500 ( )

Definition at line 47 of file 500.c.

References CSTRA, hashAdd(), memMalloc(), and RESP_DATA.

Referenced by httpWorkerProcess().

48 {
49  HttpResponse response;
50  HttpMessage message;
51 
52  response = new(HttpResponse, "HTTP/1.1", 500, "Internal Server Error");
53  message = (HttpMessage)response;
54 
55  hashAdd(message->header,
56  new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html")));
57 
58  message->nbody = sizeof(RESP_DATA) - 1;
59  message->body = memMalloc(sizeof(RESP_DATA));
60  memcpy(message->body, RESP_DATA, sizeof(RESP_DATA));
61 
62  return response;
63 }
void * memMalloc(size_t)
Definition: memory.c:783
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
#define RESP_DATA
Definition: 500.c:37
void * hashAdd(Hash, void *)
Definition: add.c:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HttpResponse httpResponseAsset ( const char *  ,
size_t  ,
time_t   
)

Definition at line 59 of file http/response/asset.c.

References assetPoolGet(), CSTRA, hashAdd(), and rfc1123Gmt().

Referenced by httpWorkerGetAsset().

60 {
61  HttpResponse response;
62  HttpMessage message;
63  Asset asset = assetPoolGet(fname, nfname);
64  char expires[200];
65  size_t nexpires;
66 
67  if (NULL == asset) {
68  return NULL;
69  }
70 
71  response = new(HttpResponse, "HTTP/1.1", 200, "OK");
72  message = (HttpMessage)response;
73 
74  message->asset = asset;
75  message->body = asset->data;
76  message->nbody = asset->size;
77 
78  nexpires = rfc1123Gmt(expires, sizeof(expires), &exptime);
79 
80  hashAdd(message->header,
81  new(HttpHeader, CSTRA("Content-Type"),
82  asset->mime_type, asset->nmime_type));
83  hashAdd(message->header,
84  new(HttpHeader, CSTRA("ETag"), asset->etag, asset->netag));
85  hashAdd(message->header,
86  new(HttpHeader, CSTRA("Expires"), expires, nexpires));
87  hashAdd(message->header,
88  new(HttpHeader, CSTRA("Last-Modified"),
89  asset->mtime, asset->nmtime));
90 
91  return response;
92 }
Asset assetPoolGet(const char *, size_t)
Definition: pool.c:43
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
size_t rfc1123Gmt(char *, size_t, const time_t *)
Definition: utils/http.c:53
void * hashAdd(Hash, void *)
Definition: add.c:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HttpResponse httpResponseJson ( const char *  ,
size_t   
)

Definition at line 40 of file json.c.

References CSTRA, hashAdd(), and memMalloc().

Referenced by routerRoute().

41 {
42  HttpResponse response;
43  HttpMessage message;
44 
45  response = new(HttpResponse, "HTTP/1.1", 200, "OK");
46  message = (HttpMessage)response;
47 
48  hashAdd(message->header,
49  new(HttpHeader, CSTRA("Content-Type"), CSTRA("application/json")));
50 
51  message->nbody = nbody;
52  message->body = memMalloc(nbody);
53  memcpy(message->body, body, nbody);
54 
55  return response;
56 }
void * memMalloc(size_t)
Definition: memory.c:783
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
void * hashAdd(Hash, void *)
Definition: add.c:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function: