The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
authlistener.c
Go to the documentation of this file.
1 
23 #include <projectcommon.h>
24 #include <memory.h>
25 #include <glib.h>
26 #include <frame.h>
27 #include <frameset.h>
28 #define IS_LISTENER_SUBCLASS
29 #include <authlistener.h>
36 
38 
43 #define ONESEC 1000000
44 
46 FSTATIC gboolean
48 {
49  AuthListener* aself = CASTTOCLASS(AuthListener, self);
50  AuthListenerAction action;
51 
52  action = g_hash_table_lookup(aself->actionmap, GINT_TO_POINTER((int)fs->fstype));
53 
54  if (NULL == action) {
55  g_warning("%s received FrameSet of unrecognized type %u", __FUNCTION__, fs->fstype);
56  goto returnout;
57  }
59  action(aself, fs, addr);
60 
61 
62 
63 returnout:
64  if (aself->autoack) {
65  DUMP3("_authlistener_got_frameset: AutoACKing FrameSet", &fs->baseclass, NULL);
66  self->transport->_netio->ackmessage(self->transport->_netio, addr, fs);
67  }
68  UNREF(fs);
69  return TRUE;
70 }
71 FSTATIC void
73 {
74  AuthListener* self = CASTTOCLASS(AuthListener, lself);
75  GHashTableIter iter;
76  gpointer key;
77  gpointer value;
78  if (lself->transport) {
79  lself->dissociate(lself);
80  }
81  g_hash_table_iter_init(&iter, self->actionmap);
82  while (g_hash_table_iter_next(&iter, &key, &value)) {
83  guint16 fstype = GPOINTER_TO_INT(key);
84  transport->addListener(transport, fstype, lself);
85  }
86  lself->transport = transport;
87 }
88 FSTATIC void
90 {
91  AuthListener* self = CASTTOCLASS(AuthListener, lself);
92  GHashTableIter iter;
93  gpointer key;
94  gpointer value;
95  if (!lself->transport) {
96  return;
97  }
98  g_hash_table_iter_init(&iter, self->actionmap);
99  while (g_hash_table_iter_next(&iter, &key, &value)) {
100  guint16 fstype = GPOINTER_TO_INT(key);
101  lself->transport->addListener(lself->transport, fstype, NULL);
102  }
103  lself->transport = NULL;
104 }
105 
107 FSTATIC void
109 {
110  AuthListener* self = CASTTOCLASS(AuthListener, aself);
111  self->baseclass.dissociate(&self->baseclass);
112  if (self->actionmap) {
113  g_hash_table_destroy(self->actionmap);
114  self->actionmap = NULL;
115  }
116  _listener_finalize(aself);
117 }
118 
119 
123 authlistener_new(gsize objsize,
126  gboolean autoack)
127 {
128  AuthListener * newlistener;
130  if (objsize < sizeof(AuthListener)) {
131  objsize = sizeof(AuthListener);
132  }
133  newlistener = NEWSUBCLASS(AuthListener, listener_new(config, objsize));
134  if (newlistener != NULL) {
135  GHashTable* hash;
140  hash = g_hash_table_new(NULL, NULL);
141  for (; map->action; ++map) {
142  g_hash_table_insert(hash, GINT_TO_POINTER(map->framesettype), map->action);
143  }
144  newlistener->actionmap = hash;
145  newlistener->autoack = autoack;
146 
147 
148  }
149  return newlistener;
150 }
Listener baseclass
Definition: authlistener.h:42
AssimObj baseclass
Definition: frameset.h:46
int framesettype
FrameSet class type
Definition: authlistener.h:51
Structure associating FrameSet class types with actions to perform when they're received.
Definition: authlistener.h:50
Listener * listener_new(ConfigContext *config, gsize objsize)
Construct a new Listener - setting up GSource and timeout data structures for it. ...
Definition: listener.c:82
Implements minimal client-oriented Frame and Frameset capabilities.
FSTATIC void _authlistener_finalize(AssimObj *self)
Finalize a Listener.
Definition: authlistener.c:108
void(* AuthListenerAction)(AuthListener *, FrameSet *, NetAddr *)
Definition: authlistener.h:48
#define FSTATIC
Definition: projectcommon.h:31
FSTATIC void _authlistener_dissociate(Listener *self)
Definition: authlistener.c:89
guint16 fstype
Type of frameset.
Definition: frameset.h:51
#define BINDDEBUG(Cclass)
BINDDEBUG is for telling the class system where the debug variable for this class is - put it in the ...
Definition: proj_classes.h:82
#define __FUNCTION__
#define DUMP3(prefix, obj, suffix)
Definition: proj_classes.h:97
FSTATIC gboolean _authlistener_got_frameset(Listener *self, FrameSet *, NetAddr *)
Function called when a FrameSet class arrived from the given NetAddr class.
Definition: authlistener.c:47
This is the AuthListener class. object - which (authorizes and) obeys packets from the Authority...
Definition: authlistener.h:41
gboolean autoack
Definition: authlistener.h:44
Implements basic Frame class.
GHashTable * actionmap
Definition: authlistener.h:43
Project common header file.
NetGSource * transport
Definition: listener.h:44
FSTATIC void _authlistener_associate(Listener *self, NetGSource *transport)
Definition: authlistener.c:72
void(* addListener)(NetGSource *, guint16, Listener *)
Register a new listener.
Definition: netgsource.h:55
AuthListenerAction action
What to do when we get it.
Definition: authlistener.h:52
void(* _finalize)(AssimObj *)
Free object (private)
Definition: assimobj.h:55
The NetAddr class class represents a general network address - whether IP, MAC, or any other type of ...
Definition: netaddr.h:43
AuthListener * authlistener_new(gsize objsize, ObeyFrameSetTypeMap *map, ConfigContext *config, gboolean autoack)
Construct a new Listener - setting up GSource and timeout data structures for it. ...
Definition: authlistener.c:123
gboolean(* got_frameset)(Listener *self, FrameSet *fs, NetAddr *na)
called when a FrameSet arrives
Definition: listener.h:45
FrameSet class - used for collecting Frames when not on the wire, and for marshalling/demarshalling t...
Definition: frameset.h:45
struct _AuthListener AuthListener
Definition: authlistener.h:31
void(* dissociate)(Listener *self)
Dissociate us from our source.
Definition: listener.h:51
#define DEBUGDECLARATIONS
Definition: proj_classes.h:79
AssimObj baseclass
Definition: listener.h:42
void(* associate)(Listener *self, NetGSource *source)
NetGSource class to associate with
Definition: listener.h:49
Defines Listener interfaces for packets coming from the Collective Authority.
#define CASTTOCLASS(Cclass, obj)
Safely cast 'obj' to C-class 'class' - verifying that it was registerd as being of type class ...
Definition: proj_classes.h:66
#define UNREF(obj)
Definition: assimobj.h:35
The NetGSource class objects integrate NetIO class objects into the g_main_loop paradigm.
Definition: netgsource.h:43
#define NEWSUBCLASS(Cclass, obj)
Definition: proj_classes.h:67
This is the Listener class. object - which generically listens for packets.
Definition: listener.h:41
ReliableUDP * transport
Definition: pinger.c:67
void _listener_finalize(AssimObj *self)
Finalize a Listener.
Definition: listener.c:53