IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 7, 2005, 2:57:59 PM (22 years ago)
Author:
jhoblitt
Message:

add idataServer* idataParseURI idataFree functions
idataCreate is now working

File:
1 edited

Legend:

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

    r2923 r2934  
     1/*
     2 * idataclient.c - idata client
     3 *
     4 * Copyright (C) 2005  Joshua Hoblitt
     5 *
     6 * $Id: idataclient.c,v 1.2 2005-01-08 00:57:59 jhoblitt Exp $
     7 */
     8
     9#include <sys/types.h>
     10#include <sys/stat.h>
     11#include <fcntl.h>
     12#include <errno.h>
     13#include <stdlib.h>
     14#include <stdio.h>
     15#include <string.h>
     16#include <regex.h>
     17#include "xmalloc.h"
     18#include "soapH.h"
     19#include "SOAP.nsmap"
    120#include "idataclient.h"
    221
    3 char *idCreate( const char *key, const unsigned int class, const char *volume, const char *comment, char *URI )
     22#define ERRBUF_SIZE 255
     23
     24void idataServerInit(idataServer *server)
     25{
     26    soap_init(server);
     27}
     28
     29char *idataServerErr(idataServer *server)
     30{
     31    char            *fault;
     32    const char      **code;
     33    const char      **string;
     34
     35    code   = soap_faultcode(server);
     36    string = soap_faultstring(server);
     37
     38    fault = xmalloc(strlen(*code) + 3 + strlen(*string) + 1);
     39    sprintf(fault, "%s - %s", *code, *string);
     40
     41    return fault;
     42}
     43
     44void idataServerCleanup(idataServer *server)
     45{
     46    soap_end(server); // remove deserialized data and clean up
     47    soap_done(server); // detach the gSOAP environment
     48}
     49
     50int idataCreate(idataServer *server, char *key, unsigned int class, char *volume, char *comment, char **URI)
     51{
     52    struct ns1__create_USCOREobjectResponse response;
     53    char            *filename;
     54    int             file;
     55
     56    if (soap_call_ns1__create_USCOREobject(server, NULL, NULL, key, class, volume, comment, &response) == SOAP_OK) {
     57        *URI = xmalloc(strlen(response.result));
     58        strcpy(*URI,response.result);
     59
     60        if (!idataParseURI(*URI, &filename)) {
     61            fprintf(stderr, "can not parse URI\n");
     62
     63            return 0;
     64        }
     65
     66        file = open(filename, O_RDWR|O_CREAT|O_EXCL, 0660);
     67        if (file == -1) {
     68            fprintf(stderr, "can not open %s: %s\n", filename, strerror(errno));
     69
     70            return 0;
     71        }
     72
     73        return file;
     74    }
     75
     76    // server error
     77    return -1;
     78}
     79
     80int idataReplicate(idataServer *server, char *key, char *volume, char **URI )
    481{
    582
     83    return 0;
    684}
    785
    8 int idReplicate( const char *key, const char *volume, char *URI )
     86int idataCull( idataServer *server,char *key )
    987{
    1088
     89    return 0;
    1190}
    1291
    13 int idCull( const char *key )
     92int idataLock(idataServer *server, char *key, rw flag )
    1493{
    1594
     95    return 0;
    1696}
    1797
    18 int idLock( const char *key, rw flag )
     98int idataUnlock(idataServer *server, char *key, rw flag )
    1999{
    20100
     101    return 0;
    21102}
    22103
    23 int idUnlock( const char *key, rw flag )
     104int idataFindInstances(idataServer *server, char *key, char *volume )
    24105{
    25106
     107    return 0;
    26108}
    27109
    28 int idFindInstances( const char *key, const char *volume )
     110int idataFind(idataServer *server, char *key )
    29111{
    30112
     113    return 0;
    31114}
    32115
    33 int idFind( const char *key )
     116int idataOpen(idataServer *server, char *key, rw flag )
    34117{
    35118
     119    return 0;
    36120}
    37121
    38 int idOpen( const char *key, rw flag )
     122int idataDelete(idataServer *server, char *key )
    39123{
    40124
     125    return 0;
    41126}
    42127
    43 int idDelete( const char *key )
     128int idataCopy(idataServer *server, char *key, char *newKey )
    44129{
    45130
     131    return 0;
    46132}
    47133
    48 int idCopy( const char *key, const char *newKey )
     134int idataMove(idataServer *server, char *key, char *newKey )
    49135{
    50136
     137    return 0;
    51138}
    52139
    53 int idMove( const char *key, const char *newKey )
     140int idataDelete_instance(idataServer *server, char *URI )
    54141{
    55142
     143    return 0;
    56144}
    57145
    58 int idDelete_instance( const char *URI )
     146int idataStat(idataServer *server, char *key )
    59147{
    60148
     149    return 0;
    61150}
    62151
    63 int idStat( const char *key )
     152int idataErr(idataServer *server, char *errString )
    64153{
    65154
     155    return 0;
    66156}
    67157
    68 int idErr( char *errString )
     158int idataParseURI(const char *URI, char **filename)
    69159{
     160    regex_t         myregex;
     161    regmatch_t      mymatch[2];
     162    char            errbuf[ERRBUF_SIZE];
     163    char            *pattern = "^file:(.*)$";
     164    int             status;
     165    int             matchStart, matchEnd;
    70166
     167    status = regcomp(&myregex, pattern, REG_EXTENDED);
     168    if (status != 0) {
     169        regerror(status, &myregex, errbuf, ERRBUF_SIZE);
     170        fprintf(stderr, "regcomp error: %s\n", errbuf);
     171
     172        return 0;
     173    }
     174
     175    status = regexec(&myregex, URI, 2, mymatch, 0);
     176    if (status != 0) {
     177        regerror(status, &myregex, errbuf, ERRBUF_SIZE);
     178        fprintf(stderr, "regexec error: %s\n", errbuf);
     179
     180        return 0;
     181    }
     182
     183    regfree(&myregex);
     184
     185    matchStart = (int)mymatch[1].rm_so;
     186    matchEnd   = (int)mymatch[1].rm_eo;
     187
     188    if (matchStart == -1) {
     189        return 0;
     190    }
     191
     192    sprintf(*filename, "%.*s", matchEnd - matchStart, URI + matchStart);
     193
     194    return strlen(*filename);
    71195}
     196
     197void idataFree(void *ptr) {
     198    xfree(ptr);
     199}
Note: See TracChangeset for help on using the changeset viewer.