[srm-cvs] CVS Update: - Make it possible to register protocols with the srm_register_protocol()

From: <d.rethans[@]jdimedia.nl>
Date: Sun Feb 16 2003 - 00:23:08 CET

Date: Sun Feb 16 00:23:07 CET 2003
User: Derick Rethans
Directory: srm/main/src

Log Message:
 [0.50]
 - Make it possible to register protocols with the srm_register_protocol()
   function in for example modules. There is currently a limit of 32 protocols,
   which should be mooooore then enough.
 
Modified files:
           srm/main/main.c (version: 1.67)
           srm/main/src/srm_protocols.c (version: 1.2)
           srm/main/src/srm_protocols.h (version: 1.2)

[FILE: /srm/main/main.c]

--- srm/main/main.c:1.66 Sat Feb 15 20:24:57 2003 GMT
+++ srm/main/main.c Sat Feb 15 22:23:06 2003 GMT
@@ -1,4 +1,4 @@
-/* $Id: cvstemp,v 1.66 2003/02/15 21:24:57 derick Exp $ */
+/* $Id: cvstemp,v 1.67 2003/02/15 23:23:06 derick Exp $ */
 
 /* The contents of this file are subject to the Vulcan Logic Public
  * License Version 1.1 (the "License"); you may not use this file
@@ -266,6 +266,26 @@
 /******************************************************************************
 ** Initializing connections
 */
+ srm_init_protocol_registry();
+
+ {
+ srm_protocol *p = malloc(sizeof (srm_protocol));
+ p->host.host = strdup(INI_SETTING(sockname));
+ p->host.family = AF_UNIX;
+ p->host.port = 0;
+ p->process = srm_process_data;
+ srm_register_protocol(p);
+ }
+
+ if (!INI_SETTING(no_tcp_ip)) {
+ srm_protocol *p = malloc(sizeof (srm_protocol));
+ p->host.host = NULL;
+ p->host.family = AF_INET;
+ p->host.port = INI_SETTING(port);
+ p->process = srm_process_data;
+ srm_register_protocol(p);
+ }
+
         srm_setup_protocols(&CP);
 
 /******************************************************************************
@@ -356,7 +376,7 @@
 /******************************************************************************
 ** Abort requested
 */
-
+ srm_deinit_protocol_registry();
         srm_unload_modules ();
         
         srm_store_close (STORE_SETTINGS);

[FILE: /srm/main/src/srm_protocols.c]

--- srm/main/src/srm_protocols.c:1.1 Sat Feb 15 20:24:58 2003 GMT
+++ srm/main/src/srm_protocols.c Sat Feb 15 22:23:07 2003 GMT
@@ -1,4 +1,4 @@
-/* $Id: cvstemp,v 1.1 2003/02/15 21:24:58 derick Exp $ */
+/* $Id: cvstemp,v 1.2 2003/02/15 23:23:07 derick Exp $ */
 
 /* The contents of this file are subject to the Vulcan Logic Public
  * License Version 1.1 (the "License"); you may not use this file
@@ -22,25 +22,59 @@
 
 #include "connection.h"
 #include "srm_protocols.h"
+#include <stdlib.h>
 #include <stdio.h>
 #include <sys/socket.h>
 
+#define SRM_MAX_PROTOCOLS 32
 
-srm_protocol protocol_list[] = {
- { { "/var/srm.socket", 0, AF_UNIX }, NULL, NULL, srm_process_data },
- { { NULL, 7777, AF_INET }, NULL, NULL, srm_process_data },
- { { NULL, 0, 0}, NULL, NULL, NULL}
-};
+static int srm_protocol_count;
+static srm_protocol *srm_protocol_list[SRM_MAX_PROTOCOLS];
 
+/******************************************************************************
+** (de)register protocol
+**/
+
+int srm_register_protocol (srm_protocol *prot)
+{
+ /* Yadda yadda, we could have made this not use globals, and make it
+ * re-entrant ant stuff.... but who cares? */
+ if (srm_protocol_count == SRM_MAX_PROTOCOLS) {
+ return SRM_FAILED;
+ }
+ srm_protocol_list[srm_protocol_count] = prot;
+ srm_protocol_count++;
+ return SRM_SUCCESS;
+}
 
 /******************************************************************************
 ** protocols
 **/
 
+void srm_init_protocol_registry (void)
+{
+ int i;
+
+ for (i = 0; i < SRM_MAX_PROTOCOLS; i++) {
+ srm_protocol_list[i] = NULL;
+ }
+ srm_protocol_count = 0;
+}
+
+void srm_deinit_protocol_registry (void)
+{
+ int i;
+
+ for (i = 0; i < srm_protocol_count; i++) {
+ if (srm_protocol_list[i]->host.host) {
+ free(srm_protocol_list[i]->host.host);
+ }
+ }
+}
+
 void srm_setup_protocols (struct con_pool* cp)
 {
         int sock;
- srm_protocol *protocol = protocol_list;
         int i;
 
         for (i = 0; i < FD_SETSIZE; i++) {
@@ -50,20 +84,18 @@
         
         FD_ZERO(&(cp->test_set));
 
- while (protocol->process) {
+ for (i = 0; i < srm_protocol_count; i++) {
                 sock = srm_setup_socket(
- protocol->host.family,
- protocol->host.port,
- protocol->host.host
+ srm_protocol_list[i]->host.family,
+ srm_protocol_list[i]->host.port,
+ srm_protocol_list[i]->host.host
                 );
                 cp->status[sock] = SRM_STATUS_RENDEZVOUS;
- cp->protocol[sock] = protocol;
+ cp->protocol[sock] = srm_protocol_list[i];
 
                 FD_SET(sock, &(cp->test_set));
                 if (sock > cp->max_fd) {
                         cp->max_fd = sock;
                 }
-
- protocol++;
         }
 }

[FILE: /srm/main/src/srm_protocols.h]

--- srm/main/src/srm_protocols.h:1.1 Sat Feb 15 20:24:58 2003 GMT
+++ srm/main/src/srm_protocols.h Sat Feb 15 22:23:07 2003 GMT
@@ -1,4 +1,4 @@
-/* $Id: cvstemp,v 1.1 2003/02/15 21:24:58 derick Exp $ */
+/* $Id: cvstemp,v 1.2 2003/02/15 23:23:07 derick Exp $ */
 
 /* The contents of this file are subject to the Vulcan Logic Public
  * License Version 1.1 (the "License"); you may not use this file
@@ -28,6 +28,9 @@
 
 int srm_process_data (int fd);
 
+int srm_register_protocol (srm_protocol *prot);
+void srm_init_protocol_registry (void);
+void srm_deinit_protocol_registry (void);
 void srm_setup_protocols (struct con_pool* cp);
 
 #endif
Received on Sun Feb 16 00:11:23 2003

This archive was generated by hypermail 2.1.8 : Tue Jan 06 2009 - 06:00:02 CET