taskrambler  0.1.9
Web server and task management solution.
http/response/asset.c File Reference
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include "class.h"
#include "stream.h"
#include "http/response.h"
#include "http/message.h"
#include "http/header.h"
#include "utils/memory.h"
#include "utils/http.h"
#include "hash.h"
#include "asset.h"
+ Include dependency graph for http/response/asset.c:

Go to the source code of this file.

Functions

HttpResponse httpResponseAsset (const char *fname, size_t nfname, time_t exptime)
 

Detailed Description

A response class that delivers an asset (file on disk).

In future this will use a asset class, get from an asset class hash. The asset hash will be a shared resource between all workers.

The asset class holds an open file descriptor wich is memory mapped and is able to give the correct pointer to neede data.

This change will envolve changes in other parts of the response write system, as we no longer need to destinguish between piped and bufferd resources...we will allways work with a memory address only one time its allocated and one time a memory mapped file.

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 http/response/asset.c.

Function Documentation

HttpResponse httpResponseAsset ( const char *  fname,
size_t  nfname,
time_t  exptime 
)

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: