taskrambler  0.1.9
Web server and task management solution.
get_asset.c File Reference
#include <sys/types.h>
#include <time.h>
#include "http/header.h"
#include "http/message.h"
#include "http/request.h"
#include "http/response.h"
#include "http/worker.h"
#include "utils/memory.h"
#include "hash.h"
+ Include dependency graph for get_asset.c:

Go to the source code of this file.

Functions

HttpMessage httpWorkerGetAsset (HttpWorker this, const char *fname)
 

Detailed Description

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 get_asset.c.

Function Documentation

HttpMessage httpWorkerGetAsset ( HttpWorker  this,
const char *  fname 
)

Definition at line 36 of file get_asset.c.

References CSTRA, hashGet(), httpResponse304(), httpResponse404(), and httpResponseAsset().

Referenced by httpWorkerProcess().

37 {
38  char * match;
39  size_t nmatch;
40  HttpHeader header;
41  HttpMessage message;
42 
43  size_t nfname = strlen(fname);
44 
45  header = hashGet(
46  ((HttpMessage)this->current_request)->header,
47  CSTRA("If-None-Match"));
48 
49  if (NULL == header) {
50  match = "";
51  nmatch = 0;
52  }
53  else {
54  match = (header->value)[0];
55  nmatch = (header->nvalue)[0];
56  }
57 
58  /*
59  * assets expire after 12 hours...
60  */
61  message = (HttpMessage)httpResponseAsset(
62  fname,
63  nfname,
64  time(NULL) + 43200);
65 
66  if (NULL == message) {
67  return (HttpMessage)httpResponse404();
68  }
69 
70  if (message->asset->netag == nmatch
71  && 0 == memcmp(message->asset->etag, match, nmatch)) {
72  HttpMessage new_message;
73 
74  new_message = (HttpMessage)httpResponse304(
75  message->asset->mime_type, message->asset->nmime_type,
76  message->asset->etag, message->asset->netag,
77  message->asset->mtime, message->asset->nmtime);
78 
79  delete(message);
80 
81  return new_message;
82  }
83 
84  return message;
85 }
HttpResponse httpResponseAsset(const char *, size_t, time_t)
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
void * hashGet(Hash, const char *, size_t)
Definition: hash/get.c:51
HttpResponse httpResponse304(const char *, size_t, const char *, size_t, const char *, size_t)
Definition: 304.c:35
HttpResponse httpResponse404()
Definition: 404.c:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function: