Index: /trunk/Nebulous/nebclient/idataclient.c
===================================================================
--- /trunk/Nebulous/nebclient/idataclient.c	(revision 2953)
+++ /trunk/Nebulous/nebclient/idataclient.c	(revision 2954)
@@ -4,5 +4,5 @@
  * Copyright (C) 2005  Joshua Hoblitt
  *
- * $Id: idataclient.c,v 1.3 2005-01-10 22:11:12 jhoblitt Exp $
+ * $Id: idataclient.c,v 1.4 2005-01-11 04:36:40 jhoblitt Exp $
  */
 
@@ -80,6 +80,25 @@
 int idataReplicate(idataServer *server, char *key, char *volume, char **URI )
 {
-
-    return 0;
+    struct ns1__replicate_USCOREobjectResponse response;
+    char            *filename;
+    int             file;
+
+    if (soap_call_ns1__replicate_USCOREobject(server, NULL, NULL, key, volume, &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;
+        }
+
+        //idataOpen(key, "read");
+        //idataCopyFilehandle(
+
+    }
+
+    // server error
+    return -1;
 }
 
@@ -164,4 +183,5 @@
     int             status;
     int             matchStart, matchEnd;
+    int             matchLength;
 
     status = regcomp(&myregex, pattern, REG_EXTENDED);
@@ -185,4 +205,5 @@
     matchStart = (int)mymatch[1].rm_so;
     matchEnd   = (int)mymatch[1].rm_eo;
+    matchLength = matchEnd - matchStart;
 
     if (matchStart == -1) {
@@ -190,5 +211,7 @@
     }
 
-    sprintf(*filename, "%.*s", matchEnd - matchStart, URI + matchStart);
+    *filename = xmalloc(matchLength + 1);
+
+    sprintf(*filename, "%.*s", matchLength, URI + matchStart);
 
     return strlen(*filename);
@@ -198,2 +221,92 @@
     xfree(ptr);
 }
+
+int idataCopyFile(char *source, char *dest)
+{
+    int             sourceFH;
+    int             destFH; 
+    size_t          bytesCopied;
+
+    sourceFH = open(source, O_RDONLY);
+    if (sourceFH == -1) {
+        fprintf(stderr, "can not open %s: %s\n", source, strerror(errno));
+
+        return -1;
+    }
+
+    destFH = open(dest, O_WRONLY|O_CREAT|O_CREAT, 0600);
+    if (destFH == -1) {
+        fprintf(stderr, "can not open %s: %s\n", dest, strerror(errno));
+
+        return -1;
+    }
+
+    bytesCopied = idataCopyFilehandle(sourceFH, destFH);
+    if (bytesCopied < 0) {
+        return -1;
+    }
+
+    if (close(sourceFH) == -1) {
+        fprintf(stderr, "can not close %s: %s", source, strerror(errno));
+
+        return -1;
+    }
+
+    if (close(destFH) == -1) {
+        fprintf(stderr, "can not close %s: %s", dest, strerror(errno));
+
+        return -1;
+    }
+
+    return bytesCopied;
+}
+
+int idataCopyFilehandle(int sourceFH, int destFH)
+{
+    size_t          bytesTotal;
+    size_t          bytesRemaining;
+    size_t          writeSize;
+    char            writeBuf[1024 * 1024];
+    struct stat     sourceStat;
+
+    if( !fstat(sourceFH, &sourceStat)) {
+        fprintf(stderr, "can not stat filehandles: %s\n", strerror(errno));
+
+        return -1;
+    }
+
+    // the size of the file to copied
+    bytesTotal = sourceStat.st_size;
+
+    /*
+     * If the file size is <= the buffer size call write(2) with the
+     * file size.  If the file size is > the buffer call write with the
+     * buffer size and loop until file size <= buffer size is true.
+    */
+
+    bytesRemaining = bytesTotal;
+
+    while (bytesRemaining) {
+        if (bytesRemaining <= sizeof(writeBuf)) {
+            writeSize = bytesRemaining;
+        } else {
+            writeSize = sizeof(writeBuf);
+        }
+
+        if (read(sourceFH, writeBuf, writeSize) != writeSize) {
+            fprintf(stderr, "can not read filehandle: %s", strerror(errno));
+
+            return -1;
+        }
+
+        if (write(destFH, writeBuf, writeSize) != writeSize) {
+            fprintf(stderr, "can not write filehandles: %s", strerror(errno));
+
+            return -1;
+        }
+
+        bytesRemaining -= writeSize;
+    }
+
+    return bytesTotal;
+}
Index: /trunk/Nebulous/nebclient/idataclient.h
===================================================================
--- /trunk/Nebulous/nebclient/idataclient.h	(revision 2953)
+++ /trunk/Nebulous/nebclient/idataclient.h	(revision 2954)
@@ -4,5 +4,5 @@
  * Copyright (C) 2005  Joshua Hoblitt
  *
- * $Id: idataclient.h,v 1.2 2005-01-08 00:57:59 jhoblitt Exp $
+ * $Id: idataclient.h,v 1.3 2005-01-11 04:36:40 jhoblitt Exp $
  */
 
@@ -49,2 +49,6 @@
 
 void idataFree(void *ptr);
+
+int idataCopyFile(char *source, char *dest);
+
+int idataCopyFilehandle(int sourceFH, int destFH);
