File 0320-bnc457366A-2140807-static_instances.patch of Package sblim-sfcb
Index: Makefile.am
===================================================================
RCS file: /cvsroot/sblim/sfcb/Makefile.am,v
retrieving revision 1.81
diff -u -r1.81 Makefile.am
--- Makefile.am 7 Nov 2008 23:20:58 -0000 1.81
+++ Makefile.am 17 Dec 2008 00:08:33 -0000
@@ -170,7 +170,7 @@
sfcbd
bin_PROGRAMS = \
- sfcbmofpp sfcbdump $(SLP_PROGRAMFILES)
+ sfcbmofpp sfcbdump sfcbinst2mof $(SLP_PROGRAMFILES)
noinst_PROGRAMS = \
sfcbdumpP32onI32 classSchema2c
@@ -367,6 +367,9 @@
sfcbdump_SOURCES=sfcbdump.c
+sfcbinst2mof_SOURCES=sfcbinst2mof.c
+sfcbinst2mof_LDADD = -lsfcFileRepository
+
classSchema2c_SOURCES=classSchema2c.c
classSchema2c_LDADD=-lsfcBrokerCore
classSchema2c_DEPENDENCIES=libsfcBrokerCore.la
Index: fileRepository.c
===================================================================
RCS file: /cvsroot/sblim/sfcb/fileRepository.c,v
retrieving revision 1.16
diff -u -r1.16 fileRepository.c
--- fileRepository.c 25 Jun 2008 17:53:45 -0000 1.16
+++ fileRepository.c 17 Dec 2008 00:08:33 -0000
@@ -42,9 +42,16 @@
#include "control.h"
+char *repfn=NULL;
+
#define BASE "repository"
-char *repfn=NULL;
+void useAlternateRepository(const char *inAltRepos)
+{
+ int keyl=strlen(inAltRepos)+1;
+ repfn=(char*)malloc(keyl);
+ strncpy(repfn,inAltRepos,keyl);
+}
static char *getRepDir()
{
Index: fileRepository.h
===================================================================
RCS file: /cvsroot/sblim/sfcb/fileRepository.h,v
retrieving revision 1.6
diff -u -r1.6 fileRepository.h
--- fileRepository.h 9 Apr 2008 18:43:14 -0000 1.6
+++ fileRepository.h 17 Dec 2008 00:08:33 -0000
@@ -24,7 +24,7 @@
#ifndef _FILEREPOSITORY_
#define _FILEREPOSITORY_
-#define BASE "repository"
+//#define BASE "repository"
typedef struct blobIndex {
int freed;
@@ -49,4 +49,11 @@
extern void* getFirst(BlobIndex *bi, int *len, char** keyb, size_t *keybl);
extern void* getNext(BlobIndex *bi, int *len, char** keyb, size_t *keybl);
+/*
+NOTE: useAlternateRepository must be called prior to
+ calling any other functions from fileRepository.h
+*/
+// override 'repository' option from sfcb.cfg... full path to repository dir
+extern void useAlternateRepository(const char *inAltRepos);
+
#endif
Index: objectImpl.c
===================================================================
RCS file: /cvsroot/sblim/sfcb/objectImpl.c,v
retrieving revision 1.47
diff -u -r1.47 objectImpl.c
--- objectImpl.c 3 Nov 2008 20:52:52 -0000 1.47
+++ objectImpl.c 17 Dec 2008 00:08:33 -0000
@@ -611,6 +611,10 @@
case CMPI_chars:
case CMPI_string:
return "string";
+ case CMPI_real64:
+ return "real64";
+ case CMPI_real32:
+ return "real32";
case CMPI_sint64:
return "sint64";
case CMPI_uint64:
@@ -629,26 +633,79 @@
return "sint8";
case CMPI_boolean:
return "boolean";
+ case CMPI_char16:
+ return "char16";
case CMPI_ref:
- return "reference";
+ return "ref";
+ case CMPI_instance:
+ return "instance";
case CMPI_dateTime:
return "dateTime";
+ default:
+ return "unknownType";
}
- return "*??*";
}
static char *dataValueToString(ClObjectHdr * hdr, CMPIData * d)
{
static char *True = "true", *False = "false";
+ char retval[1024] = {0};
switch (d->type) {
- case CMPI_chars:
- return (char *) ClObjectGetClString(hdr, (ClString *) & d->value.chars);
- case CMPI_sint32:
- return "sint32";
- case CMPI_boolean:
- return d->value.boolean ? True : False;
+ case CMPI_chars:
+ {
+ char *ret = (char *) ClObjectGetClString(hdr, (ClString *) & d->value.chars);
+ if (ret)
+ strcpy(retval, ret);
+ else
+ return "\"\"";
+ }
+ break;
+ case CMPI_char16:
+ {
+ char *ret = (char *) ClObjectGetClString(hdr, (ClString *) & d->value.char16);
+ if (ret)
+ strcpy(retval, ret);
+ else
+ return "\"\"";
+ }
+ break;
+ case CMPI_real64:
+ sprintf(retval, "%lf", d->value.real64);
+ break;
+ case CMPI_real32:
+ sprintf(retval, "%f", d->value.real32);
+ break;
+ case CMPI_sint64:
+ sprintf(retval, "%lld", d->value.sint64);
+ break;
+ case CMPI_sint32:
+ sprintf(retval, "%d", d->value.sint32);
+ break;
+ case CMPI_sint16:
+ sprintf(retval, "%d", d->value.sint16);
+ break;
+ case CMPI_sint8:
+ sprintf(retval, "%d", d->value.sint8);
+ break;
+ case CMPI_uint64:
+ sprintf(retval, "%llu", d->value.uint64);
+ break;
+ case CMPI_uint32:
+ sprintf(retval, "%u", d->value.uint32);
+ break;
+ case CMPI_uint16:
+ sprintf(retval, "%u", d->value.uint16);
+ break;
+ case CMPI_uint8:
+ sprintf(retval, "%u", d->value.uint8);
+ break;
+ case CMPI_boolean:
+ strcpy(retval, d->value.boolean ? True : False);
+ break;
+ default:
+ strcpy(retval, "***??***");
}
- return "*??*";
+ return retval;
}
@@ -1149,6 +1206,9 @@
ClQualifier *q;
char *array = NULL;
+ if (p->data.state && CMPI_nullValue)
+ return NULL;
+
q = (ClQualifier *) ClObjectGetClSection(hdr, &p->qualifiers);
if ((l = p->qualifiers.used)) {
for (i = 0; i < l; sb = 0, i++) {
@@ -1159,13 +1219,20 @@
cat2string(sc, "\n");
}
+
cat2string(sc, " ");
cat2string(sc, datatypeToString(&p->data, &array));
cat2string(sc, " ");
cat2string(sc, ClObjectGetClString(hdr, &p->id));
if (array) cat2string(sc, array);
cat2string(sc, " = ");
- cat2string(sc, dataValueToString(hdr,&p->data));
+
+ char *val = dataValueToString(hdr,&p->data);
+ if (val == NULL || *val == 0)
+ cat2string(sc, "\"\"");
+ else
+ cat2string(sc, val);
+
cat2string(sc, ";\n");
return sc->str + o;
}
@@ -1770,6 +1837,14 @@
return newInstanceH(ns, cn);
}
+ClInstance *ClInstanceNewFromMof(const char *ns, const char *cn)
+{
+ ClInstance *inst = newInstanceH(ns, cn);
+ if (inst)
+ inst->hdr.flags |= HDR_FromMof;
+ return inst;
+}
+
static long sizeInstanceH(ClObjectHdr * hdr, ClInstance * inst)
{
long sz = sizeof(*inst);
@@ -1855,7 +1930,7 @@
p = (ClProperty *) ClObjectGetClSection(&inst->hdr, &inst->properties);
for (i = 0, l = inst->properties.used; i < l; i++) {
- addPropertyToString(&sc, &inst->hdr, p + i);
+ addPropertyToString(&sc, &inst->hdr, (p+i));
}
cat2string(&sc, "};\n");
Index: objectImpl.h
===================================================================
RCS file: /cvsroot/sblim/sfcb/objectImpl.h,v
retrieving revision 1.25
diff -u -r1.25 objectImpl.h
--- objectImpl.h 15 Oct 2008 21:43:00 -0000 1.25
+++ objectImpl.h 17 Dec 2008 00:08:33 -0000
@@ -143,6 +143,7 @@
#define HDR_ContainsEmbeddedObject 4
#define HDR_StrBufferMalloced 16
#define HDR_ArrayBufferMalloced 32
+ #define HDR_FromMof 64
#endif
unsigned short type;
#ifndef SETCLPFX
@@ -456,6 +457,7 @@
extern int ClClassGetMethParamQualifierAt(ClClass * cls, ClParameter *parm, int id, CMPIData *d, char **name);
extern int isInstance(const CMPIInstance *ci);
extern ClInstance *ClInstanceNew(const char *ns, const char *cn);
+extern ClInstance *ClInstanceNewFromMof(const char *ns, const char *cn);
extern unsigned long ClSizeInstance(ClInstance *inst);
extern ClInstance *ClInstanceRebuild(ClInstance *inst, void *area);
extern void ClInstanceRelocateInstance(ClInstance *inst);
Index: sfcbrepos.sh.in
===================================================================
RCS file: /cvsroot/sblim/sfcb/sfcbrepos.sh.in,v
retrieving revision 1.15
diff -u -r1.15 sfcbrepos.sh.in
--- sfcbrepos.sh.in 29 Mar 2007 10:59:50 -0000 1.15
+++ sfcbrepos.sh.in 17 Dec 2008 00:08:33 -0000
@@ -5,7 +5,7 @@
echo "usage: $0 [-h] [-f] [-c cimschemadir] [-s stagingdir] [-r registrationdir] " 1>&2
}
-args=`getopt fhs:r:c:X: $*`
+args=`getopt fhsi:r:c:X: $*`
rc=$?
if [ $rc = 127 ]
@@ -27,6 +27,8 @@
shift;;
-f) force=1
shift;;
+ -i) ignore_instances=1
+ shift;;
-X) xformat="-b $2"
shift 2;;
-s) stagingdir=$2
@@ -46,6 +48,7 @@
usage
echo -e "\t-h display help message"
echo -e "\t-f force repository creation"
+ echo -e "\t-i do not migrate instances from previous repository (default=do migrate)"
echo -e "\t-X create repository in non-native format as specifed by argument"
echo -e "\t-s specify staging directory [@localstatedir@/lib/sfcb/stage]"
echo -e "\t-r specify repository directory [@localstatedir@/lib/sfcb/registration]"
@@ -138,6 +141,7 @@
fi
# Compile all staged namespace directories
+ instmigfile=/tmp/sfcbinst.mof
mofsubdirs=`find $stagingdir/mofs/* -type d -print 2> /dev/null`
if ls $stagingdir/mofs/*.mof > /dev/null 2>&1
then
@@ -152,11 +156,37 @@
namespace=`echo $mofdir | sed s?$stagingdir/mofs/??`
repositorydir=$registrationdir/repository/
[ -d $repositorydir ] || mkdir -p $repositorydir
- if ! sfcbmof -d $repositorydir -n $namespace -o classSchemas -I $cimschemadir -i CIM_Schema.mof $xformat $mofdir/*.mof $globalmofs
+
+ #grab all non-mof static instances, output to /tmp/sfcbinst.mof
+ if [ -z "$ignore_instances" ]
+ then
+ rm -f $instmigfile 2> /dev/null
+ #get class names (from filenames), ignoring specific files, from repos.previous, as it's already been moved
+ if [ -e $registrationdir/repository.previous/$namespace/ ]
+ then
+ static_inst_files=`ls $registrationdir/repository.previous/$namespace/ -I classSchemas -I qualifiers -I *.idx` > /dev/null 2>&1
+ for instfile in $static_inst_files
+ do
+ sfcbinst2mof -n $namespace -c $instfile -o $instmigfile -r $registrationdir/repository.previous/ -g ${DESTDIR}@sysconfdir@/sfcb/sfcb.cfg 2> /dev/null
+ done
+ fi
+ fi
+ if [ -e $instmigfile ]
+ then
+ instmigopt="-m $instmigfile"
+ else
+ instmigopt=""
+ fi
+ if ! sfcbmof -d $repositorydir -n $namespace -o classSchemas -I $cimschemadir -i CIM_Schema.mof $xformat $instmigopt $mofdir/*.mof $globalmofs
then
- echo Failed compiling the MOF files. >&2
- exit 1
+ rm -f $instmigfile 2> /dev/null
+ echo Failed compiling the MOF files. >&2
+ exit 1
fi
+ if [ -e $instmigfile ]
+ then
+ rm -f $instmigfile 2> /dev/null
+ fi
fi
done
--- ../sfcb/sfcbinst2mof.c 1969-12-31 17:00:00.000000000 -0700
+++ sfcbinst2mof.c 2008-12-16 09:08:22.000000000 -0700
@@ -0,0 +1,542 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "cmpidt.h"
+#include "cmpimacs.h"
+#include "fileRepository.h"
+#include "instance.h"
+#include "objectImpl.h"
+#include "control.h"
+#include "array.h"
+
+#define VERSION "0.8.0"
+
+static int opt_verbose = 0;
+static int opt_version = 0;
+static int opt_help = 0;
+static int opt_from_mof = 0;
+static int opt_only_from_mof = 0;
+static int opt_truncate = 0;
+static char outfilepath[3000] = {0};
+static char sfcbcfg[1024] = SFCB_CONFDIR"/sfcb.cfg";
+static char namespace[600] = {0};
+static char classname[600] = {0};
+static char altRepositoryDir[1024] = {0};
+static char * valid_options = "n:c:g:o:r:tphvVmM";
+#define dbg(x) if(opt_verbose) {x;}
+
+
+extern char *sfcb_pathToChars(CMPIObjectPath * cop, CMPIStatus * rc, char *str);
+extern CMPIObjectPath *getObjectPath(char *path, char **msg);
+extern CMPIData __ift_getPropertyAt(const CMPIInstance * ci, CMPICount i, CMPIString ** name,
+ CMPIStatus * rc);
+
+static char *datatypeToString(CMPIData * d, int *isarray)
+{
+ if (isarray != NULL)
+ *isarray = (d->type & CMPI_ARRAY);
+
+ CMPIType type = d->type & ~CMPI_ARRAY;
+
+ switch (type) {
+ case CMPI_chars:
+ case CMPI_string:
+ return "string";
+ case CMPI_real64:
+ return "real64";
+ case CMPI_real32:
+ return "real32";
+ case CMPI_sint64:
+ return "sint64";
+ case CMPI_uint64:
+ return "uint64";
+ case CMPI_sint32:
+ return "sint32";
+ case CMPI_uint32:
+ return "uint32";
+ case CMPI_sint16:
+ return "sint16";
+ case CMPI_uint16:
+ return "uint16";
+ case CMPI_uint8:
+ return "uint8";
+ case CMPI_sint8:
+ return "sint8";
+ case CMPI_boolean:
+ return "boolean";
+ case CMPI_char16:
+ return "char16";
+ case CMPI_ref:
+ return "ref";
+ case CMPI_dateTime:
+ return "dateTime";
+ default:
+ dbg(printf("unknown type: %04x : %d\n", type, type));
+ return "unknownType";
+ }
+}
+
+char *escapeQuotes(char *in)
+{
+ int i, l, o;
+ char *out;
+
+ if (in == NULL)
+ return (NULL);
+ l = strlen(in);
+ out = (char *) malloc((l * 2) + 1); // worst case scenario - it's all quotes
+
+ for (i = 0, o = 0; i < l; i++) {
+ if (in[i] == '\"') {
+ out[o++]='\\';
+ out[o++]='\"';
+ }
+ else {
+ out[o++] = in[i];
+ }
+ }
+ out[o] = '\0';
+ return out;
+}
+
+UtilStringBuffer * dataValueToString(CMPIData d, CMPIInstance *inst)
+{
+ UtilStringBuffer *sb = UtilFactory->newStrinBuffer(64);
+ char str[256] = {0};// for string, we'll redirect the sp pointer,
+ // all other types should fit in this char-array
+ char *sp = str;
+ int needsQuotes = 0;
+ int needsFree = 0;
+
+ if (d.type & CMPI_ARRAY)
+ {
+ sb->ft->appendChars(sb, "{");
+ struct native_array * na = (struct native_array *)d.value.array;
+
+ int i = 0;
+ for (i=0; i<na->size; i++)
+ {
+ if (i!=0)
+ sb->ft->appendChars(sb,",");
+ CMPIData dd;
+ dd.type = d.type & ~CMPI_ARRAY;
+ dd.state= na->data[i].state;
+ dd.value = na->data[i].value;
+ UtilStringBuffer *b = dataValueToString(dd, inst);
+ sb->ft->appendChars(sb, b->ft->getCharPtr(b));
+ }
+ sb->ft->appendChars(sb, "}");
+ return sb;
+ }
+
+ if((d.type & (CMPI_UINT|CMPI_SINT)) == CMPI_UINT) {
+ unsigned long long ul = 0LL;
+ switch (d.type) {
+ case CMPI_uint8:
+ ul = d.value.uint8;
+ break;
+ case CMPI_uint16:
+ ul = d.value.uint16;
+ break;
+ case CMPI_uint32:
+ ul = d.value.uint32;
+ break;
+ case CMPI_uint64:
+ ul = d.value.uint64;
+ break;
+ }
+ sprintf(str, "%llu", ul);
+ }
+ else if((d.type & (CMPI_UINT|CMPI_SINT)) == CMPI_SINT) {
+ long long sl = 0LL;
+ switch (d.type) {
+ case CMPI_sint8:
+ sl = d.value.sint8;
+ break;
+ case CMPI_sint16:
+ sl = d.value.sint16;
+ break;
+ case CMPI_sint32:
+ sl = d.value.sint32;
+ break;
+ case CMPI_sint64:
+ sl = d.value.sint64;
+ break;
+ }
+ sprintf(str, "%lld", sl);
+ }
+ else if (d.type & CMPI_REAL) {
+ switch (d.type) {
+ case CMPI_real32:
+ sprintf(str, "%.7e", d.value.real32);
+ break;
+ case CMPI_real64:
+ sprintf(str, "%.16e", d.value.real64);
+ break;
+ }
+ }
+ else if (d.type == CMPI_boolean) {
+ sprintf(str, "%s", d.value.boolean ? "TRUE" : "FALSE");
+ }
+ else if (d.type == CMPI_char16) {
+ sprintf(str, "%c", d.value.char16);
+ }
+ else if (d.type == CMPI_chars) {
+ needsQuotes = 1;
+ sp = (char *) d.value.string->hdl;
+ }
+ else if (d.type == CMPI_string) {
+ needsQuotes = 1;
+ sp = (char *) d.value.string->hdl;
+ }
+ else if (d.type == CMPI_dateTime) {
+ if (!(d.state & CMPI_nullValue)) {
+ needsQuotes = 1;
+ dateTime2chars(d.value.dateTime, NULL, str);
+ }
+ }
+ else if (d.type == CMPI_ref) {
+ needsQuotes = 1;
+ sfcb_pathToChars(d.value.ref, NULL, str);
+ }
+ else if (d.type == CMPI_instance) {
+ needsQuotes = 1;
+ sp = (char *) d.value.string->hdl;
+ }
+ else {
+ sp = "Unknown type";
+ }
+
+ if (needsQuotes)
+ {
+ //also needs escaping
+ sp=escapeQuotes(sp);
+ needsFree = 1;
+ }
+ if (needsQuotes)
+ sb->ft->appendChars(sb, "\"");
+ sb->ft->appendChars(sb, sp);
+ if (needsQuotes)
+ sb->ft->appendChars(sb, "\"");
+ if (needsFree)
+ free(sp);
+ return sb;
+}
+
+
+UtilStringBuffer *instanceToMofWithType(CMPIInstance * ci, int withType)
+{
+ unsigned int i, m;
+ CMPIString *name;
+ CMPIStatus rc = {0, NULL};
+ UtilStringBuffer *sb = UtilFactory->newStrinBuffer(64);
+ ClInstance *cli = (ClInstance *)ci->hdl;
+ if (!cli)
+ return NULL;
+
+ SFCB_APPENDCHARS_BLOCK(sb, "Instance of ");
+ sb->ft->appendChars(sb, instGetClassName(ci));
+ SFCB_APPENDCHARS_BLOCK(sb, "\n{\n");
+ for (i = 0, m = ClInstanceGetPropertyCount(cli); i < m; i++)
+ {
+ CMPIData d = __ift_getPropertyAt(ci, i, &name, &rc);
+ if (rc.rc == CMPI_RC_OK)
+ {
+ if (!(d.state & CMPI_nullValue))
+ {
+ SFCB_APPENDCHARS_BLOCK(sb, " ");
+ if (withType)
+ {
+ int isarray = 0;
+ sb->ft->appendChars(sb, datatypeToString(&d, &isarray));
+ if (isarray)
+ SFCB_APPENDCHARS_BLOCK(sb, "[]");
+ SFCB_APPENDCHARS_BLOCK(sb, " ");
+ }
+ sb->ft->appendChars(sb, name->hdl);
+ SFCB_APPENDCHARS_BLOCK(sb, " = ");
+ UtilStringBuffer *buff = dataValueToString(d, ci);
+ sb->ft->appendChars(sb, buff->ft->getCharPtr(buff));
+ SFCB_APPENDCHARS_BLOCK(sb, ";\n");
+ }
+ }
+ }
+
+ SFCB_APPENDCHARS_BLOCK(sb, "};\n");
+ return sb;
+}
+
+
+UtilStringBuffer *instanceToMof(CMPIInstance * ci)
+{
+ return instanceToMofWithType(ci, 0);
+}
+
+
+static CMPIInstance *instifyBlob(void * blob) {
+ CMPIInstance *inst;
+ int id;
+
+ if (blob==NULL) {
+ return NULL;
+ }
+ else {
+ inst=relocateSerializedInstance(blob);
+ memAdd(blob, &id);
+ return inst;
+ }
+}
+
+
+static BlobIndex *_getIndex(const char *ns, const char *cn)
+{
+ BlobIndex *bi;
+ if (getIndex(ns,cn,strlen(ns)+strlen(cn)+64,0,&bi))
+ return bi;
+ else return NULL;
+}
+
+
+static CMPIInstance* ipGetFirst(BlobIndex *bi, int *len, char** keyb, size_t *keybl) {
+ void *blob=getFirst(bi, len, keyb, keybl);
+ return instifyBlob(blob);
+}
+
+static CMPIInstance* ipGetNext(BlobIndex *bi, int *len, char** keyb, size_t *keybl) {
+ void *blob=getNext(bi, len, keyb, keybl);
+ return instifyBlob(blob);
+}
+
+
+
+static int parse_options(int argc, char * argv[])
+{
+ int opt;
+ while ((opt=getopt(argc,argv,valid_options)) != -1)
+ {
+ switch (opt)
+ {
+ case 'n': // namespace, required
+ strncpy(namespace,optarg,sizeof(namespace));
+ break;
+ case 'c': // classname, required
+ strncpy(classname,optarg,sizeof(classname));
+ break;
+ case 'g': // sfcb configuration - default = SFCB_CONFIR = (/usr/local)/etc/sfcb/sfcb.cfg
+ // this configuration specifies the repository directory
+ strncpy(sfcbcfg,optarg,sizeof(sfcbcfg));
+ break;
+ case 'o':
+ strncpy(outfilepath,optarg,sizeof(outfilepath));
+ break;
+ case 'r':
+ strncpy(altRepositoryDir,optarg,sizeof(altRepositoryDir));
+ break;
+ case 't': // default is append, not truncate
+ opt_truncate = 1;
+ break;
+ case 'm':
+ opt_from_mof = 1;
+ break;
+ case 'M':
+ opt_only_from_mof = 1;
+ break;
+ case 'v':
+ opt_verbose = 1;
+ break;
+ case 'V':
+ opt_version = 1;
+ break;
+ case 'h':
+ opt_help = 1;
+ break;
+ default:
+ return -1;
+ }
+ }
+ return optind;
+}
+
+
+static void version(char *name)
+{
+ printf("%s - Version %s - Dump static instances to mof\n", name, VERSION);
+}
+
+static void usage(char *name)
+{
+ printf("%s <options> [-n namespace] [-c classname]\n", name);
+}
+
+static void help(char *name)
+{
+ usage(name);
+ version(name);
+ printf(" Allowed options are\n");
+ printf(" -h display this message\n");
+ printf(" -v verbose: print some extra processing information to stdout\n");
+ printf(" -V print version information\n");
+ printf(" -n <namespace> [REQUIRED]\n");
+ printf(" -c <classname> [REQUIRED] - actual class name instrumented - not a parent class\n");
+ printf(" -g <sfcb cfg file> (default=%s/sfcb.cfg)\n", SFCB_CONFDIR);
+ printf(" -o <output file> full path to output file. Path must exist, with write rights. (default = stdout)\n");
+ printf(" -t truncate output file before writing to it (default = append)\n");
+ printf(" -m output instances that were created in MOF, in addition to instances created interactively\n");
+ printf(" -M output ONLY instances that were created in MOF (don't include instances created interactively)\n");
+ printf(" -r <repository dir> use alternate repository (override sfcb cfg file). (default = %s/registration/repository)\n", SFCB_STATEDIR);
+}
+
+
+int main(int argc, char *argv[])
+{
+ int argidx;
+ if ((argidx=parse_options(argc,argv)) == -1)
+ {
+ help(argv[0]);
+ return 1;
+ }
+ if (opt_version)
+ {
+ version(argv[0]);
+ return 0;
+ }
+ if (opt_help)
+ {
+ help(argv[0]);
+ return 0;
+ }
+ if (opt_verbose)
+ {
+ version(argv[0]);
+ printf("Parsing %s for instances, output to %s\n", classname, *outfilepath?outfilepath:"stdout");
+ if (opt_only_from_mof)
+ {
+ printf(" Dumping only instances created in MOF\n");
+ }
+ else if (opt_from_mof)
+ {
+ printf(" Dump includes instances created from MOF\n");
+ }
+ else
+ {
+ printf(" Dumping only instances not created from MOF\n");
+ }
+ }
+
+ if ( *classname==0 || *namespace==0)
+ {
+ printf("--> You must provide a namespace and a classname\n");
+ help(argv[0]);
+ return 0;
+ }
+
+
+ // now let's get to work
+ char *ns = namespace;
+ char *clsname = classname;
+ char *cfg = sfcbcfg;
+
+ char *msg = NULL;
+ char *kp = NULL;
+ size_t ekl = 0;
+ CMPIObjectPath *cop = NULL;
+ CMPIInstance *inst = NULL;
+ char copKey[8192]={0};
+ BlobIndex *bi = NULL;
+
+ setupControl(cfg);
+ if (*altRepositoryDir)
+ {
+ // must have trailing '/'... if not there, add it
+ int len = strlen(altRepositoryDir);
+ if (altRepositoryDir[len-1] != '/')
+ strcat(altRepositoryDir, "/");
+ useAlternateRepository(altRepositoryDir);
+ dbg(printf("> Using alternate repository dir: %s\n", altRepositoryDir));
+ }
+
+ dbg(printf("> NS: %s\n", ns));
+ dbg(printf("> CN: %s\n", clsname));
+
+ if ((bi=_getIndex(ns,clsname))!=NULL)
+ {
+ inst = ipGetFirst(bi,NULL,&kp,&ekl);
+ if (inst)
+ {
+ FILE *fp = NULL;
+ if (*outfilepath)
+ {
+ if (opt_truncate)
+ fp = fopen(outfilepath, "w");
+ else
+ fp = fopen(outfilepath, "a");
+ }
+
+ while(1)
+ {
+ dbg(printf("> got instance\n"));
+
+ strcpy(copKey,ns);
+ strcat(copKey,":");
+ strcat(copKey,clsname);
+ strcat(copKey,".");
+ strncat(copKey,kp,ekl);
+
+ cop=(CMPIObjectPath *)getObjectPath(copKey,&msg);
+ if (msg)
+ dbg(printf(" ! got error msg getting cop: %s\n", msg));
+ if (cop)
+ {
+ int fromMof = 0;
+ dbg(printf("> > got cop: %s\n", sfcb_pathToChars(cop, NULL, NULL)));
+ ClInstance *cli = (ClInstance *) (inst->hdl);
+ dbg(showClHdr((void *)&cli));
+ if (cli->hdr.flags & HDR_FromMof)
+ {
+ fromMof = 1;
+ dbg(printf("> > Instance is from Mof\n"));
+ }
+ else
+ {
+ fromMof = 0;
+ dbg(printf("> > Instance is Not from Mof\n"));
+ }
+
+ if ((!fromMof && (!opt_only_from_mof)) ||
+ (fromMof && (opt_from_mof || opt_only_from_mof)))
+ {
+ dbg(printf("> > Including instance in output.\n"));
+ UtilStringBuffer *sb = instanceToMof(inst);
+
+ char *str=(char *)sb->ft->getCharPtr(sb);
+ if (fp)
+ {
+ fputs((const char *)str, fp);
+ fputs("\n\n", fp);
+ }
+ else
+ {
+ printf((const char *) str);
+ printf("\n\n");
+ }
+ }
+ }
+ else
+ {
+ return -1;
+ }
+ if ((bi->next < bi->dSize) && (inst=ipGetNext(bi,NULL,&kp,&ekl)))
+ {
+ continue;
+ }
+ break;
+ }
+ if (fp)
+ fclose(fp);
+ }
+ }
+ freeBlobIndex(&bi,1);
+
+ return 0;
+}