Added dynamic protocol registering/unregistering support. The
authorPekka Riikonen <priikone@silcnet.org>
Thu, 20 Jul 2000 10:17:25 +0000 (10:17 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 20 Jul 2000 10:17:25 +0000 (10:17 +0000)
patch was provided by cras.

CHANGES
apps/silc/client.c
apps/silc/protocol.c
apps/silc/protocol.h
apps/silcd/protocol.c
apps/silcd/protocol.h
apps/silcd/server.c
lib/silccore/silcprotocol.c
lib/silccore/silcprotocol.h

diff --git a/CHANGES b/CHANGES
index f82a31567654a5ac4414dcbc27b7c2766bd82aa7..79fbf61dff97d6bc6bbd1fc98440452721cfaa46 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+Thu Jul 20 13:15:01 EEST 2000  Pekka Riikonen <priikone@poseidon.pspt.fi>
+
+       * Added dynamic protocol registering support.  Now protocols can
+         registered and unregistered on the fly.  Patch by cras.
+
 Wed Jul 19 19:08:46 EEST 2000  Pekka Riikonen <priikone@poseidon.pspt.fi>
 
        * Added lib/contrib directory to hold routines that some platforms
index 9ec43ec7a62d8f17ca9bf90f31c4822d6724a2a7..b3a6d391bc0c38ac1e3f220e51bea94256cbacf4 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.13  2000/07/20 10:17:25  priikone
+ *     Added dynamic protocol registering/unregistering support.  The
+ *     patch was provided by cras.
+ *
  * Revision 1.12  2000/07/19 07:07:34  priikone
  *     Save packet on private message's command context.
  *
@@ -178,6 +182,9 @@ int silc_client_init(SilcClient client)
     goto err1;
   }
 
+  /* Register protocols */
+  silc_client_protocols_register();
+
   /* Initialize the scheduler */
   silc_schedule_init(client->io_queue, client->timeout_queue, 
                     client->generic_queue, 5000);
@@ -247,6 +254,8 @@ void silc_client_stop(SilcClient client)
   silc_schedule_stop();
   silc_schedule_uninit();
 
+  silc_client_protocols_unregister();
+
   SILC_LOG_DEBUG(("Client client"));
 }
 
index a86b29e0d66ab7186d492d632c2c41b078c29a53..342597069f2f48a56d954167eb83a4bb95993414 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.8  2000/07/20 10:17:25  priikone
+ *     Added dynamic protocol registering/unregistering support.  The
+ *     patch was provided by cras.
+ *
  * Revision 1.7  2000/07/19 07:07:47  priikone
  *     Added version detection support to SKE.
  *
@@ -56,17 +60,6 @@ SILC_TASK_CALLBACK(silc_client_protocol_key_exchange);
 
 extern char *silc_version_string;
 
-/* SILC client protocol list */
-const SilcProtocolObject silc_protocol_list[] =
-{
-  { SILC_PROTOCOL_CLIENT_CONNECTION_AUTH, 
-    silc_client_protocol_connection_auth },
-  { SILC_PROTOCOL_CLIENT_KEY_EXCHANGE, 
-    silc_client_protocol_key_exchange },
-
-  { SILC_PROTOCOL_CLIENT_NONE, NULL },
-};
-
 /*
  * Key Exhange protocol functions
  */
@@ -483,3 +476,22 @@ SILC_TASK_CALLBACK(silc_client_protocol_connection_auth)
   }
 }
 
+/* Registers protocols used in client */
+
+void silc_client_protocols_register(void)
+{
+  silc_protocol_register(SILC_PROTOCOL_CLIENT_CONNECTION_AUTH,
+                        silc_client_protocol_connection_auth);
+  silc_protocol_register(SILC_PROTOCOL_CLIENT_KEY_EXCHANGE,
+                        silc_client_protocol_key_exchange);
+}
+
+/* Unregisters protocols */
+
+void silc_client_protocols_unregister(void)
+{
+  silc_protocol_unregister(SILC_PROTOCOL_CLIENT_CONNECTION_AUTH,
+                          silc_client_protocol_connection_auth);
+  silc_protocol_unregister(SILC_PROTOCOL_CLIENT_KEY_EXCHANGE,
+                          silc_client_protocol_key_exchange);
+}
index f78bcfd74abc85b7cb2de95ea73f7decd97557ca..684995dd2b431df6c03c4f454ede1256bf49510d 100644 (file)
@@ -69,5 +69,7 @@ typedef struct {
 } SilcClientConnAuthInternalContext;
 
 /* Prototypes */
+void silc_client_protocols_register(void);
+void silc_client_protocols_unregister(void);
 
 #endif
index 0f91d2d01d987d6b9393ffe53da077a9b307f34b..fe6139302b87d832c230b68eead6880de19a6c9a 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.9  2000/07/20 10:17:25  priikone
+ *     Added dynamic protocol registering/unregistering support.  The
+ *     patch was provided by cras.
+ *
  * Revision 1.8  2000/07/19 07:08:09  priikone
  *     Added version detection support to SKE.
  *
@@ -65,17 +69,6 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange);
 
 extern char *silc_version_string;
 
-/* SILC client protocol list */
-const SilcProtocolObject silc_protocol_list[] =
-{
-  { SILC_PROTOCOL_SERVER_CONNECTION_AUTH, 
-    silc_server_protocol_connection_auth },
-  { SILC_PROTOCOL_SERVER_KEY_EXCHANGE, 
-    silc_server_protocol_key_exchange },
-
-  { SILC_PROTOCOL_SERVER_NONE, NULL },
-};
-
 /*
  * Key Exhange protocol functions
  */
@@ -924,3 +917,23 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth)
     break;
   }
 }
+
+/* Registers protocols used in server. */
+
+void silc_server_protocols_register(void)
+{
+  silc_protocol_register(SILC_PROTOCOL_SERVER_CONNECTION_AUTH,
+                        silc_server_protocol_connection_auth);
+  silc_protocol_register(SILC_PROTOCOL_SERVER_KEY_EXCHANGE,
+                        silc_server_protocol_key_exchange);
+}
+
+/* Unregisters protocols */
+
+void silc_server_protocols_unregister(void)
+{
+  silc_protocol_unregister(SILC_PROTOCOL_SERVER_CONNECTION_AUTH,
+                          silc_server_protocol_connection_auth);
+  silc_protocol_unregister(SILC_PROTOCOL_SERVER_KEY_EXCHANGE,
+                          silc_server_protocol_key_exchange);
+}
index 9859647ca274753e171e0d7d4205b6e7e3bb6d33..67d76a638df0fe1ac618fde04afefdeaf3631337 100644 (file)
@@ -78,5 +78,7 @@ typedef struct {
 } SilcServerConnAuthInternalContext;
 
 /* Prototypes */
+void silc_server_protocols_register(void);
+void silc_server_protocols_unregister(void);
 
 #endif
index c17d2c7ffe30f1103c5846f40b61c12777af11d9..5863369729351c391c1dcf7dc7f1cb262e8a5cdf 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.11  2000/07/20 10:17:25  priikone
+ *     Added dynamic protocol registering/unregistering support.  The
+ *     patch was provided by cras.
+ *
  * Revision 1.10  2000/07/17 11:47:30  priikone
  *     Added command lagging support. Added idle counting support.
  *
@@ -315,6 +319,9 @@ int silc_server_init(SilcServer server)
     goto err1;
   }
 
+  /* Register protocols */
+  silc_server_protocols_register();
+
   /* Initialize the scheduler */
   silc_schedule_init(server->io_queue, server->timeout_queue, 
                     server->generic_queue, 
@@ -367,6 +374,8 @@ void silc_server_stop(SilcServer server)
   silc_schedule_stop();
   silc_schedule_uninit();
 
+  silc_server_protocols_unregister();
+
   SILC_LOG_DEBUG(("Server stopped"));
 }
 
index cda59efcee515de7c62817006124c35f59fde960..7c33c1afbfd3d6191ebc1543378b1e34bf8e221f 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.3  2000/07/20 10:17:25  priikone
+ *     Added dynamic protocol registering/unregistering support.  The
+ *     patch was provided by cras.
+ *
  * Revision 1.2  2000/07/05 06:06:35  priikone
  *     Global cosmetic change.
  *
 #include "silcincludes.h"
 #include "silcprotocol.h"
 
+/* Dynamically registered protocols */
+SilcProtocolObject *silc_protocol_list = NULL;
+
+/* Dynamically registers new protocol. The protocol is added into protocol
+   list and can be unregistered with silc_protocol_unregister. */
+
+void silc_protocol_register(SilcProtocolType type,
+                           SilcProtocolCallback callback)
+{
+  SilcProtocolObject *new;
+
+  new = silc_calloc(1, sizeof(*new));
+  new->type = type;
+  new->callback = callback;
+
+  if (!silc_protocol_list)
+    silc_protocol_list = new;
+  else {
+    new->next = silc_protocol_list;
+    silc_protocol_list = new;
+  }
+}
+
+/* Unregisters protocol. The unregistering is done by both protocol type
+   and the protocol callback. */
+
+void silc_protocol_unregister(SilcProtocolType type,
+                              SilcProtocolCallback callback)
+{
+  SilcProtocolObject *protocol, *prev;
+
+  protocol = silc_protocol_list;
+  prev = NULL;
+  while (protocol && (protocol->type != type && 
+                      protocol->callback != callback)) {
+    prev = protocol;
+    protocol = protocol->next;
+  }
+
+  if (protocol) {
+    if (prev)
+      prev->next = protocol->next;
+    else
+      silc_protocol_list = protocol->next;
+
+    silc_free(protocol);
+  }
+}
+
 /* Allocates a new protocol object. The new allocated and initialized 
    protocol is returned to the new_protocol argument. The argument context
    is the context to be sent as argument for the protocol. The callback
 void silc_protocol_alloc(SilcProtocolType type, SilcProtocol *new_protocol,
                         void *context, SilcProtocolFinalCallback callback)
 {
-  int i;
+  SilcProtocolObject *protocol;
 
   SILC_LOG_DEBUG(("Allocating new protocol type %d", type));
 
-  for (i = 0; silc_protocol_list[i].callback; i++)
-    if (silc_protocol_list[i].type == type)
-      break;
+  protocol = silc_protocol_list;
+  while (protocol && protocol->type != type)
+    protocol = protocol->next;
 
-  if (!silc_protocol_list[i].callback) {
+  if (!protocol) {
     SILC_LOG_ERROR(("Requested protocol does not exists"));
     return;
   }
 
   *new_protocol = silc_calloc(1, sizeof(**new_protocol));
-  (*new_protocol)->protocol = (SilcProtocolObject *)&silc_protocol_list[i];
+  (*new_protocol)->protocol = protocol;
   (*new_protocol)->state = SILC_PROTOCOL_STATE_UNKNOWN;
   (*new_protocol)->context = context;
   (*new_protocol)->execute = silc_protocol_execute;
index f04ffd794f843a0ffd37fe4d9895df392ee5ac2c..fd564fcbcd7d8db99941278bf1d8bb5441a5bdd7 100644 (file)
@@ -91,15 +91,17 @@ typedef unsigned char SilcProtocolState;
 */
 typedef SilcTaskCallback SilcProtocolCallback;
 
-typedef struct {
+typedef struct SilcProtocolObjectStruct {
   SilcProtocolType type;
   SilcProtocolCallback callback;
+
+  struct SilcProtocolObjectStruct *next;
 } SilcProtocolObject;
 
 typedef SilcTaskCallback SilcProtocolFinalCallback;
 typedef SilcTaskCallback SilcProtocolExecute;
 
-typedef struct SilcProtocolObjectStruct {
+typedef struct SilcProtocolStruct {
   SilcProtocolObject *protocol;
   SilcProtocolState state;
   void *context;
@@ -110,12 +112,11 @@ typedef struct SilcProtocolObjectStruct {
   SilcProtocolFinalCallback final_callback;
 } *SilcProtocol;
 
-/* Definition for SILC protocol list. This list includes all the
-   protocols in the SILC. SILC server and client defined own list of
-   protocols. */
-extern const SilcProtocolObject silc_protocol_list[];
-
 /* Prototypes */
+void silc_protocol_register(SilcProtocolType type,
+                           SilcProtocolCallback callback);
+void silc_protocol_unregister(SilcProtocolType type,
+                              SilcProtocolCallback callback);
 void silc_protocol_alloc(SilcProtocolType type, SilcProtocol *new_protocol,
                         void *context, SilcProtocolFinalCallback callback);
 void silc_protocol_free(SilcProtocol protocol);