1 // 2 // aegis - project change supervisor 3 // Copyright (C) 2003-2008, 2011, 2012 Peter Miller 4 // Copyright (C) 2007 Walter Franzini 5 // 6 // This program is free software; you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation; either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see 18 // <http://www.gnu.org/licenses/>. 19 // 20 21 #ifndef AEGET_HTTP_H 22 #define AEGET_HTTP_H 23 24 #include <libaegis/change.h> 25 26 class nstring; // forward 27 struct project; // forward 28 struct string_ty; // forward 29 class nstring; // forward 30 struct string_list_ty; // forward 31 32 enum http_error_t 33 { 34 http_error_continue = 100, 35 http_error_switching_protocols = 101, 36 http_error_ok = 200, 37 http_error_created = 201, 38 http_error_accepted = 202, 39 http_error_non_authoritative_information = 203, 40 http_error_no_content = 204, 41 http_error_reset_content = 205, 42 http_error_partial_content = 206, 43 http_error_multiple_choices = 300, 44 http_error_moved_permanently = 301, 45 http_error_moved_temporarily = 302, 46 http_error_see_other = 303, 47 http_error_not_modified = 304, 48 http_error_use_proxy = 305, 49 http_error_bad_request = 400, 50 http_error_unauthorized = 401, 51 http_error_payment_required = 402, 52 http_error_forbidden = 403, 53 http_error_not_found = 404, 54 http_error_method_not_allowed = 405, 55 http_error_not_acceptable = 406, 56 http_error_proxy_authentication_required = 407, 57 http_error_request_time_out = 408, 58 http_error_conflict = 409, 59 http_error_gone = 410, 60 http_error_length_required = 411, 61 http_error_precondition_failed = 412, 62 http_error_request_entity_too_large = 413, 63 http_error_request_url_too_large = 414, 64 http_error_unsupported_media_type = 415, 65 http_error_internal_server = 500, 66 http_error_not_implemented = 501, 67 http_error_bad_gateway = 502, 68 http_error_out_of_resources = 503, 69 http_error_gateway_time_out = 504, 70 http_error_version_not_supported = 505, 71 }; 72 73 extern bool http_fatal_noerror; 74 75 void http_fatal(http_error_t oops, const char *fmt, ...) ATTR_PRINTF(2, 3); 76 const char *http_getenv(const char *); 77 void html_escape_string(string_ty *); 78 void html_escape_string(const nstring &); 79 void html_escape_charstar(const char *); 80 void html_encode_string(string_ty *); 81 void html_encode_string(const nstring &); 82 void html_encode_charstar(const char *); 83 void http_content_type_header(string_ty *); 84 85 /** 86 * The html_header function is used to emit the initial portion of a HTML 87 * file, for the necessary meta attrributes and style sheet information. 88 * 89 * The "html:meta" attributes are inserted at this point. 90 */ 91 void html_header(project *, change::pointer); 92 93 /** 94 * The html_header_os function is used to emit the "html:body-begin" 95 * attributes. 96 */ 97 void html_header_ps(project *, change::pointer); 98 99 /** 100 * The html_footer function is used to emit the final page footer, 101 * including date and version. 102 * 103 * The "html:body-end" attributes are inserted at this point. 104 */ 105 void html_footer(project *, change::pointer); 106 107 /** 108 * The emit_change function is used to emit the project name and change 109 * number cross linked to all of the relevant pages. This is used in 110 * web page headings. 111 */ 112 void emit_change(change::pointer); 113 114 /** 115 * The emit_change function is used to emit the project name and change 116 * number cross linked to all of the relevant pages, except the last 117 * element. This is used in web page headings. 118 */ 119 void emit_change_but1(change::pointer); 120 121 void 122 emit_change_uuid_href(change::pointer, const nstring &, const nstring &, 123 const nstring &); 124 125 /** 126 * The http_script_name is used to obtainb the value sof the SCRIPT_NAME 127 * environment variable. This is necessary for web pages which need 128 * to refer to other web pages generated by the same script. 129 */ 130 const char *http_script_name(void); 131 132 /** 133 * The emit_project_href function is used to print the leading <a> 134 * portion of a project reference. 135 */ 136 void emit_project_href(project *pp); 137 void emit_project_href(project *pp, const char *modifier, ...) 138 ATTR_PRINTF(2, 3); 139 140 /** 141 * The emit_change_href function is used to print the leading <a> 142 * portion of a change reference. 143 */ 144 void emit_change_href(change::pointer cp, const char *modifier); 145 146 147 /** 148 * The emit_change_href_n function is used to print the leading <a> 149 * portion of a change reference, with an explict change number. 150 */ 151 void emit_change_href_n(project *pp, long change_number, 152 const char *modifier); 153 154 /** 155 * The emit_file_href function is used to print the leading <a> portion 156 * of a file reference. 157 * 158 * \param cp 159 * The change to work within. 160 * \param filename 161 * The name of the file being linked. 162 * \param modifier 163 * extra equery elements 164 */ 165 void emit_file_href(change::pointer cp, const nstring &filename, 166 const char *modifier); 167 168 /** 169 * The emit_file_href function is used to print the leading <a> portion 170 * of a file reference. 171 * 172 * \param cp 173 * The change to work within. 174 * \param filename 175 * The name of the file being linked. 176 * \param modifier 177 * extra equery elements 178 * \note 179 * This function will be DEPRECATED one day 180 */ 181 void emit_file_href(change::pointer cp, string_ty *filename, 182 const char *modifier); 183 184 /** 185 * The emit_rect_image function is used to print an <img> of a 186 * rectangle, use for drawing histograms. 187 * 188 * @param width 189 * The width of the image 190 * @param height 191 * The height of the image 192 * @param label 193 * The label to write on the rectangle 194 * @param hspace 195 * The horizontal space desired around the image. 196 */ 197 void emit_rect_image(int width, int height, const char *label, int hspace = -1); 198 199 /** 200 * The emit_rect_image_rgb function is used to print an <img> of a 201 * rectangle, use for drawing histograms, of s specific color. 202 * 203 * @param width 204 * The width of the rectangle image 205 * @param height 206 * The height of the rectangle image 207 * @param color 208 * The color of the rectangle image 209 * @param hspace 210 * The horizontal spacing to add around the rectangle image. 211 */ 212 void emit_rect_image_rgb(int width, int height, const char *color, 213 int hspace = -1); 214 215 /** 216 * The modifier_test_and_clear function may be used to look for the 217 * named modifier in the modifier list. 218 * 219 * \param modifiers 220 * The modifiers specified for this web page GET. 221 * \param name 222 * The name of the modifier to look for. 223 * \returns 224 * true if the modifier is present, false if not 225 */ 226 bool modifier_test(string_list_ty *modifiers, const char *name); 227 228 /** 229 * The modifier_test_and_clear function may be used to look for the 230 * named modifier in the modifier list. The modifier will be premoved 231 * if it is found. 232 * 233 * \param modifiers 234 * The modifiers specified for this web page GET. 235 * \param name 236 * The name of the modifier to look for. 237 * \returns 238 * true if the modifier is present, false if not 239 */ 240 bool modifier_test_and_clear(string_list_ty *modifiers, const char *name); 241 242 /** 243 * Insert an RSS icon image and link it to an RSS feed file. 244 * 245 * \param pp 246 * The project details. 247 * \param rss_filename 248 * The file name of the RSS feed file. Not the full path. 249 */ 250 void emit_rss_icon_with_link(project *pp, const nstring &rss_filename); 251 252 /** 253 * Print RSS-related meta data. 254 * 255 * \param pp 256 * The project details. 257 * \param rss_filename 258 * The file name of the RSS feed file. Not the full path. 259 */ 260 void emit_rss_meta_data(project *pp, const nstring &rss_filename); 261 262 #define HISTOGRAM_HEIGHT 12 263 #define HISTOGRAM_WIDTH 120 264 265 /** 266 * The http_sanitize_content_type function is used to turn 267 * "text/whatever" content types into "test/plain" content types, 268 * except "text/html". Other content types are passed through 269 * unchanged. 270 * 271 * @param content_type 272 * The content-type to clean up 273 * @returns 274 * text/plain for most text types, otherwise unchanged 275 */ 276 nstring http_sanitize_content_type(const nstring &content_type); 277 278 #endif // AEGET_HTTP_H 279 // vim: set ts=8 sw=4 et : 280