1/* 2 neon-specific test utils 3 Copyright (C) 2001-2008, Joe Orton <joe@manyfish.co.uk> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 19*/ 20 21#ifndef UTILS_H 22#define UTILS_H 1 23 24#include "ne_request.h" 25 26#include "child.h" 27 28#define ONREQ(x) do { int _ret = (x); if (_ret) { t_context("line %d: HTTP error:\n%s", __LINE__, ne_get_error(sess)); return FAIL; } } while (0); 29 30int single_serve_string(ne_socket *s, void *userdata); 31 32struct many_serve_args { 33 int count; 34 const char *str; 35}; 36 37/* Serves args->str response args->count times down a single 38 * connection. */ 39int many_serve_string(ne_socket *s, void *userdata); 40 41/* Run a request using URI on the session. */ 42int any_request(ne_session *sess, const char *uri); 43 44/* Run a request using URI on the session; fail on a non-2xx response. 45 */ 46int any_2xx_request(ne_session *sess, const char *uri); 47 48/* As above but with a request body. */ 49int any_2xx_request_body(ne_session *sess, const char *uri); 50 51/* makes *session, spawns server which will run 'fn(userdata, 52 * socket)'. sets error context if returns non-zero, i.e use like: 53 * CALL(make_session(...)); */ 54int make_session(ne_session **sess, server_fn fn, void *userdata); 55 56/* Server which sleeps for 10 seconds then closes the socket. */ 57int sleepy_server(ne_socket *sock, void *userdata); 58 59struct string { 60 char *data; 61 size_t len; 62}; 63 64struct double_serve_args { 65 struct string first, second; 66}; 67 68/* Serve a struct string. */ 69int serve_sstring(ne_socket *sock, void *ud); 70 71/* Discards an HTTP request, serves response ->first, discards another 72 * HTTP request, then serves response ->second. */ 73int double_serve_sstring(ne_socket *s, void *userdata); 74 75/* Serve a struct string slowly. */ 76int serve_sstring_slowly(ne_socket *sock, void *ud); 77 78struct infinite { 79 const char *header, *repeat; 80}; 81 82/* Pass a "struct infinite *" as userdata, this function sends 83 * ->header and then loops sending ->repeat forever. */ 84int serve_infinite(ne_socket *sock, void *ud); 85 86/* SOCKS server stuff. */ 87struct socks_server { 88 enum ne_sock_sversion version; 89 enum socks_failure { 90 fail_none = 0, 91 fail_init_vers, 92 fail_init_close, 93 fail_init_trunc, 94 fail_no_auth, 95 fail_bogus_auth, 96 fail_auth_close, 97 fail_auth_denied 98 } failure; 99 unsigned int expect_port; 100 ne_inet_addr *expect_addr; 101 const char *expect_fqdn; 102 const char *username; 103 const char *password; 104 int say_hello; 105 server_fn server; 106 void *userdata; 107}; 108 109int socks_server(ne_socket *sock, void *userdata); 110 111int full_write(ne_socket *sock, const char *data, size_t len); 112 113#endif /* UTILS_H */ 114