Mercurial > urweb
comparison src/c/urweb.c @ 1956:ac1be85e91ad
Add 'html5' .urp directive
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Thu, 09 Jan 2014 17:27:24 -0500 |
parents | d7bec4e63415 |
children | 81bc76aa4acd |
comparison
equal
deleted
inserted
replaced
1955:469e02eea43a | 1956:ac1be85e91ad |
---|---|
3239 return ctx->app->db_rollback(ctx); | 3239 return ctx->app->db_rollback(ctx); |
3240 } else | 3240 } else |
3241 return 0; | 3241 return 0; |
3242 } | 3242 } |
3243 | 3243 |
3244 static const char begin_xhtml[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">"; | 3244 const char uw_begin_xhtml[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">"; |
3245 const char uw_begin_html5[] = "<!DOCTYPE html><html>"; | |
3245 | 3246 |
3246 extern int uw_hash_blocksize; | 3247 extern int uw_hash_blocksize; |
3247 | 3248 |
3248 static const char sig_intro[] = "<input type=\"hidden\" name=\"Sig\" value=\""; | 3249 static const char sig_intro[] = "<input type=\"hidden\" name=\"Sig\" value=\""; |
3249 | 3250 |
3329 ctx->transactionals[i].free(ctx->transactionals[i].data, 0); | 3330 ctx->transactionals[i].free(ctx->transactionals[i].data, 0); |
3330 | 3331 |
3331 uw_check(ctx, 1); | 3332 uw_check(ctx, 1); |
3332 *ctx->page.front = 0; | 3333 *ctx->page.front = 0; |
3333 | 3334 |
3334 if (!ctx->returning_indirectly && !strncmp(ctx->page.start, begin_xhtml, sizeof begin_xhtml - 1)) { | 3335 if (!ctx->returning_indirectly |
3336 && (ctx->app->is_html5 | |
3337 ? !strncmp(ctx->page.start, uw_begin_html5, sizeof uw_begin_html5 - 1) | |
3338 : !strncmp(ctx->page.start, uw_begin_xhtml, sizeof uw_begin_xhtml - 1))) { | |
3335 char *s; | 3339 char *s; |
3336 | 3340 |
3337 // Splice script data into appropriate part of page, also adding <head> if needed. | 3341 // Splice script data into appropriate part of page, also adding <head> if needed. |
3338 s = ctx->page.start + sizeof begin_xhtml - 1; | 3342 s = ctx->page.start + (ctx->app->is_html5 ? sizeof uw_begin_html5 - 1 : sizeof uw_begin_xhtml - 1); |
3339 s = strchr(s, '<'); | 3343 s = strchr(s, '<'); |
3340 if (s == NULL) { | 3344 if (s == NULL) { |
3341 // Weird. Document has no tags! | 3345 // Weird. Document has no tags! |
3342 | 3346 |
3343 uw_write(ctx, "<head></head><body></body>"); | 3347 uw_write(ctx, "<head></head><body></body>"); |
4168 uw_write_header(ctx, "HTTP/1.1 "); | 4172 uw_write_header(ctx, "HTTP/1.1 "); |
4169 else | 4173 else |
4170 uw_write_header(ctx, "Status: "); | 4174 uw_write_header(ctx, "Status: "); |
4171 uw_write_header(ctx, "500 Internal Server Error\r\n"); | 4175 uw_write_header(ctx, "500 Internal Server Error\r\n"); |
4172 uw_write_header(ctx, "Content-type: text/html\r\n"); | 4176 uw_write_header(ctx, "Content-type: text/html\r\n"); |
4173 uw_write(ctx, begin_xhtml); | 4177 uw_write(ctx, ctx->app->is_html5 ? uw_begin_html5 : uw_begin_xhtml); |
4174 ctx->app->on_error(ctx, msg); | 4178 ctx->app->on_error(ctx, msg); |
4175 uw_write(ctx, "</html>"); | 4179 uw_write(ctx, "</html>"); |
4176 } | 4180 } |
4177 | 4181 |
4178 return r; | 4182 return r; |