1 /* oidm.c - object identifier macro routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
22 #include <ac/string.h>
23 #include <ac/socket.h>
27 static LDAP_SLIST_HEAD(OidMacroList, slap_oid_macro) om_list
28 = LDAP_SLIST_HEAD_INITIALIZER(om_list);
30 /* Replace an OID Macro invocation with its full numeric OID.
31 * If the macro is used with "macroname:suffix" append ".suffix"
39 /* OID macros must start alpha */
40 if ( OID_LEADCHAR( *oid ) ) {
44 LDAP_SLIST_FOREACH( om, &om_list, som_next ) {
45 char **names = om->som_names;
51 for( ; *names != NULL ; names++ ) {
52 int pos = dscompare(*names, oid, ':');
55 int suflen = strlen(oid + pos);
56 char *tmp = SLAP_MALLOC( om->som_oid.bv_len
59 Debug( LDAP_DEBUG_ANY,
60 "oidm_find: SLAP_MALLOC failed", 0, 0, 0 );
63 strcpy(tmp, om->som_oid.bv_val);
65 suflen = om->som_oid.bv_len;
67 strcpy(tmp+suflen, oid+pos+1);
80 while( !LDAP_SLIST_EMPTY( &om_list )) {
81 om = LDAP_SLIST_FIRST( &om_list );
82 LDAP_SLIST_REMOVE_HEAD( &om_list, som_next );
84 ldap_charray_free(om->som_names);
85 free(om->som_oid.bv_val);
102 fprintf( stderr, "%s: line %d: too many arguments\n",
104 usage: fprintf( stderr, "\tObjectIdentifier <name> <oid>\n");
108 oid = oidm_find( argv[1] );
112 "ObjectIdentifier \"%s\" previously defined \"%s\"",
113 fname, lineno, argv[1], oid );
117 om = (OidMacro *) SLAP_MALLOC( sizeof(OidMacro) );
119 Debug( LDAP_DEBUG_ANY, "parse_oidm: SLAP_MALLOC failed", 0, 0, 0 );
123 LDAP_SLIST_NEXT( om, som_next ) = NULL;
124 om->som_names = NULL;
125 ldap_charray_add( &om->som_names, argv[1] );
126 om->som_oid.bv_val = oidm_find( argv[2] );
128 if (!om->som_oid.bv_val) {
129 fprintf( stderr, "%s: line %d: OID %s not recognized\n",
130 fname, lineno, argv[2] );
134 if (om->som_oid.bv_val == argv[2]) {
135 om->som_oid.bv_val = ch_strdup( argv[2] );
138 om->som_oid.bv_len = strlen( om->som_oid.bv_val );
140 LDAP_SLIST_INSERT_HEAD( &om_list, om, som_next );