European Bob's Hula Hoopla!

Sun, 02 Oct 2005

MDBTool fixed up :D

Thanks to the help of fatpelt, my problems in the previous post (and a post I made a while ago) are now fixed. The segfault was caused by incorrect argument order, which I should have noticed. The bug getting the right result back was caused by passing an object reference where I should have passed NULL - with a reference, MDB was trying to create a relative name or something. Whatever it was trying to do, it was failing.

So, I've updated the mdbtool source. The manual page is current unwritten, but would look something like:


mdbtool [command] [options]

  getattrs [object] [attribute name]
  
    Example: mdbtool getattrs \\Tree\\Context\\Server netmail:messagingserver
    
    Dumps the value of the attribute for a given object. Double-slashes are
    used to name the object for shell reasons. The result is of the format:
    
    [attribute name]::[value]
    
    This format may change, given values could contain carriage returns.
    
  setattr [object] [attribute name] [new value]
  
    Example: mdbtool setattr \\Tree\\Context\\test Sname newname
    
    Sets the value of an attribute of the object. Attribute names are prefixed
    with 'S' (for attributes that contain strings) or 'D' (for attributes that
    contain the names of objects).
    
  addobject [object] [class] [attr1=value1 attr2=value2 ...]
  
    Example: mdbtool addobject \\Tree\\Context\\test User Sname=foo
    
    Creates a new object of any given type, and initialises some of the 
    attributes. Attribute naming requires 'S'/'D' prefixes (see setattr), 
    you can have as many initial attributes as you like.
    
  setpassword [object]
  
    Example: mdbtool setpassword \\Tree\\Context\\Admin hula
    
    Set the password for any given object; usually used for User objects. The
    example given above resets the password of the admin user.

I have plans for a fair few other commands - we're missing object (re)move, and tree/object introspection in particular - but it seems at least some commands will require work to MDB and the various drivers in order to actually work. Some schema stuff will also be needed at some point. The main thing I next want to achieve is dumping and re-creating complete trees, because I think that's one thing users will really like.

MDBReadEx() segfaults :(

And I can't figure out why, so hopefully lazyweb will help me. So, I have this code:


#include <stdio.h>
#include <stdlib.h>
#include "mdbtool.h"  /* this just pulls in mdb.h */

void leave(char *excuse) { printf("ERROR: %s", excuse); exit(1); }

int main (int argc, char *argv[]) {
	const unsigned char *attrval;
	const unsigned char *object = "\\Tree\\Context\\Server";
	const unsigned char *attr = "netmail:messagingserver";
	
	if (!MemoryManagerOpen("mdbtool"))
		leave("Could not start memory manager\n");
	
	if (!MDBInit()) leave("Could not initialise MDB\n");
	
	MDBHandle *h = MDBAuthenticate("Hula", NULL, NULL);
	if (h == NULL) leave("Could not authenticate to MDB\n");

	MDBValueStruct *vs = MDBCreateValueStruct(h, object);
	MDBEnumStruct *es = MDBCreateEnumStruct(vs);
	
	while ((attrval = MDBReadEx(object, attr, vs, es)) != NULL) {
		printf ("Attribute: %s\n", attrval);
	}
	
	MDBDestroyEnumStruct(es, vs);
	MDBDestroyValueStruct(vs);
	return 0;
}

I run it, and it segfaults:


(gdb) r
Starting program: /home/alex/mdbtool/simple
[Thread debugging using libthread_db enabled]
[New Thread -1210911040 (LWP 28415)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1210911040 (LWP 28415)]
0xb7fccfb9 in MDBReadEx () from /usr/lib/libhulamdb.so.0
(gdb) bt
#0  0xb7fccfb9 in MDBReadEx () from /usr/lib/libhulamdb.so.0
#1  0x080487dc in main (argc=1, argv=0xbf9f48b4) at simple.c:23

According to the API docs, I don't think I'm doing anything particularly wrong. Also, I can't make it work with MDBRead() either - doing something like:


	long l = MDBRead(object, attr, vs);
	
	for (i=0; i<l; i++) {
		printf ("Attr: %s\n", vs->Value[i]);
	}

... returns values, but cut off in bizarre places. Am I doing something remarkably silly, or is there some voodoo dance I need to do?. Frustrating :(