Commit 08533a4b626db1d1690a323f7f8e8337d53c1bb8

Authored by Georg Hopp
1 parent 4b5bcf89

oops, forgot one file

Showing 1 changed file with 74 additions and 0 deletions
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright (C) 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <stdlib.h>
  24 +#include <string.h>
  25 +#include <stdio.h>
  26 +#include <time.h>
  27 +#include <sys/types.h>
  28 +
  29 +#include "class.h"
  30 +#include "interface/class.h"
  31 +
  32 +#include "http/response.h"
  33 +#include "http/message.h"
  34 +#include "http/header.h"
  35 +
  36 +
  37 +#define RESP_DATA "%02d"
  38 +
  39 +HttpResponse
  40 +httpResponseRandval(int value)
  41 +{
  42 + char buffer[200];
  43 + HttpResponse response;
  44 + HttpMessage message;
  45 + size_t nbuf;
  46 +
  47 + response = new(HttpResponse, "HTTP/1.1", 200, "OK");
  48 + message = (HttpMessage)response;
  49 +
  50 + httpHeaderAdd(&(message->header),
  51 + new(HttpHeader,
  52 + "Content-Type",
  53 + sizeof("Content-Type")-1,
  54 + "text/html",
  55 + sizeof("text/html")-1));
  56 +
  57 + message->type = HTTP_MESSAGE_BUFFERED;
  58 + message->nbody = sizeof(RESP_DATA)-1-2;
  59 + message->body = malloc(sizeof(RESP_DATA)-2);
  60 + sprintf(message->body, RESP_DATA, value);
  61 +
  62 + nbuf = sprintf(buffer, "%d", message->nbody);
  63 +
  64 + httpHeaderAdd(&(message->header),
  65 + new(HttpHeader,
  66 + "Content-Length",
  67 + sizeof("Content-Length")-1,
  68 + buffer,
  69 + nbuf));
  70 +
  71 + return response;
  72 +}
  73 +
  74 +// vim: set ts=4 sw=4:
Please register or login to post a comment