source: src/router/httpd/httpd.h @ 32014

Last change on this file since 32014 was 32014, checked in by brainslayer, 2 weeks ago

fix handler

File size: 4.9 KB
Line 
1/*
2 * milli_httpd - pretty small HTTP server
3 *
4 * Copyright 2001-2003, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
11 *
12 * $Id: httpd.h,v 1.2 2005/11/24 19:38:45 seg Exp $
13 */
14
15#include <cy_conf.h>
16#ifndef _httpd_h_
17#define _httpd_h_
18
19#if defined(DEBUG) && defined(DMALLOC)
20#include <dmalloc.h>
21#endif
22
23#ifdef HAVE_MATRIXSSL
24#define DDWRT
25#include <matrixSsl.h>
26#include <matrixssl_xface.h>
27#endif
28
29#ifdef HAVE_OPENSSL
30#include <ssl.h>
31extern BIO *bio_err;
32#endif
33
34#include <bcmnvram.h>
35
36typedef struct {
37        FILE *fp;
38        int userid;
39} webs;
40
41typedef webs *webs_t;
42
43extern char *wfgets(char *buf, int len, webs_t fp);
44extern int wfprintf(webs_t fp, char *fmt, ...);
45extern size_t wfwrite(char *buf, int size, int n, webs_t fp);
46extern size_t wfread(char *buf, int size, int n, webs_t fp);
47extern int wfclose(webs_t fp);
48extern int wfflush(webs_t fp);
49#ifndef VALIDSOURCE
50#ifndef VISUALSOURCE
51
52extern int wfputs(char *buf, webs_t fp);
53#endif
54#endif
55#ifdef HAVE_HTTPS
56extern int do_ssl;
57#endif
58/* Basic authorization userid and passwd limit */
59#define AUTH_MAX 64
60
61extern char auth_realm[AUTH_MAX];
62extern void send_authenticate(char *realm);
63
64/* Generic MIME type handler */
65struct mime_handler {
66        char *pattern;
67        char *mime_type;
68        char *extra_header;
69        void (*input) (char *path, webs_t stream, int len, char *boundary);
70        void (*output) (char *method, struct mime_handler * handler, char *path, webs_t stream, char *query);
71        int (*auth) (webs_t wp, char *userid, char *passwd, char *realm, char *authorisation, int (*auth_check) (char *userid, char *passwd, char *dirname, char *authorisation));
72        unsigned char send_headers;
73        unsigned char handle_options;
74};
75
76typedef struct {
77        const char *path;       /* Web page URL path */
78        unsigned int size;      /* Size of web page in bytes */
79} websRomPageIndexType;
80
81//extern void setLength(long len);
82
83extern struct mime_handler mime_handlers[];
84
85/* CGI helper functions */
86extern void init_cgi(char *query);
87extern char *get_cgi(char *name);
88extern void set_cgi(char *name, char *value);
89extern int count_cgi();
90
91/* Regular file handler */
92extern void do_file(char *method, struct mime_handler *handler, char *path, webs_t stream, char *query);
93extern void do_file_attach(struct mime_handler *handler, char *path, webs_t stream, char *query, char *attachment);
94
95/* GoAhead 2.1 compatibility */
96//typedef FILE * webs_t;
97typedef char char_t;
98#define T(s) (s)
99#define __TMPVAR(x) tmpvar ## x
100#define _TMPVAR(x) __TMPVAR(x)
101#define TMPVAR _TMPVAR(__LINE__)
102
103#define websDebugWrite(wp, fmt, args...)
104#define websError(wp, code, msg, args...)
105
106#define websHeader(wp) wfputs("<html lang=\"en\">", wp)
107#define websFooter(wp) wfputs("</html>", wp)
108#define websDone(wp, code) wfflush(wp)
109
110#ifndef VALIDSOURCE
111#ifndef VISUALSOURCE
112char *websGetVar(webs_t wp, char *var, char *d);
113#endif
114#endif
115
116struct Webenvironment {
117        void (*Pdo_ej_buffer) (char *buffer, webs_t stream);
118        int (*Phttpd_filter_name) (char *old_name, char *new_name, size_t size, int type);
119        char *(*PwebsGetVar) (webs_t wp, char *var, char *d);
120        int (*PwebsWrite) (webs_t wp, char *fmt, ...);
121        struct wl_client_mac *Pwl_client_macs;
122        void (*Pdo_ej) (char *method, struct mime_handler * handler, char *path, webs_t stream, char *query);   // jimmy, https, 8/4/2003
123        int (*PejArgs) (int argc, char_t ** argv, char_t * fmt, ...);
124        FILE *(*PgetWebsFile) (char *path);
125        int (*Pwfputs) (char *buf, webs_t fp);
126        char *(*PGOZILA_GET) (webs_t wp, char *name);
127        char *(*Plive_translate) (const char *tran);
128        void (*Pvalidate_cgi) (webs_t fp);
129        websRomPageIndexType *PwebsRomPageIndex;
130        char *Prequest_url;
131#ifdef HAVE_HTTPS
132        int Pdo_ssl;
133#endif
134};
135
136#define websSetVar(wp, var, value) set_cgi(var, value)
137#define websDefaultHandler(wp, urlPrefix, webDir, arg, url, path, query) ({ do_ej(method, path, wp,""); fflush(wp); 1; })
138#define websWriteData(wp, buf, nChars) ({ int TMPVAR = wfwrite(buf, 1, nChars, wp); wfflush(wp); TMPVAR; })
139#define websWriteDataNonBlock websWriteData
140#define a_assert(a)
141
142/* GoAhead 2.1 Embedded JavaScript compatibility */
143extern int getWebsFileLen(char *path);
144
145#ifndef VISUALSOURCE
146#ifndef VALIDSOURCE
147extern FILE *getWebsFile(char *path);
148extern int ejArgs(int argc, char_t ** argv, char_t * fmt, ...);
149extern void do_ej(char *method, struct mime_handler *handler, char *path, webs_t stream, char *query);
150extern void do_ej_buffer(char *buffer, webs_t stream);
151extern int websWrite(webs_t wp, char *fmt, ...);
152#endif
153#endif
154int do_auth(webs_t wp, char *userid, char *passwd, char *realm, char *authorisation, int (*auth_check) (char *userid, char *passwd, char *dirname, char *authorisation));
155void Initnvramtab(void);
156void *call_ej(char *name, void *handle, webs_t wp, int argc, char_t ** argv);
157
158#endif                          /* _httpd_h_ */
Note: See TracBrowser for help on using the repository browser.