mirror of
https://github.com/jorisvink/kore
synced 2025-03-13 22:39:01 -04:00
Prototypes: int http_argument_multiple_lookup(struct http_req *req, struct http_arg *args); void http_argument_multiple_free(struct http_arg *args); These functions can be used to lookup arguments in a single call. args points to an array of struct http_arg elements. Each of them have the argument name set and its value set to NULL. The array must have its last element name field set to NULL. Upon return http_argument_multiple_lookup() gives the caller the number of arguments that were successfully found. It makes their values available under the value field in the struct http_arg array passed. Example: int v; struct http_args args[4]; memset(args, 0, sizeof(args)); args[0].name = "email"; args[1].name = "password1"; args[2].name = "password2"; args[3].name = NULL; v = http_argument_multiple_lookup(req, args); if (v != 3) { kore_debug("argument %s was not present", args[v].name); } else { for (v = 0; args[v].name != NULL; v++) kore_debug("%s -> %s", args[v].name, args[v].value); } http_argument_multiple_free(args);
91 lines
2.6 KiB
C
91 lines
2.6 KiB
C
/*
|
|
* Copyright (c) 2013 Joris Vink <joris@coders.se>
|
|
*
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
* copyright notice and this permission notice appear in all copies.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
|
|
#ifndef __H_HTTP_H
|
|
#define __H_HTTP_H
|
|
|
|
#define HTTP_HEADER_MAX_LEN 4096
|
|
#define HTTP_URI_LEN 2000
|
|
#define HTTP_USERAGENT_LEN 256
|
|
#define HTTP_REQ_HEADER_MAX 25
|
|
#define HTTP_MAX_QUERY_ARGS 10
|
|
|
|
struct http_header {
|
|
char *header;
|
|
char *value;
|
|
|
|
TAILQ_ENTRY(http_header) list;
|
|
};
|
|
|
|
struct http_arg {
|
|
char *name;
|
|
char *value;
|
|
|
|
TAILQ_ENTRY(http_arg) list;
|
|
};
|
|
|
|
#define HTTP_METHOD_GET 0
|
|
#define HTTP_METHOD_POST 1
|
|
|
|
#define HTTP_REQUEST_COMPLETE 0x01
|
|
#define HTTP_REQUEST_DELETE 0x02
|
|
|
|
struct http_request {
|
|
u_int8_t method;
|
|
u_int8_t flags;
|
|
int status;
|
|
u_int64_t start;
|
|
u_int64_t end;
|
|
char host[KORE_DOMAINNAME_LEN];
|
|
char path[HTTP_URI_LEN];
|
|
char *agent;
|
|
struct connection *owner;
|
|
struct spdy_stream *stream;
|
|
struct kore_buf *post_data;
|
|
|
|
TAILQ_HEAD(, http_header) req_headers;
|
|
TAILQ_HEAD(, http_header) resp_headers;
|
|
TAILQ_HEAD(, http_arg) arguments;
|
|
TAILQ_ENTRY(http_request) list;
|
|
};
|
|
|
|
extern int http_request_count;
|
|
|
|
void http_init(void);
|
|
void http_process(void);
|
|
time_t http_date_to_time(char *);
|
|
void http_request_free(struct http_request *);
|
|
int http_response(struct http_request *, int,
|
|
u_int8_t *, u_int32_t);
|
|
int http_request_header_get(struct http_request *, char *, char **);
|
|
void http_response_header_add(struct http_request *, char *, char *);
|
|
int http_request_new(struct connection *, struct spdy_stream *,
|
|
char *, char *, char *, struct http_request **);
|
|
|
|
int http_generic_404(struct http_request *);
|
|
int http_header_recv(struct netbuf *);
|
|
char *http_post_data_text(struct http_request *);
|
|
int http_populate_arguments(struct http_request *);
|
|
void http_argument_multiple_free(struct http_arg *);
|
|
int http_argument_lookup(struct http_request *,
|
|
const char *, char **);
|
|
int http_argument_multiple_lookup(struct http_request *,
|
|
struct http_arg *);
|
|
|
|
void kore_accesslog(struct http_request *);
|
|
|
|
#endif /* !__H_HTTP_H */
|