Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

emb.h

00001 /*
00002  * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com>
00003  * All rights reserved.
00004  *
00005  * This file is part of KLone, and as such it is subject to the license stated
00006  * in the LICENSE file which you have received as part of this distribution.
00007  *
00008  * $Id: emb.h,v 1.16 2007/09/15 16:36:12 tat Exp $
00009  */
00010 
00011 #ifndef _KLONE_EMB_H_
00012 #define _KLONE_EMB_H_
00013 
00014 #include "klone_conf.h"
00015 #include <sys/stat.h>
00016 #ifdef HAVE_STDINT
00017 #include <stdint.h>
00018 #endif /* HAVE_STDINT */
00019 #include <u/libu.h>
00020 #include <klone/klone.h>
00021 
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif 
00025 
00026 /* supported embedded resource type */
00027 enum {
00028     ET_FILE,                /* embedded file                */
00029     ET_PAGE                 /* dynamic web page             */
00030 };
00031 
00032 /* define resource list */
00033 LIST_HEAD(emblist_s, embres_s);
00034 
00035 /* common struct for embedded resources */
00036 typedef struct embres_s
00037 {
00038     LIST_ENTRY(embres_s) np;/* next & prev pointers         */
00039     const char *filename;   /* emb resource file name       */
00040     int type;               /* emb resource type (ET_*)     */
00041 } embres_t;
00042 
00043 /* embedded file */
00044 typedef struct embfile_s
00045 {
00046     embres_t res;           /* any emb resource must start with a embres_t    */
00047     size_t size;            /* size of the data block                         */
00048     unsigned char *data;    /* file data                                      */
00049     int comp;               /* if data is compressed                          */
00050     int encrypted;          /* if data is encrypted                           */
00051     time_t mtime;           /* time of last modification                      */
00052     const char *mime_type;  /* guessed mime type                              */
00053     size_t file_size;       /* size of the source file (not compressed)       */
00054 } embfile_t;
00055 
00056 /* embedded dynamic klone page */
00057 typedef struct embpage_s
00058 {
00059     embres_t res;           /* any emb resource must start with a embres_t  */
00060     void (*run)(request_t*, response_t*, session_t*);   /* page code        */
00061 } embpage_t;
00062 
00063 int emb_init(void);
00064 int emb_term(void);
00065 int emb_register(embres_t *r);
00066 int emb_unregister(embres_t *r);
00067 int emb_lookup(const char *filename, embres_t **pr);
00068 int emb_count(void);
00069 int emb_getn(size_t n, embres_t **pr);
00070 int emb_open(const char *file, io_t **pio);
00071 
00072 #ifdef __cplusplus
00073 }
00074 #endif 
00075 
00076 #endif