IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4121


Ignore:
Timestamp:
Jun 6, 2005, 11:21:05 AM (21 years ago)
Author:
jhoblitt
Message:

misc cleanups
some code additions

Location:
trunk/Nebulous/nebclient/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/nebclient/src/nebclient.c

    r3045 r4121  
    44 * Copyright (C) 2005  Joshua Hoblitt
    55 *
    6  * $Id: nebclient.c,v 1.2 2005-01-18 23:36:40 jhoblitt Exp $
     6 * $Id: nebclient.c,v 1.3 2005-06-06 21:21:05 jhoblitt Exp $
    77 */
    88
     
    2222#define ERRBUF_SIZE 255
    2323
     24static off_t idataCopyFile(char *source, char *dest);
     25static off_t idataCopyFilehandle(int sourceFH, int destFH);
     26
    2427void idataServerInit(idataServer *server)
    2528{
     
    5659    if (soap_call_ns1__create_USCOREobject(server, NULL, NULL, key, class, volume, comment, &response) == SOAP_OK) {
    5760        *URI = xmalloc(strlen(response.result));
    58         strcpy(*URI,response.result);
     61        strcpy(*URI, response.result);
    5962
    6063        if (!idataParseURI(*URI, &filename)) {
     
    8285    struct ns1__replicate_USCOREobjectResponse response;
    8386    char            *filename;
    84     int             file;
     87    int             sourceFH, destFH;
    8588
    8689    if (soap_call_ns1__replicate_USCOREobject(server, NULL, NULL, key, volume, &response) == SOAP_OK) {
    8790        *URI = xmalloc(strlen(response.result));
    88         strcpy(*URI,response.result);
     91        strcpy(*URI, response.result);
    8992
    9093        if (!idataParseURI(*URI, &filename)) {
     
    9497        }
    9598
    96         //idataOpen(key, "read");
    97         //idataCopyFilehandle(
    98 
     99        sourceFH = idataOpen(server, key, IDATA_READ);
     100        if (sourceFH == -1) {
     101            fprintf(stderr, "can not open key %s\n", key );
     102
     103            return -1;
     104        }
     105
     106        destFH = open(filename, O_RDWR|O_TRUNC, 0660);
     107        if (destFH == -1) {
     108            fprintf(stderr, "can not open %s: %s\n", filename, strerror(errno));
     109
     110            return -1;
     111        }
     112
     113        idataCopyFilehandle(sourceFH, destFH);
     114
     115        if (close(sourceFH) == -1) {
     116            fprintf(stderr, "can not close file: %s", strerror(errno));
     117
     118            return -1;
     119        }
     120
     121        if (close(destFH) == -1) {
     122            fprintf(stderr, "can not close %s: %s", filename, strerror(errno));
     123
     124            return -1;
     125        }
    99126    }
    100127
     
    121148}
    122149
    123 int idataFindInstances(idataServer *server, char *key, char *volume )
    124 {
    125 
    126     return 0;
     150int idataFindInstances(idataServer *server, char *key, char *volume, char ***locations)
     151{
     152    struct ns1__find_USCOREinstancesResponse response;
     153    int             resultElements = 0;
     154    int             i;
     155    char            **resultArray;
     156    char            **loc;
     157
     158    // FIXME is this leaking memory when response goes out of scope?
     159    if (soap_call_ns1__find_USCOREinstances(server, NULL, NULL, key, volume, &response) == SOAP_OK) {
     160
     161        resultElements = response.result->__size;
     162        resultArray    = response.result->__ptr;
     163
     164        loc = xmalloc(sizeof(char*) * resultElements);
     165
     166        for (i = 0; i < resultElements; i++) {
     167            loc[i] = xmalloc(strlen(resultArray[i]) + 1);
     168
     169            strcpy(loc[i], resultArray[i]);
     170        }
     171
     172        *locations = loc;
     173
     174        return resultElements;
     175    }
     176
     177    // server error
     178    return -1;
    127179}
    128180
  • trunk/Nebulous/nebclient/src/nebclient.h

    r3048 r4121  
    44 * Copyright (C) 2005  Joshua Hoblitt
    55 *
    6  * $Id: nebclient.h,v 1.4 2005-01-19 00:18:08 jhoblitt Exp $
     6 * $Id: nebclient.h,v 1.5 2005-06-06 21:21:05 jhoblitt Exp $
    77 */
    88
     
    3131int idataUnlock(idataServer *server, char *key, rw flag);
    3232
    33 int idataFindInstances(idataServer *server, char *key, char *volume);
     33int idataFindInstances(idataServer *server, char *key, char *volume, char ***locations);
    3434
    3535int idataFind(idataServer *server, char *key);
     
    5353void idataFree(void *ptr);
    5454
    55 static off_t idataCopyFile(char *source, char *dest);
    56 
    57 static off_t idataCopyFilehandle(int sourceFH, int destFH);
    58 
    5955#endif // IDATACLIENT_H
Note: See TracChangeset for help on using the changeset viewer.