Skip to content

Commit

Permalink
use resource type for uiomux handler
Browse files Browse the repository at this point in the history
  • Loading branch information
kfish committed Apr 6, 2010
1 parent 10e8834 commit cfa5608
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
10 changes: 0 additions & 10 deletions src/http-response.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "log.h"
#include "status.h"
#include "kongou.h"
#include "uiomux.h"
#include "stream.h"
#include "mjpeg.h"

Expand Down Expand Up @@ -54,14 +53,12 @@ respond_get_head_builtin (struct sighttpd_child * schild, http_request * request
struct stream * stream;

int status_request=0;
int uiomux_request=0;
int stream2_request=0;
int stream_request=0;
int kongou_request=0;
int mjpeg_request=0;

status_request = !strncmp (request->path, "/status", 7);
uiomux_request = !strncmp (request->path, "/uiomux", 7);
stream2_request = !strncmp (request->path, "/stream2", 8);
stream_request = !strncmp (request->path, "/stream", 7);
kongou_request = !strncmp (request->path, "/kongou", 7);
Expand All @@ -70,9 +67,6 @@ respond_get_head_builtin (struct sighttpd_child * schild, http_request * request
if (status_request) {
*status_line = http_status_line (HTTP_STATUS_OK);
*response_headers = status_append_headers (*response_headers);
} else if (uiomux_request) {
*status_line = http_status_line (HTTP_STATUS_OK);
*response_headers = uiomux_append_headers (*response_headers);
} else if (kongou_request) {
*status_line = http_status_line (HTTP_STATUS_OK);
*response_headers = kongou_append_headers (*response_headers);
Expand Down Expand Up @@ -129,23 +123,19 @@ respond_get_body_builtin (struct sighttpd_child * schild, http_request * request
struct stream * stream;

int status_request=0;
int uiomux_request=0;
int stream2_request=0;
int stream_request=0;
int kongou_request=0;
int mjpeg_request=0;

status_request = !strncmp (request->path, "/status", 7);
uiomux_request = !strncmp (request->path, "/uiomux", 7);
stream2_request = !strncmp (request->path, "/stream2", 8);
stream_request = !strncmp (request->path, "/stream", 7);
kongou_request = !strncmp (request->path, "/kongou", 7);
mjpeg_request = !strncmp (request->path, "/mjpeg", 6);

if (status_request) {
status_stream_body (fd, schild->sighttpd);
} else if (uiomux_request) {
uiomux_stream_body (fd);
} else if (kongou_request) {
kongou_stream_body (fd, request->path);
} else if (stream2_request) {
Expand Down
4 changes: 3 additions & 1 deletion src/sighttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include "stream.h"
#include "list.h"

#include "flim.h";
#include "flim.h"
#include "uiomux.h"

struct sighttpd * sighttpd_init (Dictionary * config)
{
Expand Down Expand Up @@ -47,6 +48,7 @@ struct sighttpd * sighttpd_init (Dictionary * config)
sighttpd->resources = list_new();

sighttpd->resources = list_append (sighttpd->resources, flim_resource());
sighttpd->resources = list_append (sighttpd->resources, uiomux_resource());

sighttpd->streams = list_new();

Expand Down
30 changes: 28 additions & 2 deletions src/uiomux.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <stdio.h>
#include <string.h>

#include "http-reqline.h"
#include "http-status.h"
#include "params.h"
#include "shell.h"

Expand All @@ -23,17 +25,35 @@
"</body>\n" \
"</head>\n"

params_t * uiomux_append_headers(params_t * response_headers)
static int
uiomux_check (http_request * request, void * data)
{
return !strncmp (request->path, "/uiomux", 7);
}

static params_t *
uiomux_append_headers(params_t * response_headers)
{
char length[16];

fprintf (stderr, "%s: IN\n", __func__);

response_headers =
params_append(response_headers, "Content-Type", "text/html");

return response_headers;
}

int uiomux_stream_body(int fd)
static void
uiomux_head (http_request * request, params_t * request_headers, const char ** status_line,
params_t ** response_headers, void * data)
{
*status_line = http_status_line (HTTP_STATUS_OK);
*response_headers = uiomux_append_headers (*response_headers);
}

static int
uiomux_body(int fd, http_request * request, params_t * request_headers, void * data)
{
char buf[4096];
int n, total = 0;
Expand All @@ -58,3 +78,9 @@ int uiomux_stream_body(int fd)

return total;
}

struct resource *
uiomux_resource (void)
{
return resource_new (uiomux_check, uiomux_head, uiomux_body, NULL);
}
6 changes: 2 additions & 4 deletions src/uiomux.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "resource.h"

#include "params.h"

params_t * uiomux_append_headers (params_t * response_headers);
int uiomux_stream_body (int fd);
struct resource * uiomux_resource (void);

0 comments on commit cfa5608

Please sign in to comment.