4
Message logging plugin and stat collector for webserver.
6
Register the plugin with:
7
soap_register_plugin(soap, logging);
9
Change logging destinations:
10
soap_set_logging_inbound(struct soap*, FILE*);
11
soap_set_logging_outbound(struct soap*, FILE*);
13
Obtain stats (sent and recv octet count, independent of log dest):
14
soap_get_logging_stats(soap, size_t *sent, size_t *recv);
16
gSOAP XML Web services tools
17
Copyright (C) 2000-2008, Robert van Engelen, Genivia Inc., All Rights Reserved.
18
This part of the software is released under one of the following licenses:
19
GPL, the gSOAP public license, or Genivia's license for commercial use.
20
--------------------------------------------------------------------------------
23
The contents of this file are subject to the gSOAP Public License Version 1.3
24
(the "License"); you may not use this file except in compliance with the
25
License. You may obtain a copy of the License at
26
http://www.cs.fsu.edu/~engelen/soaplicense.html
27
Software distributed under the License is distributed on an "AS IS" basis,
28
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
29
for the specific language governing rights and limitations under the License.
31
The Initial Developer of the Original Code is Robert A. van Engelen.
32
Copyright (C) 2000-2008, Robert van Engelen, Genivia Inc., All Rights Reserved.
33
--------------------------------------------------------------------------------
36
This program is free software; you can redistribute it and/or modify it under
37
the terms of the GNU General Public License as published by the Free Software
38
Foundation; either version 2 of the License, or (at your option) any later
41
This program is distributed in the hope that it will be useful, but WITHOUT ANY
42
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
43
PARTICULAR PURPOSE. See the GNU General Public License for more details.
45
You should have received a copy of the GNU General Public License along with
46
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
47
Place, Suite 330, Boston, MA 02111-1307 USA
49
Author contact information:
50
engelen@genivia.com / engelen@acm.org
52
This program is released under the GPL with the additional exemption that
53
compiling, linking, and/or using OpenSSL is allowed.
54
--------------------------------------------------------------------------------
55
A commercial use license is available from Genivia, Inc., contact@genivia.com
56
--------------------------------------------------------------------------------
65
const char logging_id[] = LOGGING_ID;
67
static int logging_init(struct soap *soap, struct logging_data *data);
68
static void logging_delete(struct soap *soap, struct soap_plugin *p);
69
static int logging_send(struct soap *soap, const char *buf, size_t len);
70
static size_t logging_recv(struct soap *soap, char *buf, size_t len);
72
/* plugin registry function, invoked by soap_register_plugin */
73
int logging(struct soap *soap, struct soap_plugin *p, void *arg)
75
/* create local plugin data */
76
p->data = (void*)SOAP_MALLOC(soap, sizeof(struct logging_data));
77
/* register the destructor */
78
p->fdelete = logging_delete;
79
/* if OK then initialize */
81
{ if (logging_init(soap, (struct logging_data*)p->data))
82
{ SOAP_FREE(soap, p->data); /* error: could not init */
83
return SOAP_EOM; /* return error */
89
/* set inbound logging FD, NULL to disable */
90
void soap_set_logging_inbound(struct soap *soap, FILE *fd)
91
{ struct logging_data *data = (struct logging_data*)soap_lookup_plugin(soap, logging_id);
96
/* set outbound logging FD, NULL to disable */
97
void soap_set_logging_outbound(struct soap *soap, FILE *fd)
98
{ struct logging_data *data = (struct logging_data*)soap_lookup_plugin(soap, logging_id);
103
/* get logging sent and recv octet counts */
104
void soap_get_logging_stats(struct soap *soap, size_t *sent, size_t *recv)
105
{ struct logging_data *data = (struct logging_data*)soap_lookup_plugin(soap, logging_id);
107
{ *sent = data->stat_sent;
108
*recv = data->stat_recv;
112
/* used by plugin registry function */
113
static int logging_init(struct soap *soap, struct logging_data *data)
114
{ data->inbound = NULL;
115
data->outbound = NULL;
118
data->fsend = soap->fsend; /* save old recv callback */
119
data->frecv = soap->frecv; /* save old send callback */
120
soap->fsend = logging_send; /* replace send callback with ours */
121
soap->frecv = logging_recv; /* replace recv callback with ours */
125
static void logging_delete(struct soap *soap, struct soap_plugin *p)
127
/* free allocated plugin data. If fcopy() is not set, then this function is
128
not called for all copies of the plugin created with soap_copy(). In this
129
example, the fcopy() callback is omitted and the plugin data is shared by
130
the soap copies created with soap_copy() */
131
SOAP_FREE(soap, p->data);
134
static size_t logging_recv(struct soap *soap, char *buf, size_t len)
135
{ struct logging_data *data = (struct logging_data*)soap_lookup_plugin(soap, logging_id);
137
/* get data from old recv callback */
138
res = data->frecv(soap, buf, len);
139
/* update should be in mutex, but we don't mind some inaccuracy in stats */
140
data->stat_recv += res;
142
fwrite(buf, res, 1, data->inbound);
146
static int logging_send(struct soap *soap, const char *buf, size_t len)
147
{ struct logging_data *data = (struct logging_data*)soap_lookup_plugin(soap, logging_id);
148
/* update should be in mutex, but we don't mind some inaccuracy in stats */
149
data->stat_sent += len;
151
fwrite(buf, len, 1, data->outbound);
152
return data->fsend(soap, buf, len); /* pass data on to old send callback */