~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to tools/gsoap/gsoap-linux-2.7/plugin/.svn/text-base/logging.c.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
logging.c
4
 
 
5
 
Message logging plugin for webserver.
6
 
 
7
 
gSOAP XML Web services tools
8
 
Copyright (C) 2004-2005, Robert van Engelen, Genivia, Inc. All Rights Reserved.
9
 
 
10
 
--------------------------------------------------------------------------------
11
 
This program is free software; you can redistribute it and/or modify it under
12
 
the terms of the GNU General Public License as published by the Free Software
13
 
Foundation; either version 2 of the License, or (at your option) any later
14
 
version.
15
 
 
16
 
This program is distributed in the hope that it will be useful, but WITHOUT ANY
17
 
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
18
 
PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
 
 
20
 
You should have received a copy of the GNU General Public License along with
21
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22
 
Place, Suite 330, Boston, MA 02111-1307 USA
23
 
 
24
 
Author contact information:
25
 
engelen@genivia.com / engelen@acm.org
26
 
--------------------------------------------------------------------------------
27
 
*/
28
 
 
29
 
#include "logging.h"
30
 
 
31
 
const char logging_id[] = LOGGING_ID;
32
 
 
33
 
static int logging_init(struct soap *soap, struct logging_data *data);
34
 
static void logging_delete(struct soap *soap, struct soap_plugin *p);
35
 
static int logging_send(struct soap *soap, const char *buf, size_t len);
36
 
static size_t logging_recv(struct soap *soap, char *buf, size_t len);
37
 
 
38
 
int logging(struct soap *soap, struct soap_plugin *p, void *arg)
39
 
{ p->id = logging_id;
40
 
  p->data = (void*)malloc(sizeof(struct logging_data));
41
 
  p->fdelete = logging_delete;
42
 
  if (p->data)
43
 
    if (logging_init(soap, (struct logging_data*)p->data))
44
 
    { free(p->data); /* error: could not init */
45
 
      return SOAP_EOM; /* return error */
46
 
    }
47
 
  return SOAP_OK;
48
 
}
49
 
 
50
 
static int logging_init(struct soap *soap, struct logging_data *data)
51
 
{ data->inbound = NULL;
52
 
  data->outbound = NULL;
53
 
  data->stat_sent = 0;
54
 
  data->stat_recv = 0;
55
 
  data->fsend = soap->fsend; /* save old recv callback */
56
 
  data->frecv = soap->frecv; /* save old send callback */
57
 
  soap->fsend = logging_send; /* replace send callback with ours */
58
 
  soap->frecv = logging_recv; /* replace recv callback with ours */
59
 
  return SOAP_OK;
60
 
}
61
 
 
62
 
static void logging_delete(struct soap *soap, struct soap_plugin *p)
63
 
{ free(p->data); /* free allocated plugin data. If fcopy() is not set, then this function is not called for all copies of the plugin created with soap_copy(). In this example, the fcopy() callback is omitted and the plugin data is shared by the soap copies created with soap_copy() */
64
 
}
65
 
 
66
 
static size_t logging_recv(struct soap *soap, char *buf, size_t len)
67
 
{ struct logging_data *data = (struct logging_data*)soap_lookup_plugin(soap, logging_id);
68
 
  size_t res = data->frecv(soap, buf, len); /* get data from old recv callback */
69
 
  data->stat_recv += res;
70
 
  /* update should be in mutex, but we don't mind some inaccuracy in the count */
71
 
  if (data->inbound)
72
 
    fwrite(buf, res, 1, data->inbound);
73
 
  return res;
74
 
}
75
 
 
76
 
static int logging_send(struct soap *soap, const char *buf, size_t len)
77
 
{ struct logging_data *data = (struct logging_data*)soap_lookup_plugin(soap, logging_id);
78
 
  /* update should be in mutex, but we don't mind some inaccuracy in the count */
79
 
  data->stat_sent += len;
80
 
  if (data->outbound)
81
 
    fwrite(buf, len, 1, data->outbound);
82
 
  return data->fsend(soap, buf, len); /* pass data on to old send callback */
83
 
}
84