Added oid_init/oid_exit. Changed oid_exit.
[yaz-moved-to-github.git] / util / oid.c
index 95c5846..02e0a22 100644 (file)
@@ -4,7 +4,19 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: oid.c,v $
- * Revision 1.36  1999-05-27 13:02:20  adam
+ * Revision 1.40  2000-01-06 14:59:13  adam
+ * Added oid_init/oid_exit. Changed oid_exit.
+ *
+ * Revision 1.39  1999/12/16 23:36:19  adam
+ * Implemented ILL protocol. Minor updates ASN.1 compiler.
+ *
+ * Revision 1.38  1999/11/30 13:47:12  adam
+ * Improved installation. Moved header files to include/yaz.
+ *
+ * Revision 1.37  1999/09/13 12:51:15  adam
+ * Added CLIENT IP OID.
+ *
+ * Revision 1.36  1999/05/27 13:02:20  adam
  * Assigned OID for old DB Update (VAL_DBUPDATE0).
  *
  * Revision 1.35  1999/04/20 09:56:49  adam
 #include <string.h>
 #include <ctype.h>
 
-#include <oid.h>
-#include <yaz-util.h>
+#include <yaz/oid.h>
+#include <yaz/yaz-util.h>
 
 static int z3950_prefix[] = { 1, 2, 840, 10003, -1 };
 static int sr_prefix[]    = { 1, 0, 10163, -1 };
@@ -159,6 +171,7 @@ struct oident_list {
 
 static struct oident_list *oident_table = NULL;
 static int oid_value_dynamic = VAL_DYNAMIC;
+static int oid_init_flag = 0;
 
 /*
  * OID database
@@ -170,6 +183,8 @@ static oident oids[] =
      "BER" },
     {PROTO_GENERAL, CLASS_TRANSYN, VAL_ISO2709,      {1,0,2709,1,1,-1},
      "ISO2709"},
+    {PROTO_GENERAL, CLASS_GENERAL, VAL_ISO_ILL_1,    {1,2,10161,2,1,-1},
+     "ISOILL-1"},
     /* Z39.50v3 definitions */
     {PROTO_Z3950,   CLASS_ABSYN,   VAL_APDU,         {2,1,-1},
      "Z-APDU"},    
@@ -333,6 +348,8 @@ static oident oids[] =
      "Proxy" },
     {PROTO_Z3950,   CLASS_USERINFO,VAL_COOKIE,       {10,1000,81,2,-1},
      "Cookie" },
+    {PROTO_Z3950,   CLASS_USERINFO,VAL_CLIENT_IP,    {10,1000,81,3,-1},
+     "Client-IP" },
     {PROTO_Z3950,   CLASS_ELEMSPEC,VAL_ESPEC1,       {11,1,-1},
      "Espec-1"},
     {PROTO_Z3950,   CLASS_VARSET,  VAL_VAR1,         {12,1,-1},
@@ -514,16 +531,31 @@ void oid_transfer (struct oident *oident)
     }
 }
 
-static void oid_init (void)
+void oid_init (void)
 {
-    static int checked = 0;
-    
-    if (checked)
+    if (oid_init_flag)
        return;
+    /* oid_transfer is thread safe, so there's nothing wrong in having
+       two threads calling it simultaniously. On the other hand
+       no thread may exit oid_init before all OID's bave been
+       transferred - which is why checked is set after oid_transfer... 
+    */
     oid_transfer (oids);
-    checked = 1;
+    oid_init_flag = 1;
 }
 
+void oid_exit (void)
+{
+    while (oident_table)
+    {
+       struct oident_list *this_p = oident_table;
+       oident_table = oident_table->next;
+
+       xfree (this_p->oident.desc);
+       xfree (this_p);
+    }
+    oid_init_flag = 0;
+}
 
 static struct oident *oid_getentbyoid_x(int *o)
 {
@@ -601,7 +633,7 @@ struct oident *oid_addent (int *oid, enum oid_proto proto,
     {
        char desc_str[200];
        struct oident_list *oident_list;
-       oident_list = (struct oident_list *) malloc (sizeof(*oident_list));
+       oident_list = (struct oident_list *) xmalloc (sizeof(*oident_list));
        oident = &oident_list->oident;
        oident->proto = proto;
        oident->oclass = oclass;
@@ -615,7 +647,7 @@ struct oident *oid_addent (int *oid, enum oid_proto proto,
                sprintf (desc_str+strlen(desc_str), ".%d", oid[i]);
            desc = desc_str;
        }
-       oident->desc = (char *) malloc (strlen(desc)+1);
+       oident->desc = (char *) xmalloc (strlen(desc)+1);
        strcpy (oident->desc, desc);
        if (value == VAL_DYNAMIC)
            oident->value = (enum oid_value) (++oid_value_dynamic);