taskrambler  v0.1.8
Web server and task management solution.
asset/asset.c File Reference
#include <stdarg.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include "class.h"
#include "asset.h"
#include "hash.h"
#include "utils/mime_type.h"
#include "utils/hash.h"
#include "utils/http.h"
+ Include dependency graph for asset/asset.c:

Go to the source code of this file.

Functions

static int assetCtor (void *_this, va_list *params)
 
static void assetDtor (void *_this)
 
static unsigned long assetGetHash (void *_this)
 
static void assetHandleDouble (void *_this, void *_doub)
 
 INIT_IFACE (Class, assetCtor, assetDtor, NULL)
 
 INIT_IFACE (Hashable, assetGetHash, assetHandleDouble)
 
 CREATE_CLASS (Asset, NULL, IFACE(Class), IFACE(Hashable))
 

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

Function Documentation

static int assetCtor ( void *  _this,
va_list *  params 
)
static

Definition at line 51 of file asset/asset.c.

References getMimeType(), rfc1123Gmt(), sdbm(), and size.

52 {
53  Asset this = _this;
54 
55  struct tm * tmp;
56  struct stat st;
57  char * fname = va_arg(*params, char*);
58  char * ext;
59 
60  this->nfname = va_arg(*params, size_t);
61 
62  strncpy(this->fname, fname, 2048);
63  this->fname[2048] = '\0';
64 
65  this->hash = sdbm(
66  (unsigned char *)this->fname,
67  this->nfname);
68 
69  if (-1 == access(this->fname, R_OK)) {
70  return -1;
71  } else {
72  this->handle = open(this->fname, O_RDONLY);
73  fstat(this->handle, &st);
74  }
75 
76  tmp = localtime(&(st.st_mtime));
77  this->netag = strftime(this->etag, sizeof(this->etag), "%s", tmp);
78  this->nmtime = rfc1123Gmt(
79  this->mtime,
80  sizeof(this->mtime),
81  &(st.st_mtime));
82 
83  this->size = st.st_size;
84 
85  ext = strrchr(this->fname, '.');
86  if (NULL != ext) {
87  ext++;
88  this->mime_type = getMimeType(ext, strlen(ext));
89  } else {
90  this->mime_type = "application/octet-stream";
91  }
92 
93  if (NULL != this->mime_type) {
94  this->nmime_type = strlen(this->mime_type);
95  } else {
96  this->nmime_type = 0;
97  }
98 
99  if (0 < this->size) {
100  this->data = mmap(
101  NULL, this->size, PROT_READ, MAP_PRIVATE, this->handle, 0);
102 
103  if (MAP_FAILED == this->data) {
104  close(this->handle);
105  return -1;
106  }
107  }
108 
109  this->ref_count = 1;
110 
111  return 0;
112 }
unsigned long sdbm(const unsigned char *, size_t)
Definition: utils/hash.c:45
char * getMimeType(const char *, size_t)
Definition: mime_type.c:84
static size_t size
size_t rfc1123Gmt(char *, size_t, const time_t *)
Definition: utils/http.c:53

+ Here is the call graph for this function:

static void assetDtor ( void *  _this)
static

Definition at line 114 of file asset/asset.c.

References size.

114  {
115  Asset this = _this;
116 
117  if (MAP_FAILED != this->data && NULL != this->data) {
118  munmap(this->data, this->size);
119  }
120 
121  if (0 < this->handle) {
122  close(this->handle);
123  }
124 }
static size_t size
static unsigned long assetGetHash ( void *  _this)
static

Definition at line 128 of file asset/asset.c.

129 {
130  Asset this = _this;
131 
132  return this->hash;
133 }
static void assetHandleDouble ( void *  _this,
void *  _doub 
)
static

Definition at line 137 of file asset/asset.c.

138 {
139 }
CREATE_CLASS ( Asset  ,
NULL  ,
IFACE(Class)  ,
IFACE(Hashable)   
)
INIT_IFACE ( Class  ,
assetCtor  ,
assetDtor  ,
NULL   
)
INIT_IFACE ( Hashable  ,
assetGetHash  ,
assetHandleDouble   
)