Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 #ifndef _HttpBodyFactory_h_
00056 #define _HttpBodyFactory_h_
00057 
00058 #include <strings.h>
00059 #include <sys/types.h>
00060 #include "libts.h"
00061 #include "HTTP.h"
00062 #include "HttpConfig.h"
00063 #include "HttpCompat.h"
00064 #include "HttpTransact.h"
00065 #include "Error.h"
00066 #include "Main.h"
00067 #include "RawHashTable.h"
00068 
00069 
00070 #define HTTP_BODY_TEMPLATE_MAGIC 0xB0DFAC00
00071 #define HTTP_BODY_SET_MAGIC      0xB0DFAC55
00072 #define HTTP_BODY_FACTORY_MAGIC  0xB0DFACFF
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 class HttpBodyTemplate
00086 {
00087 public:
00088   HttpBodyTemplate();
00089   ~HttpBodyTemplate();
00090 
00091   void reset();
00092   int load_from_file(char *dir, char *file);
00093   bool is_sane()
00094   {
00095     return (magic == HTTP_BODY_TEMPLATE_MAGIC);
00096   }
00097   char *build_instantiated_buffer(HttpTransact::State * context, int64_t *length_return);
00098 
00099   unsigned int magic;
00100   int64_t byte_count;
00101   char *template_buffer;
00102   char *template_pathname;
00103 };
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 class HttpBodySet:public HttpBodySetRawData
00120 {
00121 public:
00122   HttpBodySet();
00123   ~HttpBodySet();
00124 
00125   int init(char *set_name, char *dir);
00126   bool is_sane()
00127   {
00128     return (magic == HTTP_BODY_SET_MAGIC);
00129   }
00130 
00131   HttpBodyTemplate *get_template_by_name(const char *name);
00132   void set_template_by_name(const char *name, HttpBodyTemplate * t);
00133 };
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 class HttpBodyFactory
00151 {
00152 public:
00153   HttpBodyFactory();
00154   ~HttpBodyFactory();
00155 
00156 
00157   
00158 
00159   char *fabricate_with_old_api(const char *type, HttpTransact::State * context,
00160                                int64_t max_buffer_length, int64_t *resulting_buffer_length,
00161                                char* content_language_out_buf,
00162                                size_t content_language_buf_size,
00163                                char* content_type_out_buf,
00164                                size_t content_type_buf_size,
00165                                const char *format, va_list ap);
00166 
00167   char *fabricate_with_old_api_build_va(const char *type, HttpTransact::State * context,
00168                                         int64_t max_buffer_length, int64_t *resulting_buffer_length,
00169                                         char* content_language_out_buf, size_t content_language_buf_size,
00170                                         char* content_type_out_buf, size_t content_type_buf_size,
00171                                         const char *format, ...)
00172   {
00173     char * msg;
00174     va_list ap;
00175 
00176     va_start(ap, format);
00177     msg = fabricate_with_old_api(type, context, max_buffer_length, resulting_buffer_length,
00178                                    content_language_out_buf, content_language_buf_size,
00179                                    content_type_out_buf, content_type_buf_size, format, ap);
00180     va_end(ap);
00181     return msg;
00182   }
00183 
00184   void dump_template_tables(FILE * fp = stderr);
00185   void reconfigure();
00186 
00187 private:
00188 
00189   char *fabricate(StrList * acpt_language_list,
00190                   StrList * acpt_charset_list,
00191                   const char *type, HttpTransact::State * context,
00192                   int64_t *resulting_buffer_length,
00193                   const char **content_language_return,
00194                   const char **content_charset_return, const char **set_return = NULL);
00195 
00196   const char *determine_set_by_language(StrList * acpt_language_list, StrList * acpt_charset_list);
00197   HttpBodyTemplate *find_template(const char *set, const char *type, HttpBodySet ** body_set_return);
00198   bool is_response_suppressed(HttpTransact::State * context);
00199   bool is_sane()
00200   {
00201     return (magic == HTTP_BODY_FACTORY_MAGIC);
00202   }
00203   void sanity_check()
00204   {
00205     ink_assert(is_sane());
00206   }
00207 
00208 private:
00209 
00210   
00211 
00212   void nuke_template_tables();
00213   RawHashTable *load_sets_from_directory(char *set_dir);
00214   HttpBodySet *load_body_set_from_directory(char *set_name, char *tmpl_dir);
00215 
00216 
00217   
00218 
00219   void lock()
00220   {
00221     ink_mutex_acquire(&mutex);
00222   }
00223   void unlock()
00224   {
00225     ink_mutex_release(&mutex);
00226   }
00227 
00228 
00229   
00230 
00231   int enable_customizations;    
00232   bool enable_logging;          
00233   int response_suppression_mode;        
00234 
00235 
00236   
00237 
00238   unsigned int magic;           
00239   ink_mutex mutex;              
00240   bool callbacks_established;   
00241   RawHashTable *table_of_sets;  
00242 };
00243 
00244 #endif