| 1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
|---|
| 2 |
|
|---|
| 3 |
/* Cherokee |
|---|
| 4 |
* |
|---|
| 5 |
* Authors: |
|---|
| 6 |
* Alvaro Lopez Ortega <alvaro@alobbs.com> |
|---|
| 7 |
* |
|---|
| 8 |
* Copyright (C) 2001-2008 Alvaro Lopez Ortega |
|---|
| 9 |
* |
|---|
| 10 |
* This program is free software; you can redistribute it and/or |
|---|
| 11 |
* modify it under the terms of version 2 of the GNU General Public |
|---|
| 12 |
* License as published by the Free Software Foundation. |
|---|
| 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, write to the Free Software |
|---|
| 21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|---|
| 22 |
* USA |
|---|
| 23 |
*/ |
|---|
| 24 |
|
|---|
| 25 |
#ifdef HAVE_CONFIG_H |
|---|
| 26 |
#include <config.h> |
|---|
| 27 |
#endif |
|---|
| 28 |
|
|---|
| 29 |
#include <string.h> |
|---|
| 30 |
#include <cherokee/cherokee.h> |
|---|
| 31 |
|
|---|
| 32 |
#define ERROR 1 |
|---|
| 33 |
#define WATCH_SLEEP 1000 |
|---|
| 34 |
|
|---|
| 35 |
#define CHECK_ERROR(msg) \ |
|---|
| 36 |
if (ret != ret_ok) { \ |
|---|
| 37 |
PRINT_ERROR_S (msg"\n"); \ |
|---|
| 38 |
return ERROR; \ |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
int |
|---|
| 42 |
main (int argc, char *argv[]) |
|---|
| 43 |
{ |
|---|
| 44 |
ret_t ret; |
|---|
| 45 |
cuint_t fds_num; |
|---|
| 46 |
cherokee_fdpoll_t *fdpoll; |
|---|
| 47 |
cherokee_admin_client_t *client; |
|---|
| 48 |
cherokee_buffer_t url; |
|---|
| 49 |
cherokee_list_t *i, *tmp; |
|---|
| 50 |
|
|---|
| 51 |
cuint_t port; |
|---|
| 52 |
cherokee_buffer_t buf; |
|---|
| 53 |
cherokee_list_t conns = LIST_HEAD_INIT(conns); |
|---|
| 54 |
|
|---|
| 55 |
if (argc <= 1) { |
|---|
| 56 |
PRINT_ERROR ("%s url request\n", argv[0]); |
|---|
| 57 |
return 1; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
/* Build everyhing |
|---|
| 61 |
*/ |
|---|
| 62 |
cherokee_sys_fdlimit_get (&fds_num); |
|---|
| 63 |
|
|---|
| 64 |
ret = cherokee_fdpoll_best_new (&fdpoll, fds_num, fds_num); |
|---|
| 65 |
if (ret != ret_ok) return ERROR; |
|---|
| 66 |
|
|---|
| 67 |
ret = cherokee_admin_client_new (&client); |
|---|
| 68 |
if (ret != ret_ok) return ERROR; |
|---|
| 69 |
|
|---|
| 70 |
/* Set the request |
|---|
| 71 |
*/ |
|---|
| 72 |
cherokee_buffer_init (&url); |
|---|
| 73 |
cherokee_buffer_add (&url, argv[1], strlen(argv[1])); |
|---|
| 74 |
|
|---|
| 75 |
/* Prepare the admin client object |
|---|
| 76 |
*/ |
|---|
| 77 |
ret = cherokee_admin_client_prepare (client, fdpoll, &url); |
|---|
| 78 |
if (ret != ret_ok) { |
|---|
| 79 |
PRINT_ERROR_S ("Client prepare failed\n"); |
|---|
| 80 |
return ERROR; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
ret = cherokee_admin_client_connect (client); |
|---|
| 84 |
if (ret != ret_ok) { |
|---|
| 85 |
PRINT_ERROR_S ("Couldn't connect\n"); |
|---|
| 86 |
return ERROR; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
/* Process it |
|---|
| 90 |
*/ |
|---|
| 91 |
cherokee_buffer_init (&buf); |
|---|
| 92 |
|
|---|
| 93 |
RUN_CLIENT1 (client, fdpoll, cherokee_admin_client_ask_port, &port); |
|---|
| 94 |
CHECK_ERROR ("port"); |
|---|
| 95 |
printf ("Port is %d\n", port); |
|---|
| 96 |
|
|---|
| 97 |
RUN_CLIENT1 (client, cherokee_admin_client_ask_port_tls, &port); |
|---|
| 98 |
CHECK_ERROR ("port_tls"); |
|---|
| 99 |
printf ("Port TLS is %d\n", port); |
|---|
| 100 |
|
|---|
| 101 |
RUN_CLIENT1 (client, cherokee_admin_client_ask_rx, &buf); |
|---|
| 102 |
CHECK_ERROR ("rx"); |
|---|
| 103 |
printf ("Server RX is %s\n", buf.buf); |
|---|
| 104 |
cherokee_buffer_clean (&buf); |
|---|
| 105 |
|
|---|
| 106 |
RUN_CLIENT1 (client, cherokee_admin_client_ask_tx, &buf); |
|---|
| 107 |
CHECK_ERROR ("tx"); |
|---|
| 108 |
printf ("Server TX is %s\n", buf.buf); |
|---|
| 109 |
|
|---|
| 110 |
RUN_CLIENT1 (client, fdpoll, cherokee_admin_client_ask_connections, &conns); |
|---|
| 111 |
CHECK_ERROR ("conns"); |
|---|
| 112 |
|
|---|
| 113 |
{ |
|---|
| 114 |
list_for_each (i, &conns) { |
|---|
| 115 |
cherokee_connection_info_t *conn = CONN_INFO(i); |
|---|
| 116 |
|
|---|
| 117 |
printf ("Request: '%s', phase: '%s', rx: '%s', tx: '%s', size: '%s'\n", |
|---|
| 118 |
conn->request.buf, conn->phase.buf, conn->rx.buf, |
|---|
| 119 |
conn->tx.buf, conn->total_size.buf); |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
list_for_each_safe (i, tmp, &conns) { |
|---|
| 124 |
cherokee_connection_info_free (CONN_INFO(i)); |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
cherokee_buffer_mrproper (&buf); |
|---|
| 128 |
|
|---|
| 129 |
/* Clean up |
|---|
| 130 |
*/ |
|---|
| 131 |
cherokee_admin_client_free (client); |
|---|
| 132 |
cherokee_fdpoll_free (fdpoll); |
|---|
| 133 |
|
|---|
| 134 |
return 0; |
|---|
| 135 |
} |
|---|