Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
generic_rpc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 2013 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __GENERIC_RPC_H__
20 #define __GENERIC_RPC_H__
21 
22 #include "alist.h"
23 
24 #include <glib.h>
25 #include <pthread.h>
26 #include <stdsoap2.h>
27 
28 typedef enum {
32 
33 #define generic_rpc_argp_header "Generic RPC Server Options"
34 extern struct argp generic_rpc_argp;
35 
36 extern char *GENERIC_RPC_TMPDIR;
37 
39  char *name;
40 
41  /*
42  * State for the siginfowait thread.
43  */
44  sigset_t sigset;
45 
46  int port;
47 
48  /*
49  * Functions.
50  */
51  int (*handle_request)(struct soap *soap);
52 };
53 
54 /*
55  * We support a sort of strange listener API. Basically, we want to
56  * expose not a multiplicity of listener interfaces, but rather a
57  * per-service interface. However, each service might offer multiple
58  * object types and event types on those objects.
59  *
60  * Eventually, we will allow per-listener filtering, but for now, all we
61  * care about is ownership. Listener RPCs usually return something that
62  * affects the service object being listened to; so there can only be
63  * one authoritative listener that has control. The server *must* wait
64  * for a response (for a very long timeout) from the authoritative
65  * listener; but it must not block on any other listeners unduly.
66  *
67  * For many reasons, it is complicated to have one listener own a probe,
68  * but have another listener own that probe's target. The primary
69  * reason is that probe IDs are only unique to the target; they are not
70  * unique per VMI process. That would require us to coordinate probe Id
71  * assignment between any target served by the server. This is fine if
72  * all targets are thread-backed, because we share the VMI process's
73  * address space; but since some targets can be forked, we can't do it.
74  *
75  * So, for now, a target's owning listener also owns its probes and
76  * actions. This probably will never matter, so leave it this way in
77  * this "generic" listener model.
78  */
79 
81  /* The listener ID. */
82  int id;
83 
84  /* The RPC type the listener supports. */
86 
87  uint8_t is_dynamic:1;
88 
89  /* A table of objids it is listening to; values are always NULL. */
90  GHashTable *objid_tab;
91 
92  /*
93  * An already-connected soap struct. We try to use this if non-NULL
94  * -- but only if it is still live. We also only stash it if it
95  * supports HTTP keep-alives.
96  */
97  struct soap soap;
98 
99  int errors;
100 
101  /*
102  * The listener endpoint.
103  */
104  char *url;
105 };
106 
108  int is_owner,void *data);
109 
110 void generic_rpc_init(void);
111 void generic_rpc_fini(void);
112 
115 
116 int generic_rpc_serve(struct generic_rpc_config *cfg);
117 /*
118  * A generic handler that detaches the pthread, calls soap_serve, and
119  * destroys the soap context when finished.
120  */
122 
123 struct generic_rpc_listener *
125 struct generic_rpc_listener *
127 
130 
132 
135  void *data);
136 
137 
140 
142  int objid,int owns);
144  int objid);
145 
146 /*
147  * We need to proxy requests, but we cannot use listener IDs with
148  * proxied requests because listeners are not only bound to one object!
149  * So -- we don't know where to proxy the listener *to* (at least not
150  * until it's bound). So, dynamically "insert" listeners as needed, and
151  * garbage-collect them as needed.
152  */
154  int objid,int owns);
156  int objid);
157 
159 
160 struct xsd__hexBinary *
161 generic_rpc_read_file_into_hexBinary(struct soap *soap,
162  char *filename,int max_size);
163 
164 #define __SAFE_IO(fn,fns,fd,buf,buflen,rc) { \
165  char *_p; \
166  int _rc = 0; \
167  int _left; \
168  \
169  _p = (char *)(buf); \
170  _left = (buflen); \
171  \
172  while (_left) { \
173  _rc = fn((fd),_p,_left); \
174  if (_rc < 0) { \
175  if (errno != EINTR) { \
176  vwarn(fns "(%d,%d): %s\n", \
177  fd,buflen,strerror(errno)); \
178  break; \
179  } \
180  else { \
181  verror(fns "(%d,%d): %s\n", \
182  fd,buflen,strerror(errno)); \
183  } \
184  } \
185  else if (_rc == 0) { \
186  break; \
187  } \
188  else { \
189  _left -= _rc; \
190  _p += _rc; \
191  (rc) += _rc; \
192  } \
193  } \
194  /*vwarn("%d bytes of %d iopd\n",(buflen)-_left,(buflen));*/ \
195 }
196 
197 #endif /* __GENERIC_RPC_H__ */
GHashTable * objid_tab
Definition: generic_rpc.h:90
int( generic_rpc_listener_notifier_t)(struct generic_rpc_listener *l, int is_owner, void *data)
Definition: generic_rpc.h:107
void generic_rpc_register_svctype(rpc_svctype_t svctype)
Definition: generic_rpc.c:139
void generic_rpc_fini(void)
Definition: generic_rpc.c:104
rpc_svctype_t svctype
Definition: generic_rpc.h:85
void generic_rpc_unregister_svctype(rpc_svctype_t svctype)
Definition: generic_rpc.c:195
int generic_rpc_bind_listener_objid(rpc_svctype_t svctype, int listener_id, int objid, int owns)
Definition: generic_rpc.c:743
int generic_rpc_handle_request(struct soap *soap)
Definition: generic_rpc.c:266
int generic_rpc_listener_notify_all(rpc_svctype_t svctype, int objid, generic_rpc_listener_notifier_t *notifier, void *data)
Definition: generic_rpc.c:902
int generic_rpc_unbind_all_listeners_objid(rpc_svctype_t svctype, int objid)
Definition: generic_rpc.c:733
int generic_rpc_unbind_listener_objid(rpc_svctype_t svctype, int listener_id, int objid)
Definition: generic_rpc.c:680
struct soap soap
Definition: generic_rpc.h:97
int generic_rpc_insert_listener(rpc_svctype_t svctype, char *url)
Definition: generic_rpc.c:535
int generic_rpc_unbind_dynlistener_objid(rpc_svctype_t svctype, char *listener_url, int objid)
Definition: generic_rpc.c:864
rpc_svctype_t
Definition: generic_rpc.h:28
struct generic_rpc_listener * generic_rpc_lookup_listener_url(rpc_svctype_t svctype, char *url)
Definition: generic_rpc.c:467
struct generic_rpc_listener * generic_rpc_lookup_listener_id(rpc_svctype_t svctype, int listener_id)
Definition: generic_rpc.c:488
struct xsd__hexBinary * generic_rpc_read_file_into_hexBinary(struct soap *soap, char *filename, int max_size)
Definition: generic_rpc.c:981
int generic_rpc_remove_listener(rpc_svctype_t svctype, int listener_id)
Definition: generic_rpc.c:608
int generic_rpc_serve(struct generic_rpc_config *cfg)
Definition: generic_rpc.c:349
int generic_rpc_bind_dynlistener_objid(rpc_svctype_t svctype, char *listener_url, int objid, int owns)
Definition: generic_rpc.c:804
int generic_rpc_count_listeners(rpc_svctype_t svctype, int objid)
Definition: generic_rpc.c:880
int(* handle_request)(struct soap *soap)
Definition: generic_rpc.h:51
struct argp generic_rpc_argp
Definition: generic_rpc.c:261
char * GENERIC_RPC_TMPDIR
Definition: generic_rpc.c:52
void generic_rpc_init(void)
Definition: generic_rpc.c:69