Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moved common util functions into a subdirectory, are build as a share…

…d library now.

Added slp support.
  • Loading branch information...
commit 119dcf452d5c69f0703784dbe7f6d51de6107a69 1 parent 738d1fc
sschuetz authored
View
25 .cvsignore
@@ -0,0 +1,25 @@
+.cdtproject
+.project
+aclocal.m4
+compile
+config.guess
+config.h.in
+config.sub
+configure
+depcomp
+INSTALL
+install-sh
+ltmain.sh
+Makefile.in
+missing
+queryLexer.c
+queryParser.c
+queryParser.h
+sqlLexer.c
+sqlParser.c
+sqlParser.h
+tmpfile
+ylwrap
+cimXmlOps.c
+cimXmlOps.h
+cimXmlParserProcessed.c
View
87 Makefile.am
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.51 2006/03/06 04:11:08 a3schuur Exp $
+# $Id: Makefile.am,v 1.52 2006/07/17 13:04:18 sschuetz Exp $
#
# Makefile.am
#
@@ -13,6 +13,7 @@
#
# Author: Viktor Mihajlovski <mihajlov@de.ibm.com>
# Contributions: Adrian Schuur <schuur@de.ibm.com>
+# Sven Schuetz <sven@de.ibm.com>
#
# Description:
#
@@ -30,7 +31,7 @@ MANFILES=man/genSslCert.1 man/getSchema.1 man/sfcbd.1 man/sfcbmof.1 \
man/sfcbrepos.1 man/sfcbstage.1 man/sfcbunstage.1 man/sfcbuuid.1 \
man/wbemcat.1 man/xmltest.1
-BUILT_SOURCES=queryParser.c queryLexer.c sqlParser.c sqlLexer.c $(MANFILES)
+BUILT_SOURCES=queryParser.c queryLexer.c sqlParser.c sqlLexer.c cimXmlOps.c cimXmlParserProcessed.c $(MANFILES)
AM_YFLAGS=-d
@@ -38,6 +39,7 @@ AM_CPPFLAGS=-DSFCB_CONFDIR=\"$(sfcbconfdir)\" \
-DSFCB_STATEDIR=\"$(sfcbstatedir)\" \
-DSFCB_LIBDIR=\"$(libdir)\" \
-DSFCB_BINARY=\"$(sbindir)/sfcbd\" \
+ -I$(srcdir)/sfcUtil \
@SFCB_CPPFLAGS@
AM_CFLAGS=@SFCB_CFLAGS@
AM_LDFLAGS=@SFCB_LDFLAGS@
@@ -45,22 +47,21 @@ AM_LDFLAGS=@SFCB_LDFLAGS@
SUBDIRS=. $(MOFC_DIR)
if INDICATIONS
-lib_LTLIBRARIES = \
- libsfcBrokerCore.la \
- libsfcInternalProvider.la \
- libsfcInteropProvider.la \
- libsfcInteropServerProvider.la \
- libsfcClassProvider.la \
- libsfcClassProviderGz.la \
- libsfcCimXmlCodec.la \
- libsfcHttpAdapter.la \
- libsfcBasicAuthentication.la \
- libsfcCertificateAuthentication.la \
- libsfcIndCIMXMLHandler.la \
- libsfcObjectImplSwapI32toP32.la \
- libcimcClientSfcbLocal.la
+INDICATION_LIBS = libsfcIndCIMXMLHandler.la
+else
+INDICATION_LIBS =
+endif
+
+if SLP
+SLP_LIBS = libslpAgent.la
+SLP_LIB = -lslpAgent
else
+SLP_LIBS =
+SLP_LIB =
+endif
+
lib_LTLIBRARIES = \
+ libsfcUtil.la \
libsfcBrokerCore.la \
libsfcInternalProvider.la \
libsfcInteropProvider.la \
@@ -72,18 +73,38 @@ lib_LTLIBRARIES = \
libsfcBasicAuthentication.la \
libsfcCertificateAuthentication.la \
libsfcObjectImplSwapI32toP32.la \
- libcimcClientSfcbLocal.la
+ libcimcClientSfcbLocal.la \
+ $(SLP_LIBS) \
+ $(INDICATION_LIBS)
+
+if SLP_ALONE
+SLP_PROGRAMFILES = cimslp
+cimslp_SOURCES = \
+ cimslp.c \
+ cimslpCMPI.c \
+ cimslpSLP.c \
+ cimslpUtil.c
+
+cimslp_LDADD=-lslp -lcmpisfcc
+else
+SLP_PROGRAMFILES =
endif
sbin_PROGRAMS = \
sfcbd
bin_PROGRAMS = \
- sfcbmofpp sfcbdump
+ sfcbmofpp sfcbdump $(SLP_PROGRAMFILES)
noinst_PROGRAMS = \
sfcbdumpP32onI32
+libsfcUtil_la_SOURCES = \
+ sfcUtil/hashtable.c \
+ sfcUtil/utilFactory.c \
+ sfcUtil/utilHashtable.c \
+ sfcUtil/utilStringBuffer.c
+
if JDBC
libsfcBrokerCore_la_SOURCES = \
args.c \
@@ -107,11 +128,7 @@ libsfcBrokerCore_la_SOURCES = \
providerRegister.c \
objectImpl.c \
constClass.c \
- hashtable.c \
genericlist.c \
- utilHashtable.c \
- utilStringBuffer.c \
- utilFactory.c \
msgqueue.c \
providerMgr.c \
providerDrv.c \
@@ -153,11 +170,7 @@ libsfcBrokerCore_la_SOURCES = \
providerRegister.c \
objectImpl.c \
constClass.c \
- hashtable.c \
genericlist.c \
- utilHashtable.c \
- utilStringBuffer.c \
- utilFactory.c \
msgqueue.c \
providerMgr.c \
providerDrv.c \
@@ -173,6 +186,7 @@ libsfcBrokerCore_la_SOURCES = \
endif
libsfcBrokerCore_la_CFLAGS = $(AM_CFLAGS) @SFCB_CMPI_OS@ @SFCB_CMPI_PLATFORM@
+libsfcBrokerCore_la_LIBADD=-lsfcUtil
if JDBC
sqlLexer.c: $(srcdir)/sqlLexer.l
@@ -188,6 +202,12 @@ queryLexer.c: $(srcdir)/queryLexer.l
queryParser.c: $(srcdir)/queryParser.y
$(YACC) $(AM_YFLAGS) -p sfcQuery -o $@ $<
+cimXmlOps.c: $(srcdir)/cimXmlOps.y
+ $(YACC) $(AM_YFLAGS) -p sfcXml -o $@ $<
+
+cimXmlParserProcessed.c: $(srcdir)/cimXmlParser.c
+ sed -e "s/yy/sfcXml/g" $< > $@
+
libcimcClientSfcbLocal_la_SOURCES = \
cimcClientSfcbLocal.c
libcimcClientSfcbLocal_la_LIBADD=-lsfcBrokerCore
@@ -235,13 +255,22 @@ libsfcClassProvider_la_LIBADD=-lsfcBrokerCore
libsfcCimXmlCodec_la_SOURCES = \
cimXmlOps.y \
- cimXmlParser.c \
+ cimXmlParserProcessed.c \
cimXmlRequest.c
libsfcCimXmlCodec_la_LIBADD=-lsfcBrokerCore
+if SLP
+libslpAgent_la_CFLAGS = $(AM_CFLAGS)
+libslpAgent_la_SOURCES = \
+ cimslp.c \
+ cimslpCMPI.c \
+ cimslpSLP.c \
+ cimslpUtil.c
+libslpAgent_la_LIBADD=-lslp -lcmpisfcc
+endif
sfcbd_SOURCES=sfcBroker.c
-sfcbd_LDADD=-lsfcBrokerCore -lsfcCimXmlCodec -lsfcHttpAdapter
+sfcbd_LDADD=-lsfcBrokerCore -lsfcCimXmlCodec -lsfcHttpAdapter $(SLP_LIB)
sfcbmofpp_SOURCES=mofpp.c
@@ -251,7 +280,7 @@ noinst_HEADERS=array.h httpComm.h control.h providerMgr.h \
constClass.h msgqueue.h providerRegister.h \
cimXmlParser.h native.h support.h cimXmlGen.h \
cimXmlRequest.h genericlist.h objectImpl.h trace.h \
- hashtable.h utilft.h mlog.h \
+ sfcUtil/hashtable.h sfcUtil/utilft.h mlog.h \
cmpidt.h cmpift.h cmpiftx.h cmpimacs.h cmpimacsx.h cmpios.h \
fileRepository.h internalProvider.h \
selectexp.h queryOperation.h \
View
127 cimslp.c
@@ -1,5 +1,5 @@
/*
- * cimslp.h
+ * cimslp.c
*
* (C) Copyright IBM Corp. 2006
*
@@ -24,33 +24,96 @@
#include <stdio.h>
#include <unistd.h>
#include <string.h>
+#include <slp.h>
+#include <stdlib.h>
+#include "config.h"
#include "cimslpCMPI.h"
#include "cimslpSLP.h"
-#include "cimslpConfig.h"
+#include "cimslp.h"
-#ifndef SLP_RUN_STANDALONE
+#ifdef HAVE_SLP
+#include "control.h"
+#endif
+
+
+void freeCFG(cimomConfig cfg) {
+
+ free(cfg.cimhost);
+ free(cfg.cimpassword);
+ free(cfg.cimuser);
+ free(cfg.commScheme);
+ free(cfg.port);
+}
+
+void setUpDefaults(cimomConfig *cfg) {
+ cfg->commScheme = strdup("http");
+ cfg->cimhost = strdup("localhost");
+ cfg->port = strdup("5988");
+ cfg->cimuser = strdup("pegasus");
+ cfg->cimpassword = strdup("nonon");
+}
+
+#ifdef HAVE_SLP
-void startSLPThread()
+void slpAgent()
{
cimomConfig cfg;
+ cimSLPService as; //Service which is going to be advertised
+ int enableHttp=0;
+
+ extern char * configfile;
+
+ setUpDefaults(&cfg);
+
+ setupControl(configfile);
+ sleep(15);
+
+ printf("vorher\n");
+ as = getSLPData(cfg);
+ registerCIMService(as, 600);
+ printf("nachher\n");
+
+ /*getControlNum("httpProcs"
+
+ if (getControlBool("enableHttp", &enableHttp))
+ cfg.commScheme = strdup("http");
+*/
+ exit(0);
//get the control stuff and call getSLPData with the filled cfg;
}
-#else
+#endif
+
+#ifdef HAVE_SLP_ALONE
+
int main(int argc, char *argv[])
{
- int c;
+ int c,j;
+ int slpLifeTime = SLP_LIFETIME_DEFAULT;
+ int sleepTime;
cimSLPService as; //Service which is going to be advertised
cimomConfig cfg;
- cfg.commScheme = "http";
- cfg.cimhost = "localhost";
- cfg.port = "5988";
- cfg.cimuser = "root";
- cfg.cimpassword = "password";
+
+ setUpDefaults(&cfg);
+
+
+
+ static const char * help[] =
+ {
+ "Options:",
+ " -c, --cimhost hostname",
+ " -n, --hostport portnumber",
+ " -u, --cimuser cimserver username",
+ " -p, --cimpassword cimserver password ",
+ " -s, --commscheme http or https",
+ " -l, --lifetime SLP liftime in seconds",
+ " -h, --help display this text\n"
+ };
+
static struct option const long_options[] =
@@ -60,45 +123,69 @@ int main(int argc, char *argv[])
{ "cimuser", required_argument, 0, 'u' },
{ "cimpassword", required_argument, 0, 'p' },
{ "commscheme", required_argument, 0, 's' },
- { "help", no_argument, 0, 'h' },
+ { "lifetime", required_argument, 0, 's' },
+ { "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0 }
};
- while ((c = getopt_long(argc, argv, "c:n:u:p:s:h", long_options, 0)) != -1)
+ while ((c = getopt_long(argc, argv, "c:n:u:p:s:l:h", long_options, 0)) != -1)
{
switch(c)
{
case 0:
break;
case 'c':
+ free(cfg.cimhost);
cfg.cimhost = strdup(optarg);
break;
case 'n':
+ free(cfg.port);
cfg.port = strdup(optarg);
break;
case 'u':
+ free(cfg.cimuser);
cfg.cimuser = strdup(optarg);
break;
case 'p':
+ free(cfg.cimpassword);
cfg.cimpassword = strdup(optarg);
break;
case 's':
+ free(cfg.commScheme);
cfg.commScheme = strdup(optarg);
break;
+ case 'l':
+ slpLifeTime = atoi(optarg);
+ break;
case 'h':
- printf("Help\n");
- break;
+ for(j=0; help[j] != NULL; j++) {
+ printf("%s\n", help[j]);
+ }
+ exit(0);
default:
- printf("Help\n");
+ for(j=0; help[j] != NULL; j++) {
+ printf("%s\n", help[j]);
+ }
+ exit(0);
break;
}
}
- int i = 0;
- for(i = 0; i < 5; i++) {
+
+ if (slpLifeTime < 1 || slpLifeTime > SLP_LIFETIME_MAXIMUM) {
+ slpLifeTime = SLP_LIFETIME_DEFAULT;
+ }
+ sleepTime = slpLifeTime -1;
+ slpLifeTime += 15; //due to the strange slpd backward counting
+
+ int i;
+ for(i = 0; i < 1; i++) {
as = getSLPData(cfg);
- registerCIMService(as);
- //sleep(1);
+ registerCIMService(as, slpLifeTime);
+ //sleep(sleepTime);
}
+
+ freeCFG(cfg);
+ return 0;
}
#endif
View
23 cimslp.h
@@ -0,0 +1,23 @@
+/*
+ * cimslp.h
+ *
+ * (C) Copyright IBM Corp. 2006
+ *
+ * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
+ * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
+ * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
+ *
+ * You can obtain a current copy of the Eclipse Public License from
+ * http://www.opensource.org/licenses/eclipse-1.0.php
+ *
+ * Author: Sven Schuetz <sven@de.ibm.com>
+ * Contributions:
+ *
+ * Description:
+ *
+ * Control functions, main if running standlone, or slpAgent
+ * function if running in sfcb
+ *
+*/
+
+void slpAgent();
View
162 cimslpCMPI.c
@@ -20,8 +20,10 @@
*/
#include <cmci.h>
-#include <native.h>
+
#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
#include "cimslpCMPI.h"
#include "cimslpUtil.h"
@@ -55,10 +57,10 @@ char ** getInterOpNS()
{
char ** retArr;
- interOpNS = "root/interop";
+ interOpNS = "root/pg_interop";
retArr = malloc(2 * sizeof(char *));
- retArr[0] = (char *)malloc(13 * sizeof(char)); //length of "root/interop"
+ retArr[0] = (char *)malloc((strlen(interOpNS) + 1) * sizeof(char));
strcpy(retArr[0], interOpNS);
retArr[1] = NULL;
@@ -68,20 +70,18 @@ char ** getInterOpNS()
-CMPIInstance ** getInstances(CMCIClient *cc, char * path, char * objectname)
+CMPIInstance ** myGetInstances(CMCIClient *cc, char * path, char * objectname)
{
CMPIStatus status;
CMPIObjectPath * objectpath;
CMPIEnumeration * enumeration;
- CMPIData objectData;
CMPIInstance ** retArr = NULL;
+ int debug_break = 1;
- objectpath = newCMPIObjectPath(path, objectname, &status);
+ objectpath = newCMPIObjectPath(path, objectname, NULL);
enumeration = cc->ft->enumInstances(cc, objectpath, 0, NULL, &status);
- if (objectpath) CMRelease(objectpath);
-
//severe error, cimom not running etc.
if(status.rc == CMPI_RC_ERR_FAILED) {
printf("Fatal error. CIMOM not running? Connection params ok?\n");
@@ -90,8 +90,7 @@ CMPIInstance ** getInstances(CMCIClient *cc, char * path, char * objectname)
//object not found ?
if(status.rc == CMPI_RC_ERR_INVALID_CLASS || status.rc == CMPI_RC_ERR_NOT_FOUND) {
- if (enumeration) CMRelease(enumeration);
- return NULL;
+ retArr = NULL;
}
if (!status.rc) {
@@ -109,12 +108,13 @@ CMPIInstance ** getInstances(CMCIClient *cc, char * path, char * objectname)
retArr[n] = NULL;
}
}
-
+ if (status.msg) CMRelease(status.msg);
+ if (objectpath) CMRelease(objectpath);
if (enumeration) CMRelease(enumeration);
return retArr;
}
-CMPIConstClass * getClass(CMCIClient *cc, char * path, char * objectname)
+CMPIConstClass * myGetClass(CMCIClient *cc, char * path, char * objectname)
{
CMPIStatus status;
CMPIObjectPath * objectpath;
@@ -146,14 +146,23 @@ cimSLPService getSLPData(cimomConfig cfg)
CMPIConstClass *ccls;
cimSLPService rs; //service which is going to be returned to the calling function
+
+ printf("in getSLPDATA\n");
+
initializeService(&rs);
- cc = cmciConnect(cfg.cimhost, cfg.commScheme, cfg.port, cfg.cimuser, cfg.cimpassword, &status);
+ cc = cmciConnect(cfg.cimhost,
+ cfg.commScheme,
+ cfg.port,
+ cfg.cimuser,
+ cfg.cimpassword,
+ &status);
if(status.rc) {
printf("Could not connect to CIMOM. Check if it is running as well as your parameters.\n");
exit(0);
}
+
//first of all, get the interop namespace, needed for all further connections
//this call fills the array as well as sets the global interOpNS variable
@@ -162,31 +171,40 @@ cimSLPService getSLPData(cimomConfig cfg)
//extract all relavant stuff for SLP out of CIM_ObjectManager
//construct the server string
- ci = getInstances(cc, interOpNS, "CIM_ObjectManager");
+ ci = myGetInstances(cc, interOpNS, "CIM_ObjectManager");
if(ci) {
- rs.url_syntax = getUrlSyntax(myGetProperty(ci[0], "SystemName"), cfg.commScheme, cfg.port);
+ rs.url_syntax = getUrlSyntax(myGetProperty(ci[0], "SystemName"),
+ cfg.commScheme, cfg.port);
rs.service_hi_name = myGetProperty(ci[0], "ElementName");
rs.service_hi_description = myGetProperty(ci[0], "Description");
rs.service_id = myGetProperty(ci[0], "Name");
freeInstArr(ci);
}
+
//extract all relavant stuff for SLP out of CIM_ObjectManagerCommunicationMechanism
- ci = getInstances(cc, interOpNS, "CIM_ObjectManagerCommunicationMechanism");
+ ci = myGetInstances(cc, interOpNS, "CIM_ObjectManagerCommunicationMechanism");
if(ci) {
- rs.CommunicationMechanism = myGetProperty(ci[0], "CommunicationMechanism");
- rs.OtherCommunicationMechanismDescription = myGetProperty(ci[0], "OtherCommunicationMechanism");
+ rs.CommunicationMechanism =
+ myGetProperty(ci[0], "CommunicationMechanism");
+ rs.OtherCommunicationMechanismDescription =
+ myGetProperty(ci[0], "OtherCommunicationMechanism");
rs.ProtocolVersion = myGetProperty(ci[0], "Version");
- rs.FunctionalProfilesSupported = myGetPropertyArray(ci[0], "FunctionalProfilesSupported");
- rs.FunctionalProfileDescriptions = myGetPropertyArray(ci[0], "FunctionalProfileDescriptions");
- rs.MultipleOperationsSupported = myGetProperty(ci[0], "MultipleOperationsSupported");
- rs.AuthenticationMechanismsSupported = myGetPropertyArray(ci[0], "AuthenticationMechanismsSupported");
- rs.AuthenticationMechansimDescriptions = myGetPropertyArray(ci[0], "AuthenticationMechansimDescriptions");
+ rs.FunctionalProfilesSupported =
+ myGetPropertyArray(ci[0], "FunctionalProfilesSupported");
+ rs.FunctionalProfileDescriptions =
+ myGetPropertyArray(ci[0], "FunctionalProfileDescriptions");
+ rs.MultipleOperationsSupported =
+ myGetProperty(ci[0], "MultipleOperationsSupported");
+ rs.AuthenticationMechanismsSupported =
+ myGetPropertyArray(ci[0], "AuthenticationMechanismsSupported");
+ rs.AuthenticationMechansimDescriptions =
+ myGetPropertyArray(ci[0], "AuthenticationMechansimDescriptions");
freeInstArr(ci);
}
//extract all relavant stuff for SLP out of CIM_Namespace
- ci = getInstances(cc, interOpNS, "CIM_Namespace");
+ ci = myGetInstances(cc, interOpNS, "CIM_Namespace");
if(ci) {
rs.Namespace = myGetPropertyArrayFromArray(ci, "Name");
rs.Classinfo = myGetPropertyArrayFromArray(ci, "ClassInfo");
@@ -194,18 +212,21 @@ cimSLPService getSLPData(cimomConfig cfg)
}
//extract all relavant stuff for SLP out of CIM_RegisteredProfile
- ci = getInstances(cc, interOpNS, "CIM_RegisteredProfile");
+ ci = myGetInstances(cc, interOpNS, "CIM_RegisteredProfile");
if(ci) {
rs.RegisteredProfilesSupported = myGetRegProfiles(ci, cc);
- free(ci);
+ freeInstArr(ci);
}
//do the transformations from numbers to text via the qualifiers
- ccls = getClass(cc, interOpNS, "CIM_ObjectManagerCommunicationMechanism");
+ ccls = myGetClass(cc, interOpNS, "CIM_ObjectManagerCommunicationMechanism");
if(ccls) {
- rs.CommunicationMechanism = transformValue(rs.CommunicationMechanism, ccls, "CommunicationMechanism");
- transformValueArray(rs.FunctionalProfilesSupported, ccls, "FunctionalProfilesSupported");
- transformValueArray(rs.AuthenticationMechanismsSupported, ccls, "AuthenticationMechanismsSupported");
+ rs.CommunicationMechanism = transformValue(rs.CommunicationMechanism,
+ ccls, "CommunicationMechanism");
+ rs.FunctionalProfilesSupported = transformValueArray(rs.FunctionalProfilesSupported,
+ ccls, "FunctionalProfilesSupported");
+ rs.AuthenticationMechanismsSupported = transformValueArray(rs.AuthenticationMechanismsSupported,
+ ccls, "AuthenticationMechanismsSupported");
CMRelease(ccls);
}
@@ -218,8 +239,9 @@ cimSLPService getSLPData(cimomConfig cfg)
char ** myGetRegProfiles(CMPIInstance **instances, CMCIClient *cc)
{
CMPIObjectPath * objectpath;
- CMPIEnumeration * enumeration;
+ CMPIEnumeration * enumeration = NULL;
CMPIStatus status;
+ CMPIConstClass * ccls;
char ** retArr;
int i,j=0;
@@ -234,7 +256,11 @@ char ** myGetRegProfiles(CMPIInstance **instances, CMCIClient *cc)
//a little too much memory will be allocated, since not each instance is a RegisteredProfile, for which a
//string needs to be constructed ... but allocating dynamically would involve too much burden and overhead (?)
- retArr = (char **) malloc(i * sizeof(char *));
+ retArr = (char **) malloc((i+1) * sizeof(char *));
+
+ //getting the class including qualifiers, needed to resolve RegisteredOrganization (Values/ValueMap)
+ ccls = myGetClass(cc, interOpNS, "CIM_RegisteredProfile");
+
for(i = 0; instances[i] != NULL; i++) {
objectpath = instances[i]->ft->getObjectPath(instances[i], &status);
@@ -243,40 +269,76 @@ char ** myGetRegProfiles(CMPIInstance **instances, CMCIClient *cc)
return NULL;
}
objectpath->ft->setNameSpace(objectpath, interOpNS);
- enumeration = cc->ft->associatorNames(cc, objectpath, "CIM_SubProfileRequiresProfile", NULL, "Dependent", NULL, &status);
+
+ if (enumeration) CMRelease(enumeration);
+ enumeration = cc->ft->associatorNames(cc,
+ objectpath,
+ "CIM_SubProfileRequiresProfile",
+ NULL,
+ "Dependent",
+ NULL,
+ NULL);
//if the result is not null, we are operating on a CIM_RegisteredSubProfile, which we don't want
- if(! enumeration->ft->hasNext(enumeration, &status)) {
+ if(!enumeration || !enumeration->ft->hasNext(enumeration, &status)) {
CMPIData propertyData;
- propertyData = instances[i]->ft->getProperty(instances[i], "RegisteredOrganization", &status);
+ propertyData = instances[i]->ft->getProperty(instances[i],
+ "RegisteredOrganization",
+ &status);
retArr[j] = value2Chars(propertyData.type, &propertyData.value);
- propertyData = instances[i]->ft->getProperty(instances[i], "RegisteredName", &status);
+
+ retArr[j] = transformValue(retArr[j], ccls, "RegisteredOrganization");
+
+ propertyData = instances[i]->ft->getProperty(instances[i],
+ "RegisteredName",
+ &status);
char * tempString = value2Chars(propertyData.type, &propertyData.value);
-
+
retArr[j] = realloc(retArr[j], strlen(retArr[j]) + strlen(tempString) + 2);
retArr[j] = strcat(retArr[j], ":");
retArr[j] = strcat(retArr[j], tempString);
free(tempString);
//now search for a CIM_RegisteredSubProfile for this instance
- enumeration = cc->ft->associators(cc, objectpath, "CIM_SubProfileRequiresProfile", NULL, "Antecedent", NULL, 0, NULL, &status);
- if(! enumeration->ft->hasNext(enumeration, &status)) {
+ if (enumeration) CMRelease(enumeration);
+ enumeration = cc->ft->associators(cc,
+ objectpath,
+ "CIM_SubProfileRequiresProfile",
+ NULL,
+ "Antecedent",
+ NULL,
+ 0,
+ NULL,
+ NULL);
+ if(!enumeration || !enumeration->ft->hasNext(enumeration, NULL)) {
j++;
} else
while(enumeration->ft->hasNext(enumeration, &status)) {
CMPIData data = enumeration->ft->getNext(enumeration, NULL);
- propertyData = data.value.inst->ft->getProperty(data.value.inst, "RegisteredName", &status);
- char * subprofilestring = value2Chars(propertyData.type, &propertyData.value);
- retArr[j] = realloc(retArr[j], strlen(retArr[j]) + strlen(subprofilestring) + 2);
+ propertyData = data.value.inst->ft->getProperty(data.value.inst,
+ "RegisteredName",
+ &status);
+ char * subprofilestring = value2Chars(propertyData.type,
+ &propertyData.value);
+ retArr[j] = realloc(retArr[j],
+ strlen(retArr[j]) + strlen(subprofilestring) + 2);
retArr[j] = strcat(retArr[j], ":");
retArr[j] = strcat(retArr[j], subprofilestring);
j++;
free(subprofilestring);
}
}
+ if (objectpath) CMRelease(objectpath);
}
+ retArr[j] = NULL;
+
+ if (enumeration) CMRelease(enumeration);
+ if (ccls) CMRelease(ccls);
+ if (status.msg) CMRelease(status.msg);
+
+
return retArr;
}
@@ -287,6 +349,7 @@ char ** transformValueArray(char ** cssf, CMPIConstClass * ccls, char * property
for(i = 0; cssf[i] != NULL; i++) {
cssf[i] = transformValue(cssf[i], ccls, propertyName);
}
+ return cssf;
}
//transforms numerical values into their string counterpart
@@ -327,8 +390,8 @@ char * transformValue(char* cssf, CMPIConstClass * ccls, char * propertyName)
arr = qd.value.array;
eletyp = qd.type & ~CMPI_ARRAY;
ele = CMGetArrayElementAt(arr, j-1, NULL);
- return(value2Chars(eletyp, &ele.value));
-
+ cssf = value2Chars(eletyp, &ele.value);
+ return cssf;
} else {
//printf("No Valuemap Entry for %s in %s. Exiting ...\n", cssf, propertyName);
return NULL;
@@ -386,7 +449,7 @@ char ** myGetPropertyArray(CMPIInstance *instance, char *propertyName)
CMPIData propertyData;
CMPIStatus status;
- char **propertyArray;
+ char **propertyArray = NULL;
propertyData = instance->ft->getProperty(instance, propertyName, &status);
if (!status.rc) {
@@ -401,20 +464,19 @@ char ** myGetPropertyArray(CMPIInstance *instance, char *propertyName)
propertyArray[i] = value2Chars(eletyp, &ele.value);
}
propertyArray[n] = NULL;
- return propertyArray;
+
}
- } else {
- return NULL;
}
+ return propertyArray;
}
char * getUrlSyntax(char* sn, char * cs, char * port)
{
char * url_syntax;
- url_syntax = (char *) malloc((strlen(sn) + strlen(cs) + strlen(port) + 18) * sizeof(char)); //colon, double slash, colon, \0, service:wbem
+ //colon, double slash, colon, \0, service:wbem = 18
+ url_syntax = (char *) malloc((strlen(sn) + strlen(cs) + strlen(port) + 18) * sizeof(char));
sprintf(url_syntax, "service:wbem:%s://%s:%s", cs, sn, port);
- //sprintf(url_syntax, "%s://%s:%s", cs, sn, port);
free(sn);
View
41 cimslpCMPI.h
@@ -20,34 +20,33 @@
*/
#include <cmci.h>
-#include <native.h>
#include <unistd.h>
typedef struct {
- char * url_syntax;
- char * service_hi_name;
- char * service_hi_description;
- char * service_id;
- char * CommunicationMechanism;
- char * OtherCommunicationMechanismDescription;
- char ** InteropSchemaNamespace;
- char * ProtocolVersion;
- char ** FunctionalProfilesSupported;
- char ** FunctionalProfileDescriptions;
- char * MultipleOperationsSupported;
- char ** AuthenticationMechanismsSupported;
- char ** AuthenticationMechansimDescriptions;
- char ** Namespace;
- char ** Classinfo;
- char ** RegisteredProfilesSupported;
+ char * url_syntax;
+ char * service_hi_name;
+ char * service_hi_description;
+ char * service_id;
+ char * CommunicationMechanism;
+ char * OtherCommunicationMechanismDescription;
+ char ** InteropSchemaNamespace;
+ char * ProtocolVersion;
+ char ** FunctionalProfilesSupported;
+ char ** FunctionalProfileDescriptions;
+ char * MultipleOperationsSupported;
+ char ** AuthenticationMechanismsSupported;
+ char ** AuthenticationMechansimDescriptions;
+ char ** Namespace;
+ char ** Classinfo;
+ char ** RegisteredProfilesSupported;
} cimSLPService;
typedef struct {
char * commScheme; //http or https
char * cimhost;
char * port;
- char *cimuser;
- char *cimpassword;
+ char * cimuser;
+ char * cimpassword;
} cimomConfig;
extern char *value2Chars(CMPIType type, CMPIValue * value);
@@ -57,8 +56,8 @@ cimSLPService getSLPData(cimomConfig cfg);
char * myGetProperty(CMPIInstance *instance, char * propertyName);
char ** myGetPropertyArray(CMPIInstance *instance, char *propertyName);
char ** myGetPropertyArrayFromArray(CMPIInstance **instances, char *propertyName);
-CMPIInstance ** getInstances(CMCIClient *cc, char * path, char * objectname);
-CMPIInstance ** getInstances(CMCIClient *cc, char * path, char * objectname);
+CMPIInstance ** myGetInstances(CMCIClient *cc, char * path, char * objectname);
+CMPIConstClass * myGetClass(CMCIClient *cc, char * path, char * objectname);
char * transformValue(char * cssf, CMPIConstClass * ccls, char * propertyName);
char ** transformValueArray(char ** cssf, CMPIConstClass * ccls, char * propertyName);
char ** myGetRegProfiles(CMPIInstance **instances, CMCIClient *cc);
View
137 cimslpSLP.c
@@ -20,8 +20,10 @@
*/
#include <slp.h>
+
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include "cimslpCMPI.h"
#include "cimslpSLP.h"
@@ -37,20 +39,20 @@ void freeCSS(cimSLPService css)
{
freeStr(css.url_syntax);
freeStr(css.service_hi_name);
- freeStr(css.service_hi_description);
- freeStr(css.service_id);
- freeStr(css.CommunicationMechanism);
- freeStr(css.OtherCommunicationMechanismDescription);
+ freeStr(css.service_hi_description);
+ freeStr(css.service_id);
+ freeStr(css.CommunicationMechanism);
+ freeStr(css.OtherCommunicationMechanismDescription);
freeArr(css.InteropSchemaNamespace);
- freeStr(css.ProtocolVersion);
- freeArr(css.FunctionalProfilesSupported);
- freeArr(css.FunctionalProfileDescriptions);
- freeStr(css.MultipleOperationsSupported);
- freeArr(css.AuthenticationMechanismsSupported);
- freeArr(css.AuthenticationMechansimDescriptions);
- freeArr(css.Namespace);
- freeArr(css.Classinfo);
- freeArr(css.RegisteredProfilesSupported);
+ freeStr(css.ProtocolVersion);
+ freeArr(css.FunctionalProfilesSupported);
+ freeArr(css.FunctionalProfileDescriptions);
+ freeStr(css.MultipleOperationsSupported);
+ freeArr(css.AuthenticationMechanismsSupported);
+ freeArr(css.AuthenticationMechansimDescriptions);
+ freeArr(css.Namespace);
+ freeArr(css.Classinfo);
+ freeArr(css.RegisteredProfilesSupported);
}
void MySLPRegReport(SLPHandle hslp, SLPError errcode, void* cookie)
@@ -141,38 +143,61 @@ char* buildAttrStringFromArray(char * name, char ** value, char * attrstring)
}
-int registerCIMService(cimSLPService css) {
+int registerCIMService(cimSLPService css, int slpLifeTime)
+{
- SLPError err;
- SLPError callbackerr;
+ SLPError err = 0;
+ SLPError callbackerr = 0;
SLPHandle hslp;
char *attrstring;
+ int retCode = 0;
size = SIZE;
+
+ if(! css.url_syntax) {
+ freeCSS(css);
+ return 1;
+ }
+
attrstring = malloc(sizeof(char) * SIZE);
attrstring[0] = 0;
- attrstring = buildAttrString("service-hi-name", css.service_hi_name, attrstring);
- attrstring = buildAttrString("service-hi-description", css.service_hi_description, attrstring);
- attrstring = buildAttrString("service-id", css.service_id, attrstring);
- attrstring = buildAttrString("CommunicationMechanism", css.CommunicationMechanism, attrstring);
- attrstring = buildAttrString("OtherCommunicationMechanismDescription", css.OtherCommunicationMechanismDescription, attrstring);
- attrstring = buildAttrStringFromArray("InteropSchemaNamespace", css.InteropSchemaNamespace, attrstring);
- attrstring = buildAttrString("ProtocolVersion", css.ProtocolVersion, attrstring);
- attrstring = buildAttrStringFromArray("FunctionalProfilesSupported", css.FunctionalProfilesSupported, attrstring);
- attrstring = buildAttrStringFromArray("FunctionalProfileDescriptions", css.FunctionalProfileDescriptions, attrstring);
- attrstring = buildAttrString("MultipleOperationsSupported", css.MultipleOperationsSupported, attrstring);
- attrstring = buildAttrStringFromArray("AuthenticationMechanismsSupported", css.AuthenticationMechanismsSupported, attrstring);
- attrstring = buildAttrStringFromArray("AuthenticationMechansimDescriptions", css.AuthenticationMechansimDescriptions, attrstring);
- attrstring = buildAttrStringFromArray("Namespace", css.Namespace, attrstring);
- attrstring = buildAttrStringFromArray("Classinfo", css.Classinfo, attrstring);
- attrstring = buildAttrStringFromArray("RegisteredProfilesSupported", css.RegisteredProfilesSupported, attrstring);
+ attrstring = buildAttrString("service-hi-name",
+ css.service_hi_name, attrstring);
+ attrstring = buildAttrString("service-hi-description",
+ css.service_hi_description, attrstring);
+ attrstring = buildAttrString("service-id",
+ css.service_id, attrstring);
+ attrstring = buildAttrString("CommunicationMechanism",
+ css.CommunicationMechanism, attrstring);
+ attrstring = buildAttrString("OtherCommunicationMechanismDescription",
+ css.OtherCommunicationMechanismDescription, attrstring);
+ attrstring = buildAttrStringFromArray("InteropSchemaNamespace",
+ css.InteropSchemaNamespace, attrstring);
+ attrstring = buildAttrString("ProtocolVersion",
+ css.ProtocolVersion, attrstring);
+ attrstring = buildAttrStringFromArray("FunctionalProfilesSupported",
+ css.FunctionalProfilesSupported, attrstring);
+ attrstring = buildAttrStringFromArray("FunctionalProfileDescriptions",
+ css.FunctionalProfileDescriptions, attrstring);
+ attrstring = buildAttrString("MultipleOperationsSupported",
+ css.MultipleOperationsSupported, attrstring);
+ attrstring = buildAttrStringFromArray("AuthenticationMechanismsSupported",
+ css.AuthenticationMechanismsSupported, attrstring);
+ attrstring = buildAttrStringFromArray("AuthenticationMechansimDescriptions",
+ css.AuthenticationMechansimDescriptions, attrstring);
+ attrstring = buildAttrStringFromArray("Namespace",
+ css.Namespace, attrstring);
+ attrstring = buildAttrStringFromArray("Classinfo",
+ css.Classinfo, attrstring);
+ attrstring = buildAttrStringFromArray("RegisteredProfilesSupported",
+ css.RegisteredProfilesSupported, attrstring);
err = SLPOpen("", SLP_FALSE, &hslp);
if(err != SLP_OK)
{
printf("Error opening slp handle %i\n",err);
- return err;
+ retCode = err;
}
if(strcmp(gAttrstring, attrstring)) {
@@ -188,31 +213,29 @@ int registerCIMService(cimSLPService css) {
free(gAttrstring);
printf("deregistered!\n");
}
-
- err = SLPReg( hslp,
- css.url_syntax,
- SLP_LIFETIME_MAXIMUM,
- NULL,
- attrstring,
- SLP_TRUE,
- MySLPRegReport,
- &callbackerr );
- printf("registered!\n");
- printf("url_syntax: %s\n", css.url_syntax);
- printf("attrsting: %s\n", attrstring);
-
- if(( err != SLP_OK) || (callbackerr != SLP_OK))
- {
- printf("Error registering service with slp %i\n",err);
- //return err;
- }
+ }
+ err = SLPReg( hslp,
+ css.url_syntax,
+ slpLifeTime,
+ NULL,
+ attrstring,
+ SLP_TRUE,
+ MySLPRegReport,
+ &callbackerr );
+ printf("registered!\n");
+ printf("url_syntax: %s\n", css.url_syntax);
+ printf("attrsting: %s\n", attrstring);
+
+ if(( err != SLP_OK) || (callbackerr != SLP_OK)) {
+ printf("Error registering service with slp %i\n",err);
+ retCode = err;
+ }
+
+ if( callbackerr != SLP_OK) {
+ printf("Error registering service with slp %i\n",callbackerr);
+ retCode = callbackerr;
+ }
- if( callbackerr != SLP_OK)
- {
- printf("Error registering service with slp %i\n",callbackerr);
- //return callbackerr;
- }
- }
//only save the last state when something changed to not waste mallocs
@@ -224,5 +247,7 @@ int registerCIMService(cimSLPService css) {
freeCSS(css);
SLPClose(hslp);
+
+ return retCode;
}
View
2  cimslpSLP.h
@@ -21,4 +21,4 @@
char* buildAttrString(char * name, char * value, char * attrstring);
char* buildAttrStringFromArray(char * name, char ** value, char * attrstring);
-int registerCIMService(cimSLPService css);
+int registerCIMService(cimSLPService css, int slpLifeTime);
View
2  cimslpUtil.c
@@ -21,6 +21,8 @@
#include "cimslpUtil.h"
+#include <stdlib.h>
+
/*void freeStrArr(char ** arr) {
int n=0;
if (arr) {while (arr[n]) free(arr[n++]);free(arr);}
View
6 cimslpUtil.h
@@ -21,9 +21,9 @@
#include <cmci.h>
-//#define freeArr(arr) \
-// {int freeStrArrN=0;if (arr) {while (arr[freeStrArrN]) free(arr[freeStrArrN++]);free(arr);}}
-
+/*#define freeArr(arr) \
+ {int freeStrArrN=0;if (arr) {while (arr[freeStrArrN]) free(arr[freeStrArrN++]);free(arr);}}
+*/
#define freeStr(str) \
{if (str) free(str);}
View
32 configure.ac
@@ -1,4 +1,4 @@
-# $Id: configure.ac,v 1.39 2006/02/28 09:17:23 mihajlov Exp $
+# $Id: configure.ac,v 1.40 2006/07/17 13:04:18 sschuetz Exp $
#
# configure.ac
#
@@ -42,6 +42,10 @@ AC_ARG_ENABLE(jdbc,
[AC_HELP_STRING([--enable-jdbc],
[include server-side JDBC support for SFCB - EXPERIMENTAL.])])
+AC_ARG_ENABLE(slp,
+ [AC_HELP_STRING([--enable-slp],
+ [include slp agent for SFCB - EXPERIMENTAL.])])
+
AC_ARG_ENABLE(indications,
[AC_HELP_STRING([--disable-indications],
[disable indication support for SFCB - currently not working.])],
@@ -59,6 +63,14 @@ if test "$enable_jdbc" == "yes"; then
AC_DEFINE(HAVE_JDBC,,[JDBC support enabled.])
fi
+if test "$enable_slp" == "standalone"; then
+ AC_DEFINE(HAVE_SLP_ALONE,,[SLP standalone support enabled.])
+fi
+
+if test "$enable_slp" == "yes"; then
+ AC_DEFINE(HAVE_SLP,,[SLP support enabled.])
+fi
+
AC_CANONICAL_HOST
case $host_os in
openedition*) SFCB_CMPI_PLATFORM="-D CMPI_PLATFORM_LINUX_GENERIC_GNU"
@@ -120,6 +132,21 @@ if test "$enable_ssl" = "yes"; then
AC_CHECK_LIB(ssl,main)
fi
+if test "$enable_slp" = "yes"; then
+ CPPFLAGS="-I /usr/local/include/CimClientLib $CPPFLAGS"
+ AC_CHECK_HEADER([cmci.h])
+ AC_CHECK_LIB(slp,SLPReg)
+ AC_CHECK_LIB(cmpisfcc,cmciConnect)
+
+fi
+
+if test "$enable_slp" = "standalone"; then
+ CPPFLAGS="-I /usr/local/include/CimClientLib $CPPFLAGS"
+ AC_CHECK_HEADER([cmci.h])
+ AC_CHECK_LIB(slp,SLPReg)
+ AC_CHECK_LIB(cmpisfcc,cmciConnect)
+fi
+
# Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
@@ -172,6 +199,8 @@ fi
AM_CONDITIONAL(INDICATIONS,[test "$enable_indications" == "yes"])
AM_CONDITIONAL(JDBC,[test "$enable_jdbc" == "yes"])
+AM_CONDITIONAL(SLP,[test "$enable_slp" == "yes"])
+AM_CONDITIONAL(SLP_ALONE,[test "$enable_slp" == "standalone"])
AC_CONFIG_FILES([Makefile sfcb.spec sfcbrepos.sh sfcbstage.sh sfcbunstage.sh
sfcbuuid.sh sfcb.cfg.pre getSchema.sh.pre
@@ -189,4 +218,5 @@ echo -e "debug"\\t"${enable_debug:-no}"
echo -e "indications"\\t"${enable_indications}"
echo -e "ssl"\\t"${enable_ssl:-no}"
echo -e "jdbc"\\t"${enable_jdbc:-no}"
+echo -e "slp"\\t"${enable_slp:-no}"
echo ======================================================
View
4 genericlist.c
@@ -36,8 +36,8 @@
#include <stdio.h>
#include <stdlib.h>
#include "genericlist.h"
-#include "mlog.h"
-#include "support.h"
+#include "../mlog.h"
+#include "../support.h"
#ifdef THINK_C
View
910 hashtable.c
@@ -1,910 +0,0 @@
-
-/*
- * hashtable.c
- *
- * (C) Copyright IBM Corp. 2005
- *
- * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
- * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
- * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
- *
- * You can obtain a current copy of the Eclipse Public License from
- * http://www.opensource.org/licenses/eclipse-1.0.php
- *
- * Author: Keith Pomakis <pomaki@pobox.xom>
- * Contributions: Adrian Schuur <schuur@de.ibm.com>
- *
- * Description:
- *
- * hashtable implementation.
- *
-*/
-
-/*--------------------------------------------------------------------------*\
- * -----===== HashTable =====-----
- *
- * Author: Keith Pomakis (pomakis@pobox.com)
- * Date: August, 1998
- *
-\*--------------------------------------------------------------------------*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-#include "hashtable.h"
-#include "utilft.h"
-
-#define NEW(x) ((x *) malloc(sizeof(x)))
-
-static int pointercmp(const void *pointer1, const void *pointer2);
-static unsigned long pointerHashFunction(const void *pointer);
-static int isProbablePrime(long number);
-static long calculateIdealNumOfBuckets(HashTable * hashTable);
-
-static void *HashTableGet(const HashTable * hashTable, const void *key);
-static void HashTableRehash(HashTable * hashTable, long numOfBuckets);
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableCreate() - creates a new HashTable
- * DESCRIPTION:
- * Creates a new HashTable. When finished with this HashTable, it
- * should be explicitly destroyed by calling the HashTableDestroy()
- * function.
- * EFFICIENCY:
- * O(1)
- * ARGUMENTS:
- * numOfBuckets - the number of buckets to start the HashTable out with.
- * Must be greater than zero, and should be prime.
- * Ideally, the number of buckets should between 1/5
- * and 1 times the expected number of elements in the
- * HashTable. Values much more or less than this will
- * result in wasted memory or decreased performance
- * respectively. The number of buckets in a HashTable
- * can be re-calculated to an appropriate number by
- * calling the HashTableRehash() function once the
- * HashTable has been populated. The number of buckets
- * in a HashTable may also be re-calculated
- * automatically if the ratio of elements to buckets
- * passes the thresholds set by HashTableSetIdealRatio().
- * RETURNS:
- * HashTable - a new Hashtable, or NULL on error
-\*--------------------------------------------------------------------------*/
-
-void *HashTableCreate(long numOfBuckets)
-{
- HashTable *hashTable;
- int i;
-
- assert(numOfBuckets > 0);
-
- hashTable = (HashTable *) malloc(sizeof(HashTable));
- if (hashTable == NULL)
- return NULL;
-
- hashTable->bucketArray = (KeyValuePair **)
- malloc(numOfBuckets * sizeof(KeyValuePair *));
- if (hashTable->bucketArray == NULL) {
- free(hashTable);
- return NULL;
- }
-
- hashTable->numOfBuckets = numOfBuckets;
- hashTable->numOfElements = 0;
-
- for (i = 0; i < numOfBuckets; i++)
- hashTable->bucketArray[i] = NULL;
-
- hashTable->idealRatio = 3.0;
- hashTable->lowerRehashThreshold = 0.0;
- hashTable->upperRehashThreshold = 15.0;
-
- hashTable->keycmp = pointercmp;
- hashTable->valuecmp = pointercmp;
- hashTable->hashFunction = pointerHashFunction;
- hashTable->keyDeallocator = NULL;
- hashTable->valueDeallocator = NULL;
-
- return hashTable;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableDestroy() - destroys an existing HashTable
- * DESCRIPTION:
- * Destroys an existing HashTable.
- * EFFICIENCY:
- * O(n)
- * ARGUMENTS:
- * hashTable - the HashTable to destroy
- * RETURNS:
- * <nothing>
-\*--------------------------------------------------------------------------*/
-
-static void HashTableDestroy(HashTable * hashTable)
-{
- int i;
-
- for (i = 0; i < hashTable->numOfBuckets; i++) {
- KeyValuePair *pair = hashTable->bucketArray[i];
- while (pair != NULL) {
- KeyValuePair *nextPair = pair->next;
- if (hashTable->keyDeallocator != NULL)
- hashTable->keyDeallocator((void *) pair->key);
- if (hashTable->valueDeallocator != NULL)
- hashTable->valueDeallocator(pair->value);
- free(pair);
- pair = nextPair;
- }
- }
-
- free(hashTable->bucketArray);
- free(hashTable);
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableContainsKey() - checks the existence of a key in a HashTable
- * DESCRIPTION:
- * Determines whether or not the specified HashTable contains the
- * specified key. Uses the comparison function specified by
- * HashTableSetKeyComparisonFunction().
- * EFFICIENCY:
- * O(1), assuming a good hash function and element-to-bucket ratio
- * ARGUMENTS:
- * hashTable - the HashTable to search
- * key - the key to search for
- * RETURNS:
- * bool - whether or not the specified HashTable contains the
- * specified key.
-\*--------------------------------------------------------------------------*/
-
-static int HashTableContainsKey(const HashTable * hashTable, const void *key)
-{
- return (HashTableGet(hashTable, key) != NULL);
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableContainsValue()
- * - checks the existence of a value in a HashTable
- * DESCRIPTION:
- * Determines whether or not the specified HashTable contains the
- * specified value. Unlike HashTableContainsKey(), this function is
- * not very efficient, since it has to scan linearly looking for a
- * match. Uses the comparison function specified by
- * HashTableSetValueComparisonFunction().
- * EFFICIENCY:
- * O(n)
- * ARGUMENTS:
- * hashTable - the HashTable to search
- * value - the value to search for
- * RETURNS:
- * bool - whether or not the specified HashTable contains the
- * specified value.
-\*--------------------------------------------------------------------------*/
-
-static int HashTableContainsValue(const HashTable * hashTable,
- const void *value)
-{
- int i;
-
- for (i = 0; i < hashTable->numOfBuckets; i++) {
- KeyValuePair *pair = hashTable->bucketArray[i];
- while (pair != NULL) {
- if (hashTable->valuecmp(value, pair->value) == 0)
- return 1;
- pair = pair->next;
- }
- }
-
- return 0;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTablePut() - adds a key/value pair to a HashTable
- * DESCRIPTION:
- * Adds the specified key/value pair to the specified HashTable. If
- * the key already exists in the HashTable (determined by the comparison
- * function specified by HashTableSetKeyComparisonFunction()), its value
- * is replaced by the new value. May trigger an auto-rehash (see
- * HashTableSetIdealRatio()). It is illegal to specify NULL as the
- * key or value.
- * EFFICIENCY:
- * O(1), assuming a good hash function and element-to-bucket ratio
- * ARGUMENTS:
- * hashTable - the HashTable to add to
- * key - the key to add or whose value to replace
- * value - the value associated with the key
- * RETURNS:
- * err - 0 if successful, -1 if an error was encountered
-\*--------------------------------------------------------------------------*/
-
-static int HashTablePut(HashTable * hashTable, const void *key, void *value)
-{
- long hashValue;
- KeyValuePair *pair;
-
- assert(key != NULL);
- assert(value != NULL);
-
- hashValue = hashTable->hashFunction(key) % hashTable->numOfBuckets;
- pair = hashTable->bucketArray[hashValue];
-
- while (pair != NULL && hashTable->keycmp(key, pair->key) != 0)
- pair = pair->next;
-
- if (pair) {
- if (pair->key != key) {
- if (hashTable->keyDeallocator != NULL)
- hashTable->keyDeallocator((void *) pair->key);
- pair->key = key;
- }
- if (pair->value != value) {
- if (hashTable->valueDeallocator != NULL)
- hashTable->valueDeallocator(pair->value);
- pair->value = value;
- }
- }
- else {
- KeyValuePair *newPair = (KeyValuePair *) malloc(sizeof(KeyValuePair));
- if (newPair == NULL) {
- return -1;
- }
- else {
- newPair->key = key;
- newPair->value = value;
- newPair->next = hashTable->bucketArray[hashValue];
- hashTable->bucketArray[hashValue] = newPair;
- hashTable->numOfElements++;
-
- if (hashTable->upperRehashThreshold > hashTable->idealRatio) {
- float elementToBucketRatio =
- (float) hashTable->numOfElements /
- (float) hashTable->numOfBuckets;
- if (elementToBucketRatio > hashTable->upperRehashThreshold)
- HashTableRehash(hashTable, 0);
- }
- }
- }
-
- return 0;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableGet() - retrieves the value of a key in a HashTable
- * DESCRIPTION:
- * Retrieves the value of the specified key in the specified HashTable.
- * Uses the comparison function specified by
- * HashTableSetKeyComparisonFunction().
- * EFFICIENCY:
- * O(1), assuming a good hash function and element-to-bucket ratio
- * ARGUMENTS:
- * hashTable - the HashTable to search
- * key - the key whose value is desired
- * RETURNS:
- * void * - the value of the specified key, or NULL if the key
- * doesn't exist in the HashTable
-\*--------------------------------------------------------------------------*/
-
-static void *HashTableGet(const HashTable * hashTable, const void *key)
-{
- long hashValue = hashTable->hashFunction(key) % hashTable->numOfBuckets;
- KeyValuePair *pair = hashTable->bucketArray[hashValue];
-
- while (pair != NULL && hashTable->keycmp(key, pair->key) != 0)
- pair = pair->next;
-
- return (pair == NULL) ? NULL : pair->value;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableRemove() - removes a key/value pair from a HashTable
- * DESCRIPTION:
- * Removes the key/value pair identified by the specified key from the
- * specified HashTable if the key exists in the HashTable. May trigger
- * an auto-rehash (see HashTableSetIdealRatio()).
- * EFFICIENCY:
- * O(1), assuming a good hash function and element-to-bucket ratio
- * ARGUMENTS:
- * hashTable - the HashTable to remove the key/value pair from
- * key - the key specifying the key/value pair to be removed
- * RETURNS:
- * <nothing>
-\*--------------------------------------------------------------------------*/
-
-static void HashTableRemove(HashTable * hashTable, const void *key)
-{
- long hashValue = hashTable->hashFunction(key) % hashTable->numOfBuckets;
- KeyValuePair *pair = hashTable->bucketArray[hashValue];
- KeyValuePair *previousPair = NULL;
-
- while (pair != NULL && hashTable->keycmp(key, pair->key) != 0) {
- previousPair = pair;
- pair = pair->next;
- }
-
- if (pair != NULL) {
- if (hashTable->keyDeallocator != NULL)
- hashTable->keyDeallocator((void *) pair->key);
- if (hashTable->valueDeallocator != NULL)
- hashTable->valueDeallocator(pair->value);
- if (previousPair != NULL)
- previousPair->next = pair->next;
- else
- hashTable->bucketArray[hashValue] = pair->next;
- free(pair);
- hashTable->numOfElements--;
-
- if (hashTable->lowerRehashThreshold > 0.0) {
- float elementToBucketRatio = (float) hashTable->numOfElements /
- (float) hashTable->numOfBuckets;
- if (elementToBucketRatio < hashTable->lowerRehashThreshold)
- HashTableRehash(hashTable, 0);
- }
- }
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableRemoveAll() - removes all key/value pairs from a HashTable
- * DESCRIPTION:
- * Removes all key/value pairs from the specified HashTable. May trigger
- * an auto-rehash (see HashTableSetIdealRatio()).
- * EFFICIENCY:
- * O(n)
- * ARGUMENTS:
- * hashTable - the HashTable to remove all key/value pairs from
- * RETURNS:
- * <nothing>
-\*--------------------------------------------------------------------------*/
-
-static void HashTableRemoveAll(HashTable * hashTable)
-{
- int i;
-
- for (i = 0; i < hashTable->numOfBuckets; i++) {
- KeyValuePair *pair = hashTable->bucketArray[i];
- while (pair != NULL) {
- KeyValuePair *nextPair = pair->next;
- if (hashTable->keyDeallocator != NULL)
- hashTable->keyDeallocator((void *) pair->key);
- if (hashTable->valueDeallocator != NULL)
- hashTable->valueDeallocator(pair->value);
- free(pair);
- pair = nextPair;
- }
- hashTable->bucketArray[i] = NULL;
- }
-
- hashTable->numOfElements = 0;
- HashTableRehash(hashTable, 5);
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableIsEmpty() - determines if a HashTable is empty
- * DESCRIPTION:
- * Determines whether or not the specified HashTable contains any
- * key/value pairs.
- * EFFICIENCY:
- * O(1)
- * ARGUMENTS:
- * hashTable - the HashTable to check
- * RETURNS:
- * bool - whether or not the specified HashTable contains any
- * key/value pairs
-\*--------------------------------------------------------------------------*/
-
-static int HashTableIsEmpty(const HashTable * hashTable)
-{
- return (hashTable->numOfElements == 0);
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableSize() - returns the number of elements in a HashTable
- * DESCRIPTION:
- * Returns the number of key/value pairs that are present in the
- * specified HashTable.
- * EFFICIENCY:
- * O(1)
- * ARGUMENTS:
- * hashTable - the HashTable whose size is requested
- * RETURNS:
- * long - the number of key/value pairs that are present in
- * the specified HashTable
-\*--------------------------------------------------------------------------*/
-
-static long HashTableSize(const HashTable * hashTable)
-{
- return hashTable->numOfElements;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableGetNumBuckets() - returns the number of buckets in a HashTable
- * DESCRIPTION:
- * Returns the number of buckets that are in the specified HashTable.
- * This may change dynamically throughout the life of a HashTable if
- * automatic or manual rehashing is performed.
- * EFFICIENCY:
- * O(1)
- * ARGUMENTS:
- * hashTable - the HashTable whose number of buckets is requested
- * RETURNS:
- * long - the number of buckets that are in the specified
- * HashTable
-\*--------------------------------------------------------------------------*/
-
-static long HashTableGetNumBuckets(const HashTable * hashTable)
-{
- return hashTable->numOfBuckets;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableSetKeyComparisonFunction()
- * - specifies the function used to compare keys in a HashTable
- * DESCRIPTION:
- * Specifies the function used to compare keys in the specified
- * HashTable. The specified function should return zero if the two
- * keys are considered equal, and non-zero otherwise. The default
- * function is one that simply compares pointers.
- * ARGUMENTS:
- * hashTable - the HashTable whose key comparison function is being
- * specified
- * keycmp - a function which returns zero if the two arguments
- * passed to it are considered "equal" keys and non-zero
- * otherwise
- * RETURNS:
- * <nothing>
-\*--------------------------------------------------------------------------*/
-
-static void HashTableSetKeyComparisonFunction(HashTable * hashTable,
- int (*keycmp) (const void
- *key1,
- const void *key2))
-{
- assert(keycmp != NULL);
- hashTable->keycmp = keycmp;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableSetValueComparisonFunction()
- * - specifies the function used to compare values in a HashTable
- * DESCRIPTION:
- * Specifies the function used to compare values in the specified
- * HashTable. The specified function should return zero if the two
- * values are considered equal, and non-zero otherwise. The default
- * function is one that simply compares pointers.
- * ARGUMENTS:
- * hashTable - the HashTable whose value comparison function is being
- * specified
- * valuecmp - a function which returns zero if the two arguments
- * passed to it are considered "equal" values and non-zero
- * otherwise
- * RETURNS:
- * <nothing>
-\*--------------------------------------------------------------------------*/
-
-static void HashTableSetValueComparisonFunction(HashTable * hashTable,
- int (*valuecmp) (const void
- *value1,
- const void
- *value2))
-{
- assert(valuecmp != NULL);
- hashTable->valuecmp = valuecmp;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableSetHashFunction()
- * - specifies the hash function used by a HashTable
- * DESCRIPTION:
- * Specifies the function used to determine the hash value for a key
- * in the specified HashTable (before modulation). An ideal hash
- * function is one which is easy to compute and approximates a
- * "random" function. The default function is one that works
- * relatively well for pointers. If the HashTable keys are to be
- * strings (which is probably the case), then this default function
- * will not suffice, in which case consider using the provided
- * HashTableStringHashFunction() function.
- * ARGUMENTS:
- * hashTable - the HashTable whose hash function is being specified
- * hashFunction - a function which returns an appropriate hash code
- * for a given key
- * RETURNS:
- * <nothing>
-\*--------------------------------------------------------------------------*/
-
-static void HashTableSetHashFunction(HashTable * hashTable,
- unsigned long (*hashFunction) (const
- void *key))
-{
- assert(hashFunction != NULL);
- hashTable->hashFunction = hashFunction;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableRehash() - reorganizes a HashTable to be more efficient
- * DESCRIPTION:
- * Reorganizes a HashTable to be more efficient. If a number of
- * buckets is specified, the HashTable is rehashed to that number of
- * buckets. If 0 is specified, the HashTable is rehashed to a number
- * of buckets which is automatically calculated to be a prime number
- * that achieves (as closely as possible) the ideal element-to-bucket
- * ratio specified by the HashTableSetIdealRatio() function.
- * EFFICIENCY:
- * O(n)
- * ARGUMENTS:
- * hashTable - the HashTable to be reorganized
- * numOfBuckets - the number of buckets to rehash the HashTable to.
- * Should be prime. Ideally, the number of buckets
- * should be between 1/5 and 1 times the expected
- * number of elements in the HashTable. Values much
- * more or less than this will result in wasted memory
- * or decreased performance respectively. If 0 is
- * specified, an appropriate number of buckets is
- * automatically calculated.
- * RETURNS:
- * <nothing>
-\*--------------------------------------------------------------------------*/
-
-static void HashTableRehash(HashTable * hashTable, long numOfBuckets)
-{
- KeyValuePair **newBucketArray;
- int i;
-
- assert(numOfBuckets >= 0);
- if (numOfBuckets == 0)
- numOfBuckets = calculateIdealNumOfBuckets(hashTable);
-
- if (numOfBuckets == hashTable->numOfBuckets)
- return; /* already the right size! */
-
- newBucketArray = (KeyValuePair **)
- malloc(numOfBuckets * sizeof(KeyValuePair *));
- if (newBucketArray == NULL) {
- /* Couldn't allocate memory for the new array. This isn't a fatal
- * error; we just can't perform the rehash. */
- return;
- }
-
- for (i = 0; i < numOfBuckets; i++)
- newBucketArray[i] = NULL;
-
- for (i = 0; i < hashTable->numOfBuckets; i++) {
- KeyValuePair *pair = hashTable->bucketArray[i];
- while (pair != NULL) {
- KeyValuePair *nextPair = pair->next;
- long hashValue = hashTable->hashFunction(pair->key) % numOfBuckets;
- pair->next = newBucketArray[hashValue];
- newBucketArray[hashValue] = pair;
- pair = nextPair;
- }
- }
-
- free(hashTable->bucketArray);
- hashTable->bucketArray = newBucketArray;
- hashTable->numOfBuckets = numOfBuckets;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableSetIdealRatio()
- * - sets the ideal element-to-bucket ratio of a HashTable
- * DESCRIPTION:
- * Sets the ideal element-to-bucket ratio, as well as the lower and
- * upper auto-rehash thresholds, of the specified HashTable. Note
- * that this function doesn't actually perform a rehash.
- *
- * The default values for these properties are 3.0, 0.0 and 15.0
- * respectively. This is likely fine for most situations, so there
- * is probably no need to call this function.
- * ARGUMENTS:
- * hashTable - a HashTable
- * idealRatio - the ideal element-to-bucket ratio. When a rehash
- * occurs (either manually via a call to the
- * HashTableRehash() function or automatically due the
- * the triggering of one of the thresholds below), the
- * number of buckets in the HashTable will be
- * recalculated to be a prime number that achieves (as
- * closely as possible) this ideal ratio. Must be a
- * positive number.
- * lowerRehashThreshold
- * - the element-to-bucket ratio that is considered
- * unacceptably low (i.e., too few elements per bucket).
- * If the actual ratio falls below this number, a
- * rehash will automatically be performed. Must be
- * lower than the value of idealRatio. If no ratio
- * is considered unacceptably low, a value of 0.0 can
- * be specified.
- * upperRehashThreshold
- * - the element-to-bucket ratio that is considered
- * unacceptably high (i.e., too many elements per bucket).
- * If the actual ratio rises above this number, a
- * rehash will automatically be performed. Must be
- * higher than idealRatio. However, if no ratio
- * is considered unacceptably high, a value of 0.0 can
- * be specified.
- * RETURNS:
- * <nothing>
-\*--------------------------------------------------------------------------*/
-/*
-static void HashTableSetIdealRatio(HashTable *hashTable, float idealRatio,
- float lowerRehashThreshold, float upperRehashThreshold) {
- assert(idealRatio > 0.0);
- assert(lowerRehashThreshold < idealRatio);
- assert(upperRehashThreshold == 0.0 || upperRehashThreshold > idealRatio);
-
- hashTable->idealRatio = idealRatio;
- hashTable->lowerRehashThreshold = lowerRehashThreshold;
- hashTable->upperRehashThreshold = upperRehashThreshold;
-}
-*/
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableSetDeallocationFunctions()
- * - sets the key and value deallocation functions of a HashTable
- * DESCRIPTION:
- * Sets the key and value deallocation functions of the specified
- * HashTable. This determines what happens to a key or a value when it
- * is removed from the HashTable. If the deallocation function is NULL
- * (the default if this function is never called), its reference is
- * simply dropped and it is up to the calling program to perform the
- * proper memory management. If the deallocation function is non-NULL,
- * it is called to free the memory used by the object. E.g., for simple
- * objects, an appropriate deallocation function may be free().
- *
- * This affects the behaviour of the HashTableDestroy(), HashTablePut(),
- * HashTableRemove() and HashTableRemoveAll() functions.
- * ARGUMENTS:
- * hashTable - a HashTable
- * keyDeallocator
- * - if non-NULL, the function to be called when a key is
- * removed from the HashTable.
- * valueDeallocator
- * - if non-NULL, the function to be called when a value is
- * removed from the HashTable.
- * RETURNS:
- * <nothing>
-\*--------------------------------------------------------------------------*/
-
-static void HashTableSetDeallocationFunctions(HashTable * hashTable,
- void (*keyDeallocator) (void
- *key),
- void (*valueDeallocator)
- (void *value))
-{
- hashTable->keyDeallocator = keyDeallocator;
- hashTable->valueDeallocator = valueDeallocator;
-}
-
-/*--------------------------------------------------------------------------*\
- * NAME:
- * HashTableStringHashFunction() - a good hash function for strings
- * DESCRIPTION:
- * A hash function that is appropriate for hashing strings. Note that
- * this is not the default hash function. To make it the default hash
- * function, call HashTableSetHashFunction(hashTable,
- * HashTableStringHashFunction).
- * ARGUMENTS:
- * key - the key to be hashed
- * RETURNS:
- * unsigned long - the unmodulated hash value of the key
-\*--------------------------------------------------------------------------*/
-/*
-static unsigned long HashTableStringHashFunction(const void *key) {
- const unsigned char *str = (const unsigned char *) key;
- unsigned long hashValue = 0;
- int i;
-
- for (i=0; str[i] != '\0'; i++)
- hashValue = hashValue * 37 + str[i];
-
- return hashValue;
-}
-*/
-static int pointercmp(const void *pointer1, const void *pointer2)
-{
- return (pointer1 != pointer2);
-}
-
-static unsigned long pointerHashFunction(const void *pointer)
-{
- return ((unsigned long) pointer) >> 4;
-}
-
-static int isProbablePrime(long oddNumber)
-{
- long i;
-
- for (i = 3; i < 51; i += 2)
- if (oddNumber == i)
- return 1;
- else if (oddNumber % i == 0)
- return 0;
-
- return 1; /* maybe */
-}
-
-static long calculateIdealNumOfBuckets(HashTable * hashTable)
-{
- long idealNumOfBuckets = hashTable->numOfElements / hashTable->idealRatio;
- if (idealNumOfBuckets < 5)
- idealNumOfBuckets = 5;
- else
- idealNumOfBuckets |= 0x01; /* make it an odd number */
- while (!isProbablePrime(idealNumOfBuckets))
- idealNumOfBuckets += 2;
- return idealNumOfBuckets;
-}
-
-static UtilHashTable *NotSupported(UtilHashTable * ht)
-{
- return NULL;
-}
-
-static void hashTableDestroy(UtilHashTable * ht)
-{
- HashTableDestroy((HashTable *) ht->hdl);
- free(ht);
-}
-
-static void hashTableRemoveAll(UtilHashTable * ht)
-{
- HashTableRemoveAll((HashTable *) ht->hdl);
-}
-
-static int hashTableContainsKey(const UtilHashTable * ht, const void *key)
-{
- return HashTableContainsKey((HashTable *) ht->hdl, key);
-}
-
-static int hashTableContainsValue(const UtilHashTable * ht, const void *val)
-{
- return HashTableContainsValue((HashTable *) ht->hdl, val);
-}
-
-static int hashTablePut(UtilHashTable * ht, const void *key, void *val)
-{
- return HashTablePut((HashTable *) ht->hdl, key, val);
-}
-
-static void *hashTableGet(const UtilHashTable * ht, const void *key)
-{
- return HashTableGet((HashTable *) ht->hdl, key);
-}
-
-static void hashTableRemove(UtilHashTable * ht, const void *key)
-{
- HashTableRemove((HashTable *) ht->hdl, key);
-}
-
-static int hashTableIsEmpty(const UtilHashTable * ht)
-{
- return HashTableIsEmpty((HashTable *) ht->hdl);
-}
-
-static int hashTableSize(const UtilHashTable * ht)
-{
- return HashTableSize((HashTable *) ht->hdl);
-}
-
-static int hashTableGetNumBuckets(const UtilHashTable * ht)
-{
- return HashTableGetNumBuckets((HashTable *) ht->hdl);
-}
-
-static void hashTableRehash(UtilHashTable * ht, int buckets)
-{
- HashTableRehash((HashTable *) ht->hdl, buckets);
-}
-
-static HashTableIterator *hashTableGetFirst(UtilHashTable * ht, void **key,
- void **val)
-{
- HashTable *t = (HashTable *) ht->hdl;
- HashTableIterator *iter = NEW(HashTableIterator);
- for (iter->bucket = 0; iter->bucket < t->numOfBuckets; iter->bucket++) {
- iter->pair = t->bucketArray[iter->bucket];
- if (iter->pair != NULL) {
- *key = (void *) iter->pair->key;
- *val = iter->pair->value;
- return iter;
- }
- }
- free(iter);
- return NULL;
-}
-
-static HashTableIterator *hashTableGetNext(UtilHashTable * ht,
- HashTableIterator * iter,
- void **key, void **val)
-{
- HashTable *t = (HashTable *) ht->hdl;
- iter->pair = iter->pair->next;
- while (iter->bucket < t->numOfBuckets) {
- if (iter->pair == NULL) {
- if (iter->bucket+1 < t->numOfBuckets)
- iter->pair = t->bucketArray[++iter->bucket];
- else break;
- continue;
- }
- *key = (void *) iter->pair->key;
- *val = iter->pair->value;
- return iter;
- }
- free(iter);
- return NULL;
-}
-
-static void hashTableSetKeyComparisonFunction(UtilHashTable * ht,
- int (*keycomp) (const void
- *k1,
- const void *k2))
-{
- HashTable *t = (HashTable *) ht->hdl;
- HashTableSetKeyComparisonFunction(t, keycomp);
-}
-
-static void hashTableSetValueComparisonFunction(UtilHashTable * ht,
- int (*valcomp) (const void
- *v1,
- const void *v2))
-{
- HashTable *t = (HashTable *) ht->hdl;
- HashTableSetValueComparisonFunction(t, valcomp);
-}
-
-static void hashTableSetHashFunction(UtilHashTable * ht,
- unsigned long (*hashFunction) (const
- void *key))
-{
- HashTable *t = (HashTable *) ht->hdl;
- HashTableSetHashFunction(t, hashFunction);
-}
-
-static void hashTableSetDeallocationFunctions(UtilHashTable * ht,
- void (*keyRelease) (void
- *key),
- void (*valueRelease) (void
- *value))
-{
- HashTable *t = (HashTable *) ht->hdl;
- HashTableSetDeallocationFunctions(t, keyRelease, valueRelease);
-}
-
-static Util_HashTable_FT ift = {
- 1,
- hashTableDestroy, // release
- NotSupported, // clone
- hashTableRemoveAll, // clear
- hashTableContainsKey, // containsKey
- hashTableContainsValue, // containsValue
- hashTablePut, // put
- hashTableGet, // get
- hashTableRemove, // remove
- hashTableIsEmpty, // isEmpty
- hashTableSize, // size
- hashTableGetNumBuckets, // buckets
- hashTableRehash, // rehash
-
- hashTableGetFirst, // getFirst
- hashTableGetNext, // getNext
-
- hashTableSetKeyComparisonFunction, // setKeyCmpFunction
- hashTableSetValueComparisonFunction, // setValueCmpFunction
- hashTableSetHashFunction, // setHashFunction
- hashTableSetDeallocationFunctions, // setReleaseFunctions
-};
-
-
-Util_HashTable_FT *UtilHashTableFT = &ift;
View
63 hashtable.h
@@ -1,63 +0,0 @@
-
-/*
- * hashtable.h
- *
- * (C) Copyright IBM Corp. 2005
- *
- * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
- * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
- * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
- *
- * You can obtain a current copy of the Eclipse Public License from
- * http://www.opensource.org/licenses/eclipse-1.0.php
- *
- * Author: Keith Pomakis <pomaki@pobox.xom>
- * Contributions: Adrian Schuur <schuur@de.ibm.com>
- *
- * Description:
- *
- * hashtable implementation.
- *
-*/
-
-/*--------------------------------------------------------------------------*\
- * -----===== HashTable =====-----
- *
- * Author: Keith Pomakis (pomakis@pobox.com)
- * Date: August, 1998
- *
-\*--------------------------------------------------------------------------*/
-
-
-#ifndef _HASHTABLE_H
-#define _HASHTABLE_H
-
-/* These structs should not be accessed directly from user code.
- * All access should be via the public functions declared below. */
-
-typedef struct KeyValuePair_struct {
- const void *key;
- void *value;
- struct KeyValuePair_struct *next;
-} KeyValuePair;
-
-typedef struct {
- long numOfBuckets;
- long numOfElements;
- KeyValuePair **bucketArray;
- float idealRatio, lowerRehashThreshold, upperRehashThreshold;
- int (*keycmp) (const void *key1, const void *key2);
- int (*valuecmp) (const void *value1, const void *value2);
- unsigned long (*hashFunction) (const void *key);
- void (*keyDeallocator) (void *key);
- void (*valueDeallocator) (void *value);
-} HashTable;
-
-struct _HashTableIterator {
- int bucket;
- KeyValuePair *pair;
-};
-typedef struct _HashTableIterator HashTableIterator;
-
-
-#endif /* _HASHTABLE_H */
View
20 interop.mof
@@ -30,3 +30,23 @@ class DMY_ListenerDestinationCIMXML : CIM_ListenerDestinationCIMXML
class DMY_IndicationHandlerCIMXML : CIM_IndicationHandlerCIMXML
{
};
+
+class DMY_ObjectManager : CIM_ObjectManager
+{
+};
+
+class DMY_ObjectManagerCommunicationMechanism : CIM_ObjectManagerCommunicationMechanism
+{
+};
+
+class DMY_RegisteredSubProfile : CIM_RegisteredSubProfile
+{
+};
+
+class DMY_Namespace : CIM_Namespace
+{
+};
+
+class DMY_SubProfileRequiresProfile : CIM_SubProfileRequiresProfile
+{
+};
View
2  providerDrv.c
@@ -27,6 +27,7 @@
#include <time.h>
#include <sys/stat.h>
+#include "trace.h"
#include "cmpidt.h"
#include "providerMgr.h"
#include "providerRegister.h"
@@ -36,7 +37,6 @@
#include "msgqueue.h"
#include "constClass.h"
#include "native.h"
-#include "trace.h"
#include "queryOperation.h"
#include "selectexp.h"
#include "control.h"
View
46 sfcBroker.c
@@ -12,6 +12,7 @@
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* Author: Adrian Schuur <schuur@de.ibm.com>
+ * Contributions: Sven Schuetz <sven@de.ibm.com>
*
* Description:
*
@@ -46,6 +47,11 @@
#include "config.h"
#endif
+#ifdef HAVE_SLP
+#include "cimslp.h"
+static int startSLP = 1;
+#endif
+
extern void setExFlag(unsigned long f);
extern char *parseTarget(const char *target);
extern UtilStringBuffer *instanceToString(CMPIInstance * ci, char **props);
@@ -362,6 +368,34 @@ static int startDbpd(int argc, char *argv[], int sslMode)
#endif
+#ifdef HAVE_SLP
+
+static int startSLPAgent()
+{
+ int pid;//,sfcPid=currentProc;
+ //sleep(2);
+ pid= fork();
+ if (pid < 0) {
+ perror("slpAgent fork");
+ exit(2);
+ }
+ if (pid == 0) {
+ printf("pid vom slpprozess: %d\n", getpid());
+ //currentProc=getpid();
+ //dbpDaemon(argc, argv, sslMode, sfcPid);
+ //closeSocket(&sfcbSockets,cRcv,"startHttpd");
+ //closeSocket(&resultSockets,cAll,"startHttpd");
+ slpAgent();
+ }
+ else {
+ //addStartedAdapter(pid);
+ return 0;
+ }
+ return 0;
+}
+
+#endif
+
static void usage(int status)
{
if (status != 0)
@@ -496,7 +530,7 @@ int main(int argc, char *argv[])
_SFCB_TRACE_START(1,tmask);
- setupControl(configfile);
+ setupControl(configfile);
// SFCB_DEBUG
#ifndef SFCB_DEBUG
if (tmask)
@@ -509,9 +543,11 @@ int main(int argc, char *argv[])
if (getControlBool("enableHttp", &enableHttp))
enableHttp=1;
+
#if defined USE_SSL
if (getControlBool("enableHttps", &enableHttps))
enableHttps=0;
+
sslMode=enableHttps;
sslOMode=sslMode & !enableHttp;
#else
@@ -583,6 +619,14 @@ int main(int argc, char *argv[])
startDbpd(argc, argv,0);
}
#endif
+
+
+#ifdef HAVE_SLP
+ //Start SLP Agent
+ if (startSLP) {
+ startSLPAgent();
+ }
+#endif
setSignal(SIGSEGV, handleSigSegv,SA_ONESHOT);
setSignal(SIGCHLD, handleSigChld,0);
View
44 utilFactory.c
@@ -1,44 +0,0 @@
-
-/*
- * utilFactory.c
- *
- * (C) Copyright IBM Corp. 2005
- *
- * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
- * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
- * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
- *
- * You can obtain a current copy of the Eclipse Public License from
- * http://www.opensource.org/licenses/eclipse-1.0.php
- *
- * Author: Adrian Schuur <schuur@de.ibm.com>
- *
- * Description:
- *
- * Encapsulated utility factory implementation.
- *
-*/
-
-
-
-#include "utilft.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-
-extern UtilHashTable *newHashTable(long buckets, long opt);
-extern UtilHashTable *newHashTableDefault(long buckets);
-extern UtilList *newList();
-extern UtilStringBuffer *newStringBuffer(int s);
-
-static Util_Factory_FT ift = {
- 1,
- newHashTableDefault,
- newHashTable,
- newList,
- newStringBuffer
-};
-
-
-Util_Factory_FT *UtilFactory = &ift;
View
184 utilHashtable.c
@@ -1,184 +0,0 @@
-
-/*
- * utilHashtable.c
- *
- * (C) Copyright IBM Corp. 2005
- *
- * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
- * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
- * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
- *
- * You can obtain a current copy of the Eclipse Public License from
- * http://www.opensource.org/licenses/eclipse-1.0.php
- *
- * Author: Adrian Schuur <schuur@de.ibm.com>
- *
- * Description:
- *
- * Hashtable factory support.
- *
-*/
-
-
-#include "utilft.h"
-#include <stdio.h>
-#include <