Index: /trunk/Nebulous/nebclient/idataclient.c
===================================================================
--- /trunk/Nebulous/nebclient/idataclient.c	(revision 2933)
+++ /trunk/Nebulous/nebclient/idataclient.c	(revision 2934)
@@ -1,71 +1,199 @@
+/*
+ * idataclient.c - idata client
+ *
+ * Copyright (C) 2005  Joshua Hoblitt
+ *
+ * $Id: idataclient.c,v 1.2 2005-01-08 00:57:59 jhoblitt Exp $
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <regex.h>
+#include "xmalloc.h"
+#include "soapH.h"
+#include "SOAP.nsmap"
 #include "idataclient.h"
 
-char *idCreate( const char *key, const unsigned int class, const char *volume, const char *comment, char *URI )
+#define ERRBUF_SIZE 255
+
+void idataServerInit(idataServer *server)
+{
+    soap_init(server);
+}
+
+char *idataServerErr(idataServer *server)
+{
+    char            *fault;
+    const char      **code;
+    const char      **string;
+
+    code   = soap_faultcode(server);
+    string = soap_faultstring(server);
+
+    fault = xmalloc(strlen(*code) + 3 + strlen(*string) + 1);
+    sprintf(fault, "%s - %s", *code, *string);
+
+    return fault;
+}
+
+void idataServerCleanup(idataServer *server)
+{
+    soap_end(server); // remove deserialized data and clean up
+    soap_done(server); // detach the gSOAP environment
+}
+
+int idataCreate(idataServer *server, char *key, unsigned int class, char *volume, char *comment, char **URI)
+{
+    struct ns1__create_USCOREobjectResponse response;
+    char            *filename;
+    int             file;
+
+    if (soap_call_ns1__create_USCOREobject(server, NULL, NULL, key, class, volume, comment, &response) == SOAP_OK) {
+        *URI = xmalloc(strlen(response.result));
+        strcpy(*URI,response.result);
+
+        if (!idataParseURI(*URI, &filename)) {
+            fprintf(stderr, "can not parse URI\n");
+
+            return 0;
+        }
+
+        file = open(filename, O_RDWR|O_CREAT|O_EXCL, 0660);
+        if (file == -1) {
+            fprintf(stderr, "can not open %s: %s\n", filename, strerror(errno));
+
+            return 0;
+        }
+
+        return file;
+    }
+
+    // server error
+    return -1;
+}
+
+int idataReplicate(idataServer *server, char *key, char *volume, char **URI )
 {
 
+    return 0;
 }
 
-int idReplicate( const char *key, const char *volume, char *URI )
+int idataCull( idataServer *server,char *key )
 {
 
+    return 0;
 }
 
-int idCull( const char *key )
+int idataLock(idataServer *server, char *key, rw flag )
 {
 
+    return 0;
 }
 
-int idLock( const char *key, rw flag )
+int idataUnlock(idataServer *server, char *key, rw flag )
 {
 
+    return 0;
 }
 
-int idUnlock( const char *key, rw flag )
+int idataFindInstances(idataServer *server, char *key, char *volume )
 {
 
+    return 0;
 }
 
-int idFindInstances( const char *key, const char *volume )
+int idataFind(idataServer *server, char *key )
 {
 
+    return 0;
 }
 
-int idFind( const char *key )
+int idataOpen(idataServer *server, char *key, rw flag )
 {
 
+    return 0;
 }
 
-int idOpen( const char *key, rw flag )
+int idataDelete(idataServer *server, char *key )
 {
 
+    return 0;
 }
 
-int idDelete( const char *key )
+int idataCopy(idataServer *server, char *key, char *newKey )
 {
 
+    return 0;
 }
 
-int idCopy( const char *key, const char *newKey )
+int idataMove(idataServer *server, char *key, char *newKey )
 {
 
+    return 0;
 }
 
-int idMove( const char *key, const char *newKey )
+int idataDelete_instance(idataServer *server, char *URI )
 {
 
+    return 0;
 }
 
-int idDelete_instance( const char *URI )
+int idataStat(idataServer *server, char *key )
 {
 
+    return 0;
 }
 
-int idStat( const char *key )
+int idataErr(idataServer *server, char *errString )
 {
 
+    return 0;
 }
 
-int idErr( char *errString )
+int idataParseURI(const char *URI, char **filename)
 {
+    regex_t         myregex;
+    regmatch_t      mymatch[2];
+    char            errbuf[ERRBUF_SIZE];
+    char            *pattern = "^file:(.*)$";
+    int             status;
+    int             matchStart, matchEnd;
 
+    status = regcomp(&myregex, pattern, REG_EXTENDED);
+    if (status != 0) {
+        regerror(status, &myregex, errbuf, ERRBUF_SIZE);
+        fprintf(stderr, "regcomp error: %s\n", errbuf);
+
+        return 0;
+    }
+
+    status = regexec(&myregex, URI, 2, mymatch, 0);
+    if (status != 0) {
+        regerror(status, &myregex, errbuf, ERRBUF_SIZE);
+        fprintf(stderr, "regexec error: %s\n", errbuf);
+
+        return 0;
+    }
+
+    regfree(&myregex);
+
+    matchStart = (int)mymatch[1].rm_so;
+    matchEnd   = (int)mymatch[1].rm_eo;
+
+    if (matchStart == -1) {
+        return 0;
+    }
+
+    sprintf(*filename, "%.*s", matchEnd - matchStart, URI + matchStart);
+
+    return strlen(*filename);
 }
+
+void idataFree(void *ptr) {
+    xfree(ptr);
+}
Index: /trunk/Nebulous/nebclient/idataclient.h
===================================================================
--- /trunk/Nebulous/nebclient/idataclient.h	(revision 2933)
+++ /trunk/Nebulous/nebclient/idataclient.h	(revision 2934)
@@ -1,16 +1,50 @@
+/*
+ * idataclient -  idata client
+ * 
+ * Copyright (C) 2005  Joshua Hoblitt
+ *
+ * $Id: idataclient.h,v 1.2 2005-01-08 00:57:59 jhoblitt Exp $
+ */
+
+#include "soapH.h"
+
 typedef enum { ID_READ, ID_WRITE } rw;
+typedef struct soap idataServer;
 
-char *idCreate( const char *key, const unsigned int class, const char *volume, const char *comment, char *URI );
-int idReplicate( const char *key, const char *volume, char *URI );
-int idCull( const char *key );
-int idLock( const char *key, rw flag );
-int idUnlock( const char *key, rw flag );
-int idFindInstances( const char *key, const char *volume );
-int idFind( const char *key );
-int idOpen( const char *key, rw flag );
-int idDelete( const char *key );
-int idCopy( const char *key, const char *newKey );
-int idMove( const char *key, const char *newKey );
-int idDelete_instance( const char *URI );
-int idStat( const char *key );
-int idErr( char *errString );
+void idataServerInit(idataServer *server);
+
+char *idataServerErr(idataServer *server);
+
+void idataServerCleanup(idataServer *server);
+
+int idataCreate(idataServer *server, char *key, unsigned int class, char *volume, char *comment, char **URI);
+
+int idataReplicate(idataServer *server, char *key, char *volume, char **URI);
+
+int idataCull(idataServer *server, char *key);
+
+int idataLock(idataServer *server, char *key, rw flag);
+
+int idataUnlock(idataServer *server, char *key, rw flag);
+
+int idataFindInstances(idataServer *server, char *key, char *volume);
+
+int idataFind(idataServer *server, char *key);
+
+int idataOpen(idataServer *server, char *key, rw flag);
+
+int idataDelete(idataServer *server, char *key);
+
+int idataCopy(idataServer *server, char *key, char *newKey);
+
+int idataMove(idataServer *server, char *key, char *newKey);
+
+int idataDelete_instance(idataServer *server, char *URI);
+
+int idataStat(idataServer *server, char *key);
+
+int idataErr(idataServer *server, char *errString);
+
+int idataParseURI(const char *URI, char **filename);
+
+void idataFree(void *ptr);
Index: /trunk/Nebulous/nebclient/makefile
===================================================================
--- /trunk/Nebulous/nebclient/makefile	(revision 2933)
+++ /trunk/Nebulous/nebclient/makefile	(revision 2934)
@@ -1,11 +1,12 @@
 SH=/bin/sh
 CFLAGS=-fPIC -Wall -O2 -pipe
+LIBS=-lpcre
 
-objects=idataclient.o stdsoap2.o soapC.o soapClient.o
+objects=idataclient.o stdsoap2.o soapC.o soapClient.o xmalloc.o
 
-all: idataclient.so
+all: libidataclient.so
 
-idataclient.so: $(objects)
-	$(CC) $(CFLAGS) -shared -o idataclient.so $(objects)
+libidataclient.so: $(objects)
+	$(CC) $(CFLAGS) -shared -o libidataclient.so $(objects)
 
 $(objects): %.o : %.c
