Index: trunk/Nebulous/nebclient/src/nebclient.c
===================================================================
--- trunk/Nebulous/nebclient/src/nebclient.c	(revision 3045)
+++ trunk/Nebulous/nebclient/src/nebclient.c	(revision 4121)
@@ -4,5 +4,5 @@
  * Copyright (C) 2005  Joshua Hoblitt
  *
- * $Id: nebclient.c,v 1.2 2005-01-18 23:36:40 jhoblitt Exp $
+ * $Id: nebclient.c,v 1.3 2005-06-06 21:21:05 jhoblitt Exp $
  */
 
@@ -22,4 +22,7 @@
 #define ERRBUF_SIZE 255
 
+static off_t idataCopyFile(char *source, char *dest);
+static off_t idataCopyFilehandle(int sourceFH, int destFH);
+
 void idataServerInit(idataServer *server)
 {
@@ -56,5 +59,5 @@
     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);
+        strcpy(*URI, response.result);
 
         if (!idataParseURI(*URI, &filename)) {
@@ -82,9 +85,9 @@
     struct ns1__replicate_USCOREobjectResponse response;
     char            *filename;
-    int             file;
+    int             sourceFH, destFH;
 
     if (soap_call_ns1__replicate_USCOREobject(server, NULL, NULL, key, volume, &response) == SOAP_OK) {
         *URI = xmalloc(strlen(response.result));
-        strcpy(*URI,response.result);
+        strcpy(*URI, response.result);
 
         if (!idataParseURI(*URI, &filename)) {
@@ -94,7 +97,31 @@
         }
 
-        //idataOpen(key, "read");
-        //idataCopyFilehandle(
-
+        sourceFH = idataOpen(server, key, IDATA_READ);
+        if (sourceFH == -1) {
+            fprintf(stderr, "can not open key %s\n", key );
+
+            return -1;
+        }
+
+        destFH = open(filename, O_RDWR|O_TRUNC, 0660);
+        if (destFH == -1) {
+            fprintf(stderr, "can not open %s: %s\n", filename, strerror(errno));
+
+            return -1;
+        }
+
+        idataCopyFilehandle(sourceFH, destFH);
+
+        if (close(sourceFH) == -1) {
+            fprintf(stderr, "can not close file: %s", strerror(errno));
+
+            return -1;
+        }
+
+        if (close(destFH) == -1) {
+            fprintf(stderr, "can not close %s: %s", filename, strerror(errno));
+
+            return -1;
+        }
     }
 
@@ -121,8 +148,33 @@
 }
 
-int idataFindInstances(idataServer *server, char *key, char *volume )
-{
-
-    return 0;
+int idataFindInstances(idataServer *server, char *key, char *volume, char ***locations)
+{
+    struct ns1__find_USCOREinstancesResponse response;
+    int             resultElements = 0;
+    int             i;
+    char            **resultArray;
+    char            **loc;
+
+    // FIXME is this leaking memory when response goes out of scope?
+    if (soap_call_ns1__find_USCOREinstances(server, NULL, NULL, key, volume, &response) == SOAP_OK) {
+
+        resultElements = response.result->__size;
+        resultArray    = response.result->__ptr;
+
+        loc = xmalloc(sizeof(char*) * resultElements);
+
+        for (i = 0; i < resultElements; i++) {
+            loc[i] = xmalloc(strlen(resultArray[i]) + 1);
+
+            strcpy(loc[i], resultArray[i]);
+        }
+
+        *locations = loc;
+
+        return resultElements;
+    }
+
+    // server error
+    return -1;
 }
 
