Changeset 2934 for trunk/Nebulous/nebclient
- Timestamp:
- Jan 7, 2005, 2:57:59 PM (22 years ago)
- Location:
- trunk/Nebulous/nebclient
- Files:
-
- 3 edited
-
idataclient.c (modified) (1 diff)
-
idataclient.h (modified) (1 diff)
-
makefile (modified) (1 diff)
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" 1 20 #include "idataclient.h" 2 21 3 char *idCreate( const char *key, const unsigned int class, const char *volume, const char *comment, char *URI ) 22 #define ERRBUF_SIZE 255 23 24 void idataServerInit(idataServer *server) 25 { 26 soap_init(server); 27 } 28 29 char *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 44 void idataServerCleanup(idataServer *server) 45 { 46 soap_end(server); // remove deserialized data and clean up 47 soap_done(server); // detach the gSOAP environment 48 } 49 50 int 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 80 int idataReplicate(idataServer *server, char *key, char *volume, char **URI ) 4 81 { 5 82 83 return 0; 6 84 } 7 85 8 int id Replicate( const char *key, const char *volume, char *URI)86 int idataCull( idataServer *server,char *key ) 9 87 { 10 88 89 return 0; 11 90 } 12 91 13 int id Cull( const char *key)92 int idataLock(idataServer *server, char *key, rw flag ) 14 93 { 15 94 95 return 0; 16 96 } 17 97 18 int id Lock( constchar *key, rw flag )98 int idataUnlock(idataServer *server, char *key, rw flag ) 19 99 { 20 100 101 return 0; 21 102 } 22 103 23 int id Unlock( const char *key, rw flag)104 int idataFindInstances(idataServer *server, char *key, char *volume ) 24 105 { 25 106 107 return 0; 26 108 } 27 109 28 int id FindInstances( const char *key, const char *volume)110 int idataFind(idataServer *server, char *key ) 29 111 { 30 112 113 return 0; 31 114 } 32 115 33 int id Find( const char *key)116 int idataOpen(idataServer *server, char *key, rw flag ) 34 117 { 35 118 119 return 0; 36 120 } 37 121 38 int id Open( const char *key, rw flag)122 int idataDelete(idataServer *server, char *key ) 39 123 { 40 124 125 return 0; 41 126 } 42 127 43 int id Delete( const char *key )128 int idataCopy(idataServer *server, char *key, char *newKey ) 44 129 { 45 130 131 return 0; 46 132 } 47 133 48 int id Copy( const char *key, constchar *newKey )134 int idataMove(idataServer *server, char *key, char *newKey ) 49 135 { 50 136 137 return 0; 51 138 } 52 139 53 int id Move( const char *key, const char *newKey)140 int idataDelete_instance(idataServer *server, char *URI ) 54 141 { 55 142 143 return 0; 56 144 } 57 145 58 int id Delete_instance( const char *URI)146 int idataStat(idataServer *server, char *key ) 59 147 { 60 148 149 return 0; 61 150 } 62 151 63 int id Stat( const char *key)152 int idataErr(idataServer *server, char *errString ) 64 153 { 65 154 155 return 0; 66 156 } 67 157 68 int id Err( char *errString)158 int idataParseURI(const char *URI, char **filename) 69 159 { 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; 70 166 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); 71 195 } 196 197 void idataFree(void *ptr) { 198 xfree(ptr); 199 } -
trunk/Nebulous/nebclient/idataclient.h
r2923 r2934 1 /* 2 * idataclient - idata client 3 * 4 * Copyright (C) 2005 Joshua Hoblitt 5 * 6 * $Id: idataclient.h,v 1.2 2005-01-08 00:57:59 jhoblitt Exp $ 7 */ 8 9 #include "soapH.h" 10 1 11 typedef enum { ID_READ, ID_WRITE } rw; 12 typedef struct soap idataServer; 2 13 3 char *idCreate( const char *key, const unsigned int class, const char *volume, const char *comment, char *URI ); 4 int idReplicate( const char *key, const char *volume, char *URI ); 5 int idCull( const char *key ); 6 int idLock( const char *key, rw flag ); 7 int idUnlock( const char *key, rw flag ); 8 int idFindInstances( const char *key, const char *volume ); 9 int idFind( const char *key ); 10 int idOpen( const char *key, rw flag ); 11 int idDelete( const char *key ); 12 int idCopy( const char *key, const char *newKey ); 13 int idMove( const char *key, const char *newKey ); 14 int idDelete_instance( const char *URI ); 15 int idStat( const char *key ); 16 int idErr( char *errString ); 14 void idataServerInit(idataServer *server); 15 16 char *idataServerErr(idataServer *server); 17 18 void idataServerCleanup(idataServer *server); 19 20 int idataCreate(idataServer *server, char *key, unsigned int class, char *volume, char *comment, char **URI); 21 22 int idataReplicate(idataServer *server, char *key, char *volume, char **URI); 23 24 int idataCull(idataServer *server, char *key); 25 26 int idataLock(idataServer *server, char *key, rw flag); 27 28 int idataUnlock(idataServer *server, char *key, rw flag); 29 30 int idataFindInstances(idataServer *server, char *key, char *volume); 31 32 int idataFind(idataServer *server, char *key); 33 34 int idataOpen(idataServer *server, char *key, rw flag); 35 36 int idataDelete(idataServer *server, char *key); 37 38 int idataCopy(idataServer *server, char *key, char *newKey); 39 40 int idataMove(idataServer *server, char *key, char *newKey); 41 42 int idataDelete_instance(idataServer *server, char *URI); 43 44 int idataStat(idataServer *server, char *key); 45 46 int idataErr(idataServer *server, char *errString); 47 48 int idataParseURI(const char *URI, char **filename); 49 50 void idataFree(void *ptr); -
trunk/Nebulous/nebclient/makefile
r2926 r2934 1 1 SH=/bin/sh 2 2 CFLAGS=-fPIC -Wall -O2 -pipe 3 LIBS=-lpcre 3 4 4 objects=idataclient.o stdsoap2.o soapC.o soapClient.o 5 objects=idataclient.o stdsoap2.o soapC.o soapClient.o xmalloc.o 5 6 6 all: idataclient.so7 all: libidataclient.so 7 8 8 idataclient.so: $(objects)9 $(CC) $(CFLAGS) -shared -o idataclient.so $(objects)9 libidataclient.so: $(objects) 10 $(CC) $(CFLAGS) -shared -o libidataclient.so $(objects) 10 11 11 12 $(objects): %.o : %.c
Note:
See TracChangeset
for help on using the changeset viewer.
