~ubuntu-branches/ubuntu/trusty/gdis/trusty

« back to all changes in this revision

Viewing changes to logging.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Leidert (dale)
  • Date: 2009-04-06 17:12:18 UTC
  • mfrom: (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090406171218-uizoe126jrq09ytt
Tags: 0.90-1
* New upstream release 0.90.
* Acknowledge NMU (closes: #492994). Thanks to Neil Williams.

* makefile.debian: Upstream doesn't provide a Makefile to edit - so created
  our own.
* debian/compat: Added and set to be 5.
* debian/control: Added Homepage, Vcs* and DM-Upload-Allowed fields.
  (Maintainer): Set to the debichem team with approval by Noèl.
  (Uploaders): Added myself.
  (Build-Depends): Increased debhelper version to 5. Removed glutg3-dev.
  Added dpatch.
  (Standards-Version): Bumped to 3.8.1.
  (Description): Removed homepage. Fixed a typo.
* debian/copyright: Updated, completed and adjusted.
* debian/dirs: Dropped useless file.
* debian/docs: Renamed to debian/gdis.docs.
* debian/menu: Renamed to debian/gdis.menu.
  (section): Fixed accordingly to policy.
* debian/gdis.1: Just some formatting changes.
* debian/gdis.desktop: Added file (with small fixes) provided by Phill Bull
  (LP: #111353).
* debian/gdis.install: Added.
* debian/rules: Cleaned. Installation is now done by dh_install. Make sure,
  the CVS directory is not copied. Added dh_desktop call.
* debian/source.lintian-overrides: makefile.debian is created for Debian but
  lives outside debian/.
* debian/watch: Added.
* debian/README.build: Dropped.
* debian/README.source: Added to be compliant to the policy v3.8.
* debian/patches/Debian_make.dpatch: Added.
  - gdis.h (ELEM_FILE): Moved fix for gdis.elemts path (#399132) to this
    patch.
* debian/patches/00list: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        logging.c
 
3
 
 
4
        Message logging plugin and stat collector for webserver.
 
5
 
 
6
        Register the plugin with:
 
7
                soap_register_plugin(soap, logging);
 
8
 
 
9
        Change logging destinations:
 
10
                soap_set_logging_inbound(struct soap*, FILE*);
 
11
                soap_set_logging_outbound(struct soap*, FILE*);
 
12
 
 
13
        Obtain stats (sent and recv octet count, independent of log dest):
 
14
                soap_get_logging_stats(soap, size_t *sent, size_t *recv);
 
15
 
 
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
--------------------------------------------------------------------------------
 
21
gSOAP public license.
 
22
 
 
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.
 
30
 
 
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
--------------------------------------------------------------------------------
 
34
GPL license.
 
35
 
 
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
 
39
version.
 
40
 
 
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.
 
44
 
 
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
 
48
 
 
49
Author contact information:
 
50
engelen@genivia.com / engelen@acm.org
 
51
 
 
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
--------------------------------------------------------------------------------
 
57
*/
 
58
 
 
59
#include "logging.h"
 
60
 
 
61
#ifdef __cplusplus
 
62
extern "C" {
 
63
#endif
 
64
 
 
65
const char logging_id[] = LOGGING_ID;
 
66
 
 
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);
 
71
 
 
72
/* plugin registry function, invoked by soap_register_plugin */
 
73
int logging(struct soap *soap, struct soap_plugin *p, void *arg)
 
74
{ p->id = logging_id;
 
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 */
 
80
  if (p->data)
 
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 */
 
84
    }
 
85
  }
 
86
  return SOAP_OK;
 
87
}
 
88
 
 
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);
 
92
  if (data)
 
93
    data->inbound = fd;
 
94
}
 
95
 
 
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);
 
99
  if (data)
 
100
    data->outbound = fd;
 
101
}
 
102
 
 
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);
 
106
  if (data)
 
107
  { *sent = data->stat_sent;
 
108
    *recv = data->stat_recv;
 
109
  }
 
110
}
 
111
 
 
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;
 
116
  data->stat_sent = 0;
 
117
  data->stat_recv = 0;
 
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 */
 
122
  return SOAP_OK;
 
123
}
 
124
 
 
125
static void logging_delete(struct soap *soap, struct soap_plugin *p)
 
126
 
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);
 
132
}
 
133
 
 
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);
 
136
  size_t res;
 
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;
 
141
  if (data->inbound)
 
142
    fwrite(buf, res, 1, data->inbound);
 
143
  return res;
 
144
}
 
145
 
 
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;
 
150
  if (data->outbound)
 
151
    fwrite(buf, len, 1, data->outbound);
 
152
  return data->fsend(soap, buf, len); /* pass data on to old send callback */
 
153
}
 
154
 
 
155
#ifdef __cplusplus
 
156
}
 
157
#endif
 
158