From 537a12bc42f095f75ae22ae5927a5b953ad27ba4 Mon Sep 17 00:00:00 2001 From: Lazlo Westerhof Date: Mon, 11 Mar 2024 12:28:24 +0100 Subject: [PATCH] YDA-5623: format microservices with clang-format --- src/Archive.hh | 293 +++++++++++++++++++----------------- src/CredentialsStore.hh | 73 ++++----- src/msiArchiveCreate.cc | 151 ++++++++----------- src/msiArchiveExtract.cc | 109 ++++++-------- src/msiArchiveIndex.cc | 24 +-- src/msiRegisterEpicPID.cc | 309 +++++++++++++++++++------------------- src/msi_add_avu.cpp | 59 +++----- src/msi_json_arrayops.cc | 220 ++++++++++++++------------- src/msi_json_objops.cc | 227 ++++++++++++++-------------- src/msi_rmw_avu.cpp | 59 +++----- 10 files changed, 743 insertions(+), 781 deletions(-) diff --git a/src/Archive.hh b/src/Archive.hh index d324f63..3b31682 100644 --- a/src/Archive.hh +++ b/src/Archive.hh @@ -15,58 +15,67 @@ #include #include -#define A_BUFSIZE (1024 * 1024) -#define A_BLOCKSIZE ((size_t) 8192) +#define A_BUFSIZE (1024 * 1024) +#define A_BLOCKSIZE ((size_t) 8192) /* * libarchive for iRODS */ -class Archive { - class Data { - public: - Data(rsComm_t *rsComm, const char *name) : - rsComm(rsComm), - name(name) { +class Archive +{ + class Data + { + public: + Data(rsComm_t* rsComm, const char* name) + : rsComm(rsComm) + , name(name) + { resource = NULL; index = 0; } - rsComm_t *rsComm; /* iRODS context */ - const char *name; /* name of file to open */ - const char *resource; /* resource to create the file on */ - int index; /* file index */ - dataObjInp_t create; /* cached create input */ - dataObjInp_t open; /* cached open input */ - char buf[A_BUFSIZE]; /* buffer for reading */ + rsComm_t* rsComm; /* iRODS context */ + const char* name; /* name of file to open */ + const char* resource; /* resource to create the file on */ + int index; /* file index */ + dataObjInp_t create; /* cached create input */ + dataObjInp_t open; /* cached open input */ + char buf[A_BUFSIZE]; /* buffer for reading */ }; /* * archive constructor */ - Archive(struct archive *archive, Data *data, bool creating, json_t *list, - size_t dataSize, std::string &path, std::string &collection, - const char *resc, std::string indexString) : - archive(archive), - data(data), - creating(creating), - list(list), - dataSize(dataSize), - path(path), - origin(collection), - indexString(indexString) + Archive(struct archive* archive, + Data* data, + bool creating, + json_t* list, + size_t dataSize, + std::string& path, + std::string& collection, + const char* resc, + std::string indexString) + : archive(archive) + , data(data) + , creating(creating) + , list(list) + , dataSize(dataSize) + , path(path) + , origin(collection) + , indexString(indexString) { data->resource = resc; index = 0; } -public: + public: /* * create archive */ - static Archive *create(rsComm_t *rsComm, std::string path, - std::string collection, const char *resc) { - struct archive *a; - Data *data; + static Archive* create(rsComm_t* rsComm, std::string path, std::string collection, const char* resc) + { + struct archive* a; + Data* data; /* * Create archive, determine format and compression mode based on @@ -78,13 +87,13 @@ public: } if (path.length() >= 4 && !path.compare(path.length() - 4, 4, ".zip")) { archive_write_set_format_zip(a); - } else { + } + else { archive_write_set_format_ustar(a); } data = new Data(rsComm, path.c_str()); data->resource = resc; - if (archive_write_open(a, data, &a_creat, &a_write, &a_close) != - ARCHIVE_OK) { + if (archive_write_open(a, data, &a_creat, &a_write, &a_close) != ARCHIVE_OK) { delete data; archive_write_free(a); return NULL; @@ -93,23 +102,23 @@ public: /* * archive was created, call the constructor */ - return new Archive(a, data, true, json_array(), 0, path, collection, - resc, ""); + return new Archive(a, data, true, json_array(), 0, path, collection, resc, ""); } /* * open existing archive */ - static Archive *open(rsComm_t *rsComm, std::string path, const char *resc) { - struct archive *a; - Data *data; - struct archive_entry *entry; + static Archive* open(rsComm_t* rsComm, std::string path, const char* resc) + { + struct archive* a; + Data* data; + struct archive_entry* entry; size_t size; - char *buf; + char* buf; json_t *json, *list; json_error_t error; std::string origin; - Archive *archive; + Archive* archive; /* * open any archive @@ -121,9 +130,9 @@ public: archive_read_support_filter_all(a); archive_read_support_format_all(a); data = new Data(rsComm, path.c_str()); - if (archive_read_open(a, data, &a_open, &a_read, &a_close) != - ARCHIVE_OK || - archive_read_next_header(a, &entry) != ARCHIVE_OK) { + if (archive_read_open(a, data, &a_open, &a_read, &a_close) != ARCHIVE_OK || + archive_read_next_header(a, &entry) != ARCHIVE_OK) + { delete data; archive_read_free(a); return NULL; @@ -144,8 +153,7 @@ public: size = (size_t) archive_entry_size(entry); buf = new char[size + 1]; buf[size] = '\0'; - if (archive_read_data(a, buf, size) != (__LA_SSIZE_T) size || - (json=json_loads(buf, 0, &error)) == NULL) { + if (archive_read_data(a, buf, size) != (__LA_SSIZE_T) size || (json = json_loads(buf, 0, &error)) == NULL) { delete buf; delete data; archive_read_free(a); @@ -164,8 +172,7 @@ public: /* * safe to call the constructor */ - archive = new Archive(a, data, false, list, size, path, origin, resc, - buf); + archive = new Archive(a, data, false, list, size, path, origin, resc, buf); delete buf; return archive; } @@ -173,11 +180,13 @@ public: /* * destruct archive, cleaning up if needed */ - ~Archive() { + ~Archive() + { if (archive != NULL) { if (creating) { archive_write_free(archive); - } else { + } + else { archive_read_free(archive); } } @@ -190,11 +199,18 @@ public: * Add a DataObj to an archive. It will be added to the index at first, * the actual archive will be created when construct() is called. */ - void addDataObj(std::string name, size_t size, time_t created, - time_t modified, std::string owner, std::string zone, - std::string checksum, json_t *attributes, json_t *acl) { + void addDataObj(std::string name, + size_t size, + time_t created, + time_t modified, + std::string owner, + std::string zone, + std::string checksum, + json_t* attributes, + json_t* acl) + { if (path.compare(origin + "/" + name) != 0) { - json_t *json; + json_t* json; json = json_object(); json_object_set_new(json, "name", json_string(name.c_str())); @@ -202,11 +218,9 @@ public: json_object_set_new(json, "size", json_integer((json_int_t) size)); json_object_set_new(json, "created", json_integer(created)); json_object_set_new(json, "modified", json_integer(modified)); - json_object_set_new(json, "owner", - json_string((owner + "#" + zone).c_str())); + json_object_set_new(json, "owner", json_string((owner + "#" + zone).c_str())); if (checksum.length() != 0) { - json_object_set_new(json, "checksum", - json_string(checksum.c_str())); + json_object_set_new(json, "checksum", json_string(checksum.c_str())); } if (attributes != NULL) { json_object_set(json, "attributes", attributes); @@ -224,18 +238,22 @@ public: * Add a collection to an archive. It will be added to the index at first, * the actual archive will be created when construct() is called. */ - void addColl(std::string name, time_t created, time_t modified, - std::string owner, std::string zone, json_t *attributes, - json_t *acl) { - json_t *json; + void addColl(std::string name, + time_t created, + time_t modified, + std::string owner, + std::string zone, + json_t* attributes, + json_t* acl) + { + json_t* json; json = json_object(); json_object_set_new(json, "name", json_string(name.c_str())); json_object_set_new(json, "type", json_string("coll")); json_object_set_new(json, "created", json_integer(created)); json_object_set_new(json, "modified", json_integer(modified)); - json_object_set_new(json, "owner", - json_string((owner + "#" + zone).c_str())); + json_object_set_new(json, "owner", json_string((owner + "#" + zone).c_str())); if (attributes != NULL) { json_object_set(json, "attributes", attributes); } @@ -248,20 +266,19 @@ public: /* * construct an archive from the index, return status */ - int construct() { + int construct() + { if (creating) { - json_t *json; - char *str; + json_t* json; + char* str; __LA_SSIZE_T len; /* * first entry, INDEX.json */ json = json_object(); - json_object_set_new(json, "collection", - json_string(origin.c_str())); - json_object_set_new(json, "size", - json_integer((json_int_t) dataSize)); + json_object_set_new(json, "collection", json_string(origin.c_str())); + json_object_set_new(json, "size", json_integer((json_int_t) dataSize)); json_object_set(json, "items", list); str = json_dumps(json, JSON_INDENT(2)); json_decref(json); @@ -272,8 +289,7 @@ public: archive_entry_set_filetype(entry, AE_IFREG); archive_entry_set_perm(entry, 0444); archive_entry_set_size(entry, len); - if (archive_write_header(archive, entry) < 0 || - archive_write_data(archive, str, (size_t) len) < 0) { + if (archive_write_header(archive, entry) < 0 || archive_write_data(archive, str, (size_t) len) < 0) { free(str); return SYS_TAR_APPEND_ERR; } @@ -283,7 +299,7 @@ public: * now add the DataObjs and collections */ for (index = 0; index < json_array_size(list); index++) { - const char *filename; + const char* filename; int fd; size_t size; time_t mtime; @@ -294,8 +310,7 @@ public: mtime = json_integer_value(json_object_get(json, "modified")); archive_entry_set_pathname(entry, filename); archive_entry_set_mtime(entry, mtime, 0); - if (strcmp(json_string_value(json_object_get(json, "type")), - "coll") == 0) { + if (strcmp(json_string_value(json_object_get(json, "type")), "coll") == 0) { /* * collection */ @@ -304,14 +319,14 @@ public: if (archive_write_header(archive, entry) < 0) { return SYS_TAR_APPEND_ERR; } - } else { + } + else { /* * DataObj */ archive_entry_set_filetype(entry, AE_IFREG); archive_entry_set_perm(entry, 0600); - size = (size_t) json_integer_value(json_object_get(json, - "size")); + size = (size_t) json_integer_value(json_object_get(json, "size")); archive_entry_set_size(entry, (__LA_INT64_T) size); if (archive_write_header(archive, entry) < 0) { return SYS_TAR_APPEND_ERR; @@ -320,10 +335,8 @@ public: if (fd < 0) { return fd; } - while ((len=_read(data->rsComm, fd, data->buf, - sizeof(data->buf))) > 0) { - if (archive_write_data(archive, data->buf, - (size_t) len) < 0) { + while ((len = _read(data->rsComm, fd, data->buf, sizeof(data->buf))) > 0) { + if (archive_write_data(archive, data->buf, (size_t) len) < 0) { _close(data->rsComm, fd); return SYS_TAR_APPEND_ERR; } @@ -346,24 +359,28 @@ public: /* * return INDEX.json as a string */ - std::string indexItems() { + std::string indexItems() + { return indexString; } /* * return size in blocks of items once extracted */ - size_t size() { + size_t size() + { return dataSize; } /* * get metadata of next item (potentially skipping current) from archive */ - json_t *nextItem() { + json_t* nextItem() + { if (archive_read_next_header(archive, &entry) == ARCHIVE_OK) { return json_array_get(list, index++); - } else { + } + else { return NULL; } } @@ -371,7 +388,8 @@ public: /* * extract current item under the given filename */ - int extractItem(std::string filename) { + int extractItem(std::string filename) + { if (archive_entry_filetype(entry) == AE_IFDIR) { collInp_t collCreateInp; int err; @@ -383,7 +401,8 @@ public: rstrcpy(collCreateInp.collName, filename.c_str(), MAX_NAME_LEN); err = rsCollCreate(data->rsComm, &collCreateInp); return (err == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME) ? 0 : err; - } else { + } + else { char buf[A_BUFSIZE]; int fd, status; __LA_SSIZE_T len; @@ -395,7 +414,7 @@ public: if (fd < 0) { return fd; } - while ((len=archive_read_data(archive, buf, sizeof(buf))) > 0) { + while ((len = archive_read_data(archive, buf, sizeof(buf))) > 0) { status = _write(data->rsComm, fd, buf, (size_t) len); if (status < 0) { _close(data->rsComm, fd); @@ -412,11 +431,12 @@ public: return 0; } -private: + private: /* * create an iRODS DataObj */ - static int _creat(Data *data, const char *name) { + static int _creat(Data* data, const char* name) + { int fd; /* @@ -426,8 +446,7 @@ private: memset(&data->create, '\0', sizeof(dataObjInp_t)); data->create.openFlags = O_WRONLY | O_TRUNC; if (data->resource != NULL) { - addKeyVal(&data->create.condInput, DEST_RESC_NAME_KW, - data->resource); + addKeyVal(&data->create.condInput, DEST_RESC_NAME_KW, data->resource); } addKeyVal(&data->create.condInput, TRANSLATED_PATH_KW, ""); rstrcpy(data->create.objPath, name, MAX_NAME_LEN); @@ -437,8 +456,7 @@ private: memset(&data->create, '\0', sizeof(dataObjInp_t)); data->create.openFlags = O_CREAT | O_WRONLY; if (data->resource != NULL) { - addKeyVal(&data->create.condInput, DEST_RESC_NAME_KW, - data->resource); + addKeyVal(&data->create.condInput, DEST_RESC_NAME_KW, data->resource); } addKeyVal(&data->create.condInput, TRANSLATED_PATH_KW, ""); rstrcpy(data->create.objPath, name, MAX_NAME_LEN); @@ -451,7 +469,8 @@ private: /* * open an iRODS DataObj */ - static int _open(Data *data, const char *name) { + static int _open(Data* data, const char* name) + { memset(&data->open, '\0', sizeof(dataObjInp_t)); data->open.openFlags = O_RDONLY; rstrcpy(data->open.objPath, name, MAX_NAME_LEN); @@ -461,7 +480,8 @@ private: /* * read an iRODS DataObj */ - static int _read(rsComm_t *rsComm, int index, void *buf, size_t len) { + static int _read(rsComm_t* rsComm, int index, void* buf, size_t len) + { openedDataObjInp_t input; bytesBuf_t rbuf; @@ -476,7 +496,7 @@ private: /* * write to an iRODS DataObj */ - static int _write(rsComm_t *rsComm, int index, const void *buf, size_t len) + static int _write(rsComm_t* rsComm, int index, const void* buf, size_t len) { openedDataObjInp_t input; bytesBuf_t wbuf; @@ -484,7 +504,7 @@ private: memset(&input, '\0', sizeof(openedDataObjInp_t)); input.l1descInx = index; input.len = (int) len; - wbuf.buf = (void *) buf; + wbuf.buf = (void*) buf; wbuf.len = (int) len; return rsDataObjWrite(rsComm, &input, &wbuf); } @@ -492,7 +512,8 @@ private: /* * close an iRODS DatObj */ - static int _close(rsComm_t *rsComm, int index) { + static int _close(rsComm_t* rsComm, int index) + { openedDataObjInp_t input; memset(&input, '\0', sizeof(openedDataObjInp_t)); @@ -503,10 +524,11 @@ private: /* * libarchive wrapper for _creat() */ - static int a_creat(struct archive *a, void *data) { - Data *d; + static int a_creat(struct archive* a, void* data) + { + Data* d; - d = (Data *) data; + d = (Data*) data; d->index = _creat(d, d->name); return (d->index >= 0) ? ARCHIVE_OK : ARCHIVE_FATAL; } @@ -514,10 +536,11 @@ private: /* * libarchive wrapper for _open() */ - static int a_open(struct archive *a, void *data) { - Data *d; + static int a_open(struct archive* a, void* data) + { + Data* d; - d = (Data *) data; + d = (Data*) data; d->index = _open(d, d->name); return (d->index >= 0) ? ARCHIVE_OK : ARCHIVE_FATAL; } @@ -525,15 +548,16 @@ private: /* * libarchive wrapper for _read() */ - static __LA_SSIZE_T a_read(struct archive *a, void *data, const void **buf) { - Data *d; + static __LA_SSIZE_T a_read(struct archive* a, void* data, const void** buf) + { + Data* d; __LA_SSIZE_T status; - d = (Data *) data; - if (d->index < 0 || - (status=_read(d->rsComm, d->index, d->buf, sizeof(d->buf))) < 0) { + d = (Data*) data; + if (d->index < 0 || (status = _read(d->rsComm, d->index, d->buf, sizeof(d->buf))) < 0) { return -1; - } else { + } + else { *buf = d->buf; return status; } @@ -542,16 +566,16 @@ private: /* * libarchive wrapper for _write() */ - static __LA_SSIZE_T a_write(struct archive *a, void *data, const void *buf, - size_t size) { - Data *d; + static __LA_SSIZE_T a_write(struct archive* a, void* data, const void* buf, size_t size) + { + Data* d; __LA_SSIZE_T status; - d = (Data *) data; - if (d->index < 0 || - (status=_write(d->rsComm, d->index, buf, size)) < 0) { + d = (Data*) data; + if (d->index < 0 || (status = _write(d->rsComm, d->index, buf, size)) < 0) { return -1; - } else { + } + else { return status; } } @@ -559,21 +583,22 @@ private: /* * libarchive wrapper for _close() */ - static int a_close(struct archive *a, void *data) { - Data *d; + static int a_close(struct archive* a, void* data) + { + Data* d; - d = (Data *) data; + d = (Data*) data; return (d->index < 0 || _close(d->rsComm, d->index) < 0) ? -1 : 0; } - struct archive *archive; /* libarchive reference */ - struct archive_entry *entry; /* archive entry */ - Data *data; /* context data */ - bool creating; /* new archive? */ - json_t *list; /* list of items */ - size_t index; /* index of current item */ - size_t dataSize; /* total size of archived DataObjs */ - std::string path; /* path of archive */ - std::string origin; /* original collection */ - std::string indexString; /* index as a string */ + struct archive* archive; /* libarchive reference */ + struct archive_entry* entry; /* archive entry */ + Data* data; /* context data */ + bool creating; /* new archive? */ + json_t* list; /* list of items */ + size_t index; /* index of current item */ + size_t dataSize; /* total size of archived DataObjs */ + std::string path; /* path of archive */ + std::string origin; /* original collection */ + std::string indexString; /* index as a string */ }; diff --git a/src/CredentialsStore.hh b/src/CredentialsStore.hh index ae3f318..d149ae5 100644 --- a/src/CredentialsStore.hh +++ b/src/CredentialsStore.hh @@ -1,56 +1,61 @@ #include "jansson.h" #include "irods_includes.hh" -# define CREDS_STORE "/var/lib/irods/.credentials_store/store_config.json" - +#define CREDS_STORE "/var/lib/irods/.credentials_store/store_config.json" /* * keep it simple */ -class CredentialsStore { -public: +class CredentialsStore +{ + public: // load stored values - CredentialsStore() { - json_error_t error; - - store = json_load_file(CREDS_STORE, 0, &error); - if (store == NULL) { - rodsLog(LOG_ERROR, "Failed to load credentials store"); - } - // store is returned with refcount 1 + CredentialsStore() + { + json_error_t error; + + store = json_load_file(CREDS_STORE, 0, &error); + if (store == NULL) { + rodsLog(LOG_ERROR, "Failed to load credentials store"); + } + // store is returned with refcount 1 } // free stored values - ~CredentialsStore() { - if (store != NULL) { - json_decref(store); - } + ~CredentialsStore() + { + if (store != NULL) { + json_decref(store); + } } // check that the store is properly initialized - bool isLoaded() { - return (store != NULL); + bool isLoaded() + { + return (store != NULL); } // check that the store has a credential - bool has(const char *key) { - return (store != NULL && json_object_get(store, key) != NULL); + bool has(const char* key) + { + return (store != NULL && json_object_get(store, key) != NULL); } // get a credential from the store - const char *get(const char *key) { - if (store != NULL) { - json_t *value; - - value = json_object_get(store, key); - if (value != NULL && json_is_string(value)) { - return json_string_value(value); - } - } - - rodsLog(LOG_ERROR, "Failed to retrieve credential \"%s\"", key); - return NULL; + const char* get(const char* key) + { + if (store != NULL) { + json_t* value; + + value = json_object_get(store, key); + if (value != NULL && json_is_string(value)) { + return json_string_value(value); + } + } + + rodsLog(LOG_ERROR, "Failed to retrieve credential \"%s\"", key); + return NULL; } -private: - json_t *store; // in-memory copy of credentials store + private: + json_t* store; // in-memory copy of credentials store }; diff --git a/src/msiArchiveCreate.cc b/src/msiArchiveCreate.cc index 5f99813..87a6ca0 100644 --- a/src/msiArchiveCreate.cc +++ b/src/msiArchiveCreate.cc @@ -14,11 +14,11 @@ /* * obtain ID of a collection, or a negative error status */ -static long long collID(rsComm_t *rsComm, std::string &coll) +static long long collID(rsComm_t* rsComm, std::string& coll) { char collQCond[MAX_NAME_LEN]; genQueryInp_t genQueryInp; - genQueryOut_t *genQueryOut; + genQueryOut_t* genQueryOut; long long collId; memset(&genQueryInp, '\0', sizeof(genQueryInp_t)); @@ -33,9 +33,9 @@ static long long collID(rsComm_t *rsComm, std::string &coll) if (collId == 0) { if (genQueryOut->rowCnt != 1) { collId = CAT_UNKNOWN_COLLECTION; - } else { - collId = strtoll(getSqlResultByInx(genQueryOut, COL_COLL_ID)->value, - NULL, 10); + } + else { + collId = strtoll(getSqlResultByInx(genQueryOut, COL_COLL_ID)->value, NULL, 10); } } freeGenQueryOut(&genQueryOut); @@ -46,11 +46,11 @@ static long long collID(rsComm_t *rsComm, std::string &coll) /* * obtain attribute metadata for a DataObj */ -static json_t *attrDataObj(rsComm_t *rsComm, long long id) +static json_t* attrDataObj(rsComm_t* rsComm, long long id) { char dataQCond[MAX_NAME_LEN]; genQueryInp_t genQueryInp; - genQueryOut_t *genQueryOut; + genQueryOut_t* genQueryOut; sqlResult_t *names, *values, *units; json_t *list, *json; @@ -64,20 +64,16 @@ static json_t *attrDataObj(rsComm_t *rsComm, long long id) genQueryOut = NULL; list = NULL; - while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && - genQueryOut->rowCnt != 0) { + while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && genQueryOut->rowCnt != 0) { names = getSqlResultByInx(genQueryOut, COL_META_DATA_ATTR_NAME); values = getSqlResultByInx(genQueryOut, COL_META_DATA_ATTR_VALUE); units = getSqlResultByInx(genQueryOut, COL_META_DATA_ATTR_UNITS); for (int i = 0; i < genQueryOut->rowCnt; i++) { json = json_object(); - json_object_set_new(json, "name", - json_string(&names->value[names->len * i])); - json_object_set_new(json, "value", - json_string(&values->value[values->len * i])); - json_object_set_new(json, "unit", - json_string(&units->value[units->len * i])); + json_object_set_new(json, "name", json_string(&names->value[names->len * i])); + json_object_set_new(json, "value", json_string(&values->value[values->len * i])); + json_object_set_new(json, "unit", json_string(&units->value[units->len * i])); if (list == NULL) { list = json_array(); } @@ -99,11 +95,11 @@ static json_t *attrDataObj(rsComm_t *rsComm, long long id) /* * obtain attribute metadata for a collection */ -static json_t *attrColl(rsComm_t *rsComm, long long id) +static json_t* attrColl(rsComm_t* rsComm, long long id) { char collQCond[MAX_NAME_LEN]; genQueryInp_t genQueryInp; - genQueryOut_t *genQueryOut; + genQueryOut_t* genQueryOut; sqlResult_t *names, *values, *units; json_t *list, *json; @@ -117,20 +113,16 @@ static json_t *attrColl(rsComm_t *rsComm, long long id) genQueryOut = NULL; list = NULL; - while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && - genQueryOut->rowCnt != 0) { + while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && genQueryOut->rowCnt != 0) { names = getSqlResultByInx(genQueryOut, COL_META_COLL_ATTR_NAME); values = getSqlResultByInx(genQueryOut, COL_META_COLL_ATTR_VALUE); units = getSqlResultByInx(genQueryOut, COL_META_COLL_ATTR_UNITS); for (int i = 0; i < genQueryOut->rowCnt; i++) { json = json_object(); - json_object_set_new(json, "name", - json_string(&names->value[names->len * i])); - json_object_set_new(json, "value", - json_string(&values->value[values->len * i])); - json_object_set_new(json, "unit", - json_string(&units->value[units->len * i])); + json_object_set_new(json, "name", json_string(&names->value[names->len * i])); + json_object_set_new(json, "value", json_string(&values->value[values->len * i])); + json_object_set_new(json, "unit", json_string(&units->value[units->len * i])); if (list == NULL) { list = json_array(); } @@ -152,19 +144,18 @@ static json_t *attrColl(rsComm_t *rsComm, long long id) /* * obtain ACLs for a DataObj */ -static json_t *aclDataObj(rsComm_t *rsComm, long long id) +static json_t* aclDataObj(rsComm_t* rsComm, long long id) { char tmpStr[MAX_NAME_LEN]; genQueryInp_t genQueryInp; - genQueryOut_t *genQueryOut; + genQueryOut_t* genQueryOut; sqlResult_t *users, *zones, *access; - json_t *list; + json_t* list; memset(&genQueryInp, '\0', sizeof(genQueryInp_t)); snprintf(tmpStr, MAX_NAME_LEN, "='%lld'", id); addInxVal(&genQueryInp.sqlCondInp, COL_DATA_ACCESS_DATA_ID, tmpStr); - addInxVal(&genQueryInp.sqlCondInp, COL_DATA_TOKEN_NAMESPACE, - "='access_type'"); + addInxVal(&genQueryInp.sqlCondInp, COL_DATA_TOKEN_NAMESPACE, "='access_type'"); addInxIval(&genQueryInp.selectInp, COL_USER_NAME, 1); addInxIval(&genQueryInp.selectInp, COL_USER_ZONE, 1); addInxIval(&genQueryInp.selectInp, COL_DATA_ACCESS_NAME, 1); @@ -172,14 +163,15 @@ static json_t *aclDataObj(rsComm_t *rsComm, long long id) genQueryOut = NULL; list = NULL; - while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && - genQueryOut->rowCnt != 0) { + while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && genQueryOut->rowCnt != 0) { users = getSqlResultByInx(genQueryOut, COL_USER_NAME); zones = getSqlResultByInx(genQueryOut, COL_USER_ZONE); access = getSqlResultByInx(genQueryOut, COL_DATA_ACCESS_NAME); for (int i = 0; i < genQueryOut->rowCnt; i++) { - snprintf(tmpStr, MAX_NAME_LEN, "%s#%s:%s", + snprintf(tmpStr, + MAX_NAME_LEN, + "%s#%s:%s", &users->value[users->len * i], &zones->value[zones->len * i], &access->value[access->len * i]); @@ -204,19 +196,18 @@ static json_t *aclDataObj(rsComm_t *rsComm, long long id) /* * obtain ACLs for a collection */ -static json_t *aclColl(rsComm_t *rsComm, long long id) +static json_t* aclColl(rsComm_t* rsComm, long long id) { char tmpStr[MAX_NAME_LEN]; genQueryInp_t genQueryInp; - genQueryOut_t *genQueryOut; + genQueryOut_t* genQueryOut; sqlResult_t *users, *zones, *access; - json_t *list; + json_t* list; memset(&genQueryInp, '\0', sizeof(genQueryInp_t)); snprintf(tmpStr, MAX_NAME_LEN, "='%lld'", id); addInxVal(&genQueryInp.sqlCondInp, COL_COLL_ACCESS_COLL_ID, tmpStr); - addInxVal(&genQueryInp.sqlCondInp, COL_COLL_TOKEN_NAMESPACE, - "='access_type'"); + addInxVal(&genQueryInp.sqlCondInp, COL_COLL_TOKEN_NAMESPACE, "='access_type'"); addInxIval(&genQueryInp.selectInp, COL_COLL_USER_NAME, 1); addInxIval(&genQueryInp.selectInp, COL_COLL_USER_ZONE, 1); addInxIval(&genQueryInp.selectInp, COL_COLL_ACCESS_NAME, 1); @@ -224,14 +215,15 @@ static json_t *aclColl(rsComm_t *rsComm, long long id) genQueryOut = NULL; list = NULL; - while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && - genQueryOut->rowCnt != 0) { + while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && genQueryOut->rowCnt != 0) { users = getSqlResultByInx(genQueryOut, COL_COLL_USER_NAME); zones = getSqlResultByInx(genQueryOut, COL_COLL_USER_ZONE); access = getSqlResultByInx(genQueryOut, COL_COLL_ACCESS_NAME); for (int i = 0; i < genQueryOut->rowCnt; i++) { - snprintf(tmpStr, MAX_NAME_LEN, "%s#%s:%s", + snprintf(tmpStr, + MAX_NAME_LEN, + "%s#%s:%s", &users->value[users->len * i], &zones->value[zones->len * i], &access->value[access->len * i]); @@ -256,14 +248,12 @@ static json_t *aclColl(rsComm_t *rsComm, long long id) /* * pass on metadata from DataObjs in a given location to the archive */ -static void dirDataObj(Archive *a, rsComm_t *rsComm, std::string coll, - long long collId) +static void dirDataObj(Archive* a, rsComm_t* rsComm, std::string coll, long long collId) { char collQCond[MAX_NAME_LEN]; genQueryInp_t genQueryInp; - genQueryOut_t *genQueryOut; - sqlResult_t *names, *ids, *sizes, *owners, *zones, *ctimes, *mtimes, - *checksums; + genQueryOut_t* genQueryOut; + sqlResult_t *names, *ids, *sizes, *owners, *zones, *ctimes, *mtimes, *checksums; long long dataId; memset(&genQueryInp, '\0', sizeof(genQueryInp_t)); @@ -281,8 +271,7 @@ static void dirDataObj(Archive *a, rsComm_t *rsComm, std::string coll, genQueryInp.maxRows = MAX_SQL_ROWS; genQueryOut = NULL; - while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && - genQueryOut->rowCnt != 0) { + while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && genQueryOut->rowCnt != 0) { names = getSqlResultByInx(genQueryOut, COL_DATA_NAME); ids = getSqlResultByInx(genQueryOut, COL_D_DATA_ID); sizes = getSqlResultByInx(genQueryOut, COL_DATA_SIZE); @@ -295,8 +284,7 @@ static void dirDataObj(Archive *a, rsComm_t *rsComm, std::string coll, for (int i = 0; i < genQueryOut->rowCnt; i++) { dataId = strtoll(&ids->value[ids->len * i], NULL, 10); a->addDataObj(coll + &names->value[names->len * i], - (size_t) strtoll(&sizes->value[sizes->len * i], NULL, - 10), + (size_t) strtoll(&sizes->value[sizes->len * i], NULL, 10), strtoll(&ctimes->value[ctimes->len * i], NULL, 10), strtoll(&mtimes->value[mtimes->len * i], NULL, 10), &owners->value[owners->len * i], @@ -320,16 +308,15 @@ static void dirDataObj(Archive *a, rsComm_t *rsComm, std::string coll, /* * recursively pass on metadata for collections to the archive */ -static void dirColl(Archive *a, rsComm_t *rsComm, std::string &coll, - std::string &path) +static void dirColl(Archive* a, rsComm_t* rsComm, std::string& coll, std::string& path) { char collQCond[MAX_NAME_LEN]; genQueryInp_t genQueryInp; - genQueryOut_t *genQueryOut; + genQueryOut_t* genQueryOut; sqlResult_t *names, *ids, *owners, *zones, *ctimes, *mtimes; long long id; - char *name; - std::list> dirs = { }; + char* name; + std::list> dirs = {}; memset(&genQueryInp, '\0', sizeof(genQueryInp_t)); snprintf(collQCond, MAX_NAME_LEN, "='%s'", path.c_str()); @@ -343,8 +330,7 @@ static void dirColl(Archive *a, rsComm_t *rsComm, std::string &coll, genQueryInp.maxRows = MAX_SQL_ROWS; genQueryOut = NULL; - while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && - genQueryOut->rowCnt != 0) { + while (rsGenQuery(rsComm, &genQueryInp, &genQueryOut) == 0 && genQueryOut->rowCnt != 0) { names = getSqlResultByInx(genQueryOut, COL_COLL_NAME); ids = getSqlResultByInx(genQueryOut, COL_COLL_ID); owners = getSqlResultByInx(genQueryOut, COL_COLL_OWNER_NAME); @@ -385,18 +371,17 @@ static void dirColl(Archive *a, rsComm_t *rsComm, std::string &coll, */ for (auto dir = dirs.begin(); dir != dirs.end(); dir++) { dirColl(a, rsComm, coll, dir->first); - dirDataObj(a, rsComm, dir->first.substr(coll.length() + 1) + "/", - dir->second); + dirDataObj(a, rsComm, dir->first.substr(coll.length() + 1) + "/", dir->second); } } extern "C" { -int msiArchiveCreate(msParam_t *archiveIn, - msParam_t *collectionIn, - msParam_t *resourceIn, - msParam_t *statusOut, - ruleExecInfo_t *rei) +int msiArchiveCreate(msParam_t* archiveIn, + msParam_t* collectionIn, + msParam_t* resourceIn, + msParam_t* statusOut, + ruleExecInfo_t* rei) { long long id; int status; @@ -410,14 +395,14 @@ int msiArchiveCreate(msParam_t *archiveIn, } /* Parse input paramaters. */ - const char *archiveStr = parseMspForStr(archiveIn); - const char *collectionStr = parseMspForStr(collectionIn); + const char* archiveStr = parseMspForStr(archiveIn); + const char* collectionStr = parseMspForStr(collectionIn); if (archiveStr == NULL || collectionStr == NULL) { return SYS_INVALID_INPUT_PARAM; } std::string archive = archiveStr; std::string collection = collectionStr; - const char *resource = NULL; + const char* resource = NULL; if (resourceIn->type != NULL && strcmp(resourceIn->type, STR_MS_T) == 0) { resource = parseMspForStr(resourceIn); } @@ -428,15 +413,16 @@ int msiArchiveCreate(msParam_t *archiveIn, * no such collection */ status = (int) id; - } else { + } + else { /* * create archive */ - Archive *a = Archive::create(rei->rsComm, archive, collection, - resource); + Archive* a = Archive::create(rei->rsComm, archive, collection, resource); if (a == NULL) { status = SYS_TAR_OPEN_ERR; - } else { + } + else { /* * add collections and DataObjs to archive */ @@ -455,23 +441,14 @@ int msiArchiveCreate(msParam_t *archiveIn, return status; } -irods::ms_table_entry *plugin_factory() { - irods::ms_table_entry *msvc = new irods::ms_table_entry(4); - - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msiArchiveCreate", - std::function(msiArchiveCreate)); +irods::ms_table_entry* plugin_factory() +{ + irods::ms_table_entry* msvc = new irods::ms_table_entry(4); + + msvc->add_operation( + "msiArchiveCreate", + std::function(msiArchiveCreate)); return msvc; } - } diff --git a/src/msiArchiveExtract.cc b/src/msiArchiveExtract.cc index 0fb96ca..f37fcc5 100644 --- a/src/msiArchiveExtract.cc +++ b/src/msiArchiveExtract.cc @@ -13,15 +13,14 @@ #include "rsModDataObjMeta.hpp" #include "rsModAVUMetadata.hpp" - /* * obtain free space on resource, if set */ -static long long freeSpace(rsComm_t *rsComm, const char *resource) +static long long freeSpace(rsComm_t* rsComm, const char* resource) { char rescQCond[MAX_NAME_LEN]; genQueryInp_t genQueryInp; - genQueryOut_t *genQueryOut; + genQueryOut_t* genQueryOut; long long space; memset(&genQueryInp, '\0', sizeof(genQueryInp_t)); @@ -36,13 +35,12 @@ static long long freeSpace(rsComm_t *rsComm, const char *resource) if (space == 0) { if (genQueryOut->rowCnt != 1) { space = SYS_RESC_DOES_NOT_EXIST; - } else { + } + else { /* * the resource exists, but the free space might still be unset */ - space = strtoll(getSqlResultByInx(genQueryOut, - COL_R_FREE_SPACE)->value, - NULL, 10); + space = strtoll(getSqlResultByInx(genQueryOut, COL_R_FREE_SPACE)->value, NULL, 10); } } freeGenQueryOut(&genQueryOut); @@ -53,7 +51,7 @@ static long long freeSpace(rsComm_t *rsComm, const char *resource) /* * change the modification time for an extracted DataObj */ -static void modify(rsComm_t *rsComm, std::string &file, json_t *json) +static void modify(rsComm_t* rsComm, std::string& file, json_t* json) { modDataObjMeta_t modDataObj; dataObjInfo_t dataObjInfo; @@ -65,41 +63,35 @@ static void modify(rsComm_t *rsComm, std::string &file, json_t *json) memset(®Param, '\0', sizeof(keyValPair_t)); rstrcpy(dataObjInfo.objPath, file.c_str(), MAX_NAME_LEN); modDataObj.dataObjInfo = &dataObjInfo; - snprintf(tmpStr, MAX_NAME_LEN, "%lld", - json_integer_value(json_object_get(json, "modified"))); + snprintf(tmpStr, MAX_NAME_LEN, "%lld", json_integer_value(json_object_get(json, "modified"))); addKeyVal(®Param, DATA_MODIFY_KW, tmpStr); modDataObj.regParam = ®Param; - rsModDataObjMeta(rsComm, &modDataObj); /* allowed to fail */ + rsModDataObjMeta(rsComm, &modDataObj); /* allowed to fail */ } /* * set the attributes of a collection or DataObj */ -static void attributes(rsComm_t *rsComm, std::string &file, const char *type, - json_t *list) +static void attributes(rsComm_t* rsComm, std::string& file, const char* type, json_t* list) { modAVUMetadataInp_t modAVUInp; size_t sz, i; - const char *name; - json_t *json; + const char* name; + json_t* json; memset(&modAVUInp, '\0', sizeof(modAVUMetadataInp_t)); - modAVUInp.arg1 = (char *) type; - modAVUInp.arg2 = (char *) file.c_str(); + modAVUInp.arg1 = (char*) type; + modAVUInp.arg2 = (char*) file.c_str(); name = NULL; sz = json_array_size(list); for (i = 0; i < sz; i++) { json = json_array_get(list, i); - modAVUInp.arg3 = (char *) - json_string_value(json_object_get(json, "name")); - modAVUInp.arg4 = (char *) - json_string_value(json_object_get(json, "value")); - modAVUInp.arg5 = (char *) - json_string_value(json_object_get(json, "unit")); - modAVUInp.arg0 = (name == NULL || strcmp(modAVUInp.arg3, name) != 0) ? - (char *) "set" : (char *) "add"; + modAVUInp.arg3 = (char*) json_string_value(json_object_get(json, "name")); + modAVUInp.arg4 = (char*) json_string_value(json_object_get(json, "value")); + modAVUInp.arg5 = (char*) json_string_value(json_object_get(json, "unit")); + modAVUInp.arg0 = (name == NULL || strcmp(modAVUInp.arg3, name) != 0) ? (char*) "set" : (char*) "add"; name = modAVUInp.arg3; - rsModAVUMetadata(rsComm, &modAVUInp); /* allowed to fail */ + rsModAVUMetadata(rsComm, &modAVUInp); /* allowed to fail */ } } @@ -110,10 +102,10 @@ int msiArchiveExtract(msParam_t* archiveIn, msParam_t* extractIn, msParam_t* resourceIn, msParam_t* statusOut, - ruleExecInfo_t *rei) + ruleExecInfo_t* rei) { collInp_t collCreateInp; - json_t *json; + json_t* json; int status; long long space; @@ -126,26 +118,27 @@ int msiArchiveExtract(msParam_t* archiveIn, } /* Parse input paramaters. */ - const char *archiveStr = parseMspForStr(archiveIn); - const char *pathStr = parseMspForStr(pathIn); + const char* archiveStr = parseMspForStr(archiveIn); + const char* pathStr = parseMspForStr(pathIn); if (archiveStr == NULL || pathStr == NULL) { return SYS_INVALID_INPUT_PARAM; } std::string archive = archiveStr; std::string path = pathStr; - const char *extract = NULL; + const char* extract = NULL; if (extractIn->type != NULL && strcmp(extractIn->type, STR_MS_T) == 0) { extract = parseMspForStr(extractIn); } - const char *resource = NULL; + const char* resource = NULL; if (resourceIn->type != NULL && strcmp(resourceIn->type, STR_MS_T) == 0) { resource = parseMspForStr(resourceIn); } - Archive *a = Archive::open(rei->rsComm, archive, resource); + Archive* a = Archive::open(rei->rsComm, archive, resource); if (a == NULL) { status = SYS_TAR_OPEN_ERR; - } else { + } + else { status = 0; space = 0; if (resource != NULL) { @@ -155,8 +148,8 @@ int msiArchiveExtract(msParam_t* archiveIn, space = freeSpace(rei->rsComm, resource); if (space < 0) { status = (int) space; - } else if (space != 0 && extract == NULL && - a->size() > (size_t) (space - space / 10)) { + } + else if (space != 0 && extract == NULL && a->size() > (size_t) (space - space / 10)) { /* * the choice of status code is rather a shot in the dark */ @@ -179,17 +172,15 @@ int msiArchiveExtract(msParam_t* archiveIn, /* * extract items */ - while ((json=a->nextItem()) != NULL) { + while ((json = a->nextItem()) != NULL) { std::string file; - const char *type; - json_t *list; + const char* type; + json_t* list; file = json_string_value(json_object_get(json, "name")); if (extract == NULL || file.compare(extract) == 0) { if (extract != NULL) { - if (space != 0 && - json_integer_value(json_object_get(json, "size")) > - space - space / 10) { + if (space != 0 && json_integer_value(json_object_get(json, "size")) > space - space / 10) { /* * single-file space check failed */ @@ -205,11 +196,8 @@ int msiArchiveExtract(msParam_t* archiveIn, * extract in collection */ memset(&collCreateInp, '\0', sizeof(collInp_t)); - rstrcpy(collCreateInp.collName, - (path + "/" + file.substr(0, found)).c_str(), - MAX_NAME_LEN); - addKeyVal(&collCreateInp.condInput, RECURSIVE_OPR__KW, - ""); + rstrcpy(collCreateInp.collName, (path + "/" + file.substr(0, found)).c_str(), MAX_NAME_LEN); + addKeyVal(&collCreateInp.condInput, RECURSIVE_OPR__KW, ""); rsCollCreate(rei->rsComm, &collCreateInp); } } @@ -230,7 +218,8 @@ int msiArchiveExtract(msParam_t* archiveIn, if (list != NULL) { attributes(rei->rsComm, file, "-C", list); } - } else { + } + else { modify(rei->rsComm, file, json); if (list != NULL) { attributes(rei->rsComm, file, "-d", list); @@ -249,25 +238,15 @@ int msiArchiveExtract(msParam_t* archiveIn, return status; } -irods::ms_table_entry *plugin_factory() { - irods::ms_table_entry *msvc = new irods::ms_table_entry(5); +irods::ms_table_entry* plugin_factory() +{ + irods::ms_table_entry* msvc = new irods::ms_table_entry(5); - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msiArchiveExtract", - std::function(msiArchiveExtract)); + msvc->add_operation( + "msiArchiveExtract", + std::function( + msiArchiveExtract)); return msvc; } - } diff --git a/src/msiArchiveIndex.cc b/src/msiArchiveIndex.cc index e62f8f2..3120955 100644 --- a/src/msiArchiveIndex.cc +++ b/src/msiArchiveIndex.cc @@ -11,9 +11,7 @@ extern "C" { -int msiArchiveIndex(msParam_t *archiveIn, - msParam_t *indexOut, - ruleExecInfo_t *rei) +int msiArchiveIndex(msParam_t* archiveIn, msParam_t* indexOut, ruleExecInfo_t* rei) { /* Check input parameters. */ if (archiveIn->type == NULL || strcmp(archiveIn->type, STR_MS_T)) { @@ -21,13 +19,13 @@ int msiArchiveIndex(msParam_t *archiveIn, } /* Parse input paramaters. */ - const char *archiveStr = parseMspForStr(archiveIn); + const char* archiveStr = parseMspForStr(archiveIn); if (archiveStr == NULL) { return SYS_INVALID_INPUT_PARAM; } std::string archive = archiveStr; - Archive *a = Archive::open(rei->rsComm, archive, NULL); + Archive* a = Archive::open(rei->rsComm, archive, NULL); if (a == NULL) { return SYS_TAR_OPEN_ERR; } @@ -37,19 +35,13 @@ int msiArchiveIndex(msParam_t *archiveIn, return 0; } -irods::ms_table_entry *plugin_factory() { - irods::ms_table_entry *msvc = new irods::ms_table_entry(2); +irods::ms_table_entry* plugin_factory() +{ + irods::ms_table_entry* msvc = new irods::ms_table_entry(2); - msvc->add_operation< - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msiArchiveIndex", - std::function(msiArchiveIndex)); + msvc->add_operation( + "msiArchiveIndex", std::function(msiArchiveIndex)); return msvc; } - } diff --git a/src/msiRegisterEpicPID.cc b/src/msiRegisterEpicPID.cc index 0e24eb4..189cd5f 100644 --- a/src/msiRegisterEpicPID.cc +++ b/src/msiRegisterEpicPID.cc @@ -35,84 +35,95 @@ static CredentialsStore credentials; static size_t length; -std::string escapeJson(const std::string &s) { +std::string escapeJson(const std::string& s) +{ std::ostringstream o; for (auto c = s.cbegin(); c != s.cend(); c++) { switch (*c) { - case '"': o << "\\\""; break; - case '\\': o << "\\\\"; break; - case '\b': o << "\\b"; break; - case '\f': o << "\\f"; break; - case '\n': o << "\\n"; break; - case '\r': o << "\\r"; break; - case '\t': o << "\\t"; break; - default: - if ('\x00' <= *c && *c <= '\x1f') { - o << "\\u" - << std::hex << std::setw(4) << std::setfill('0') << (int)*c; - } else { - o << *c; - } + case '"': + o << "\\\""; + break; + case '\\': + o << "\\\\"; + break; + case '\b': + o << "\\b"; + break; + case '\f': + o << "\\f"; + break; + case '\n': + o << "\\n"; + break; + case '\r': + o << "\\r"; + break; + case '\t': + o << "\\t"; + break; + default: + if ('\x00' <= *c && *c <= '\x1f') { + o << "\\u" << std::hex << std::setw(4) << std::setfill('0') << (int) *c; + } + else { + o << *c; + } } } return o.str(); } extern "C" { - /* Curl requires a static callback function to read the input of a PUT request from. - * This callback simply copies the payload. */ - static size_t readCallback(void *buffer, size_t size, size_t nmemb, void *userp) - { - std::string *payload = (std::string *) userp; - size_t len = size * nmemb; - if (len > length) { - len = length; - } - memcpy(buffer, payload->c_str() + payload->length() - length, len); - length -= len; - - return len; - } - - /* Curl requires a static callback function to write the output of a request to. - * This callback simply discards everything. */ - static size_t discard(void *contents, size_t size, size_t nmemb, void *userp) - { - return size * nmemb; - } - - - int msiRegisterEpicPID(msParam_t* valueIn, - msParam_t* idInOut, - msParam_t* httpCodeOut, - ruleExecInfo_t *rei) - { - CURL *curl; +/* Curl requires a static callback function to read the input of a PUT request from. + * This callback simply copies the payload. */ +static size_t readCallback(void* buffer, size_t size, size_t nmemb, void* userp) +{ + std::string* payload = (std::string*) userp; + size_t len = size * nmemb; + if (len > length) { + len = length; + } + memcpy(buffer, payload->c_str() + payload->length() - length, len); + length -= len; + + return len; +} + +/* Curl requires a static callback function to write the output of a request to. + * This callback simply discards everything. */ +static size_t discard(void* contents, size_t size, size_t nmemb, void* userp) +{ + return size * nmemb; +} + +int msiRegisterEpicPID(msParam_t* valueIn, msParam_t* idInOut, msParam_t* httpCodeOut, ruleExecInfo_t* rei) +{ + CURL* curl; CURLcode res; /* Check if user is priviliged. */ if (rei->uoic->authInfo.authFlag < LOCAL_PRIV_USER_AUTH) { - return SYS_USER_NO_PERMISSION; + return SYS_USER_NO_PERMISSION; } /* Bail early if the credentials store could not be loaded */ if (!credentials.isLoaded()) { - return SYS_CONFIG_FILE_ERR; + return SYS_CONFIG_FILE_ERR; } /* Check input parameters. */ if (strcmp(valueIn->type, STR_MS_T)) { - return SYS_INVALID_INPUT_PARAM; + return SYS_INVALID_INPUT_PARAM; } /* Parse input paramaters. */ - std::string value = parseMspForStr(valueIn); - std::string uuid = parseMspForStr(idInOut); + std::string value = parseMspForStr(valueIn); + std::string uuid = parseMspForStr(idInOut); /* Bail if there is no EPIC server configured. */ if (!credentials.has("epic_url")) { - fillStrInMsParam(httpCodeOut, "0"); - return 0; + fillStrInMsParam(httpCodeOut, "0"); + return 0; } /* Retrieve parameters from the credentials store. */ @@ -127,116 +138,104 @@ extern "C" { /* Get a curl handle. */ curl = curl_easy_init(); - if(curl) { - /* First set the URL that is about to receive our PUT. */ - url += "/" + pid; - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - - /* Set HTTP headers. */ - struct curl_slist *list = NULL; - list = curl_slist_append(list, "Content-Type: application/json"); - list = curl_slist_append(list, "Authorization: Handle clientCert=\"true\""); - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); - - /* Specify the key and certificate. */ - curl_easy_setopt(curl, CURLOPT_SSLKEY, key.c_str()); - curl_easy_setopt(curl, CURLOPT_SSLCERT, certificate.c_str()); - - /* Create payload. */ - std::string payload = "{\"values\":[{\"index\":1,\"type\":\"URL\",\"data\":{\"format\":\"string\",\"value\":\"" + - escapeJson(value) + - "\"}},{\"index\":100,\"type\":\"HS_ADMIN\",\"data\":{\"format\":\"admin\",\"value\":{\"handle\":\"0.NA/" + - prefix + - "\",\"index\":200,\"permissions\":\"011111110011\"}}}]}"; - curl_easy_setopt(curl, CURLOPT_READFUNCTION, readCallback); - curl_easy_setopt(curl, CURLOPT_READDATA, &payload); - length = payload.length(); - curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long) length); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, discard); - - /* Don't verify the server certificate. */ - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - - /* Use the PUT command. */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); - - /* Perform the request, res will get the return code. */ - res = curl_easy_perform(curl); - - /* Check for errors. */ - if(res != CURLE_OK) { - rodsLog(LOG_ERROR, "msiRegisterEpicPID: curl error: %s", curl_easy_strerror(res)); - return SYS_INTERNAL_NULL_INPUT_ERR; - } else { - long http_code = 0; - curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code); - fillStrInMsParam(httpCodeOut, std::to_string(http_code).c_str()); - - /* 201 Created */ - if (http_code == 200 || http_code == 201) { - /* Operation successful.*/ - fillStrInMsParam(idInOut, pid.c_str()); - } - /* 400 Bad Request */ - else if (http_code == 400) { - rodsLog(LOG_ERROR, - "msiRegisterEpicPID: Invalid handle"); - } - /* 401 Unauthorized */ - else if (http_code == 401) { - rodsLog( LOG_ERROR, - "msiRegisterEpicPID: Authentication needed"); - } - /* 403 Forbidden */ - else if (http_code == 403) { - rodsLog(LOG_ERROR, - "msiRegisterEpicPID: Permission denied"); - } - /* 404 Not Found */ - else if (http_code == 404) { - rodsLog(LOG_ERROR, - "msiRegisterEpicPID: Handle not found"); - } - /* 409 Conflict */ - else if (http_code == 409) { - rodsLog(LOG_ERROR, - "msiRegisterEpicPID: Handle or value already exists"); - } - /* 500 Internal Server Error */ - else if (http_code == 500) { - rodsLog(LOG_ERROR, - "msiRegisterEpicPID: Server internal error"); + if (curl) { + /* First set the URL that is about to receive our PUT. */ + url += "/" + pid; + curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + + /* Set HTTP headers. */ + struct curl_slist* list = NULL; + list = curl_slist_append(list, "Content-Type: application/json"); + list = curl_slist_append(list, "Authorization: Handle clientCert=\"true\""); + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list); + + /* Specify the key and certificate. */ + curl_easy_setopt(curl, CURLOPT_SSLKEY, key.c_str()); + curl_easy_setopt(curl, CURLOPT_SSLCERT, certificate.c_str()); + + /* Create payload. */ + std::string payload = + "{\"values\":[{\"index\":1,\"type\":\"URL\",\"data\":{\"format\":\"string\",\"value\":\"" + + escapeJson(value) + + "\"}},{\"index\":100,\"type\":\"HS_ADMIN\",\"data\":{\"format\":\"admin\",\"value\":{\"handle\":\"0.NA/" + + prefix + "\",\"index\":200,\"permissions\":\"011111110011\"}}}]}"; + curl_easy_setopt(curl, CURLOPT_READFUNCTION, readCallback); + curl_easy_setopt(curl, CURLOPT_READDATA, &payload); + length = payload.length(); + curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long) length); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, discard); + + /* Don't verify the server certificate. */ + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + + /* Use the PUT command. */ + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); + + /* Perform the request, res will get the return code. */ + res = curl_easy_perform(curl); + + /* Check for errors. */ + if (res != CURLE_OK) { + rodsLog(LOG_ERROR, "msiRegisterEpicPID: curl error: %s", curl_easy_strerror(res)); + return SYS_INTERNAL_NULL_INPUT_ERR; } - else { - rodsLog(LOG_ERROR, - "msiRegisterEpicPID: HTTP error code: %lu", http_code); - } - } - - /* Cleanup. */ - curl_easy_cleanup(curl); + else { + long http_code = 0; + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); + fillStrInMsParam(httpCodeOut, std::to_string(http_code).c_str()); + + /* 201 Created */ + if (http_code == 200 || http_code == 201) { + /* Operation successful.*/ + fillStrInMsParam(idInOut, pid.c_str()); + } + /* 400 Bad Request */ + else if (http_code == 400) { + rodsLog(LOG_ERROR, "msiRegisterEpicPID: Invalid handle"); + } + /* 401 Unauthorized */ + else if (http_code == 401) { + rodsLog(LOG_ERROR, "msiRegisterEpicPID: Authentication needed"); + } + /* 403 Forbidden */ + else if (http_code == 403) { + rodsLog(LOG_ERROR, "msiRegisterEpicPID: Permission denied"); + } + /* 404 Not Found */ + else if (http_code == 404) { + rodsLog(LOG_ERROR, "msiRegisterEpicPID: Handle not found"); + } + /* 409 Conflict */ + else if (http_code == 409) { + rodsLog(LOG_ERROR, "msiRegisterEpicPID: Handle or value already exists"); + } + /* 500 Internal Server Error */ + else if (http_code == 500) { + rodsLog(LOG_ERROR, "msiRegisterEpicPID: Server internal error"); + } + else { + rodsLog(LOG_ERROR, "msiRegisterEpicPID: HTTP error code: %lu", http_code); + } + } + + /* Cleanup. */ + curl_easy_cleanup(curl); } /* Cleanup. */ curl_global_cleanup(); return 0; - } - - irods::ms_table_entry* plugin_factory() { - irods::ms_table_entry *msvc = new irods::ms_table_entry(3); - - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msiRegisterEpicPID", - std::function(msiRegisterEpicPID)); +} + +irods::ms_table_entry* plugin_factory() +{ + irods::ms_table_entry* msvc = new irods::ms_table_entry(3); + + msvc->add_operation( + "msiRegisterEpicPID", + std::function(msiRegisterEpicPID)); return msvc; - } +} } diff --git a/src/msi_add_avu.cpp b/src/msi_add_avu.cpp index 1104850..2e09110 100644 --- a/src/msi_add_avu.cpp +++ b/src/msi_add_avu.cpp @@ -2,40 +2,39 @@ #include "irods_ms_plugin.hpp" #include "rsModAVUMetadata.hpp" -int msiAddAVU( - msParam_t* _item_type, - msParam_t* _item_name, - msParam_t* _attr_name, - msParam_t* _attr_val, - msParam_t* _attr_unit, - ruleExecInfo_t* _rei ) { - - char *it_str = parseMspForStr( _item_type ); - if( !it_str ) { +int msiAddAVU(msParam_t* _item_type, + msParam_t* _item_name, + msParam_t* _attr_name, + msParam_t* _attr_val, + msParam_t* _attr_unit, + ruleExecInfo_t* _rei) +{ + char* it_str = parseMspForStr(_item_type); + if (!it_str) { return SYS_INVALID_INPUT_PARAM; } - char *in_str = parseMspForStr( _item_name ); - if( !in_str ) { + char* in_str = parseMspForStr(_item_name); + if (!in_str) { return SYS_INVALID_INPUT_PARAM; } - char *an_str = parseMspForStr( _attr_name ); - if( !an_str ) { + char* an_str = parseMspForStr(_attr_name); + if (!an_str) { return SYS_INVALID_INPUT_PARAM; } - char *av_str = parseMspForStr( _attr_val ); - if( !av_str ) { + char* av_str = parseMspForStr(_attr_val); + if (!av_str) { return SYS_INVALID_INPUT_PARAM; } - char *au_str = parseMspForStr( _attr_unit ); - if( !au_str ) { + char* au_str = parseMspForStr(_attr_unit); + if (!au_str) { return SYS_INVALID_INPUT_PARAM; } - char op[] = "add"; + char op[] = "add"; modAVUMetadataInp_t avuOp; memset(&avuOp, 0, sizeof(avuOp)); @@ -49,26 +48,14 @@ int msiAddAVU( _rei->status = rsModAVUMetadata(_rei->rsComm, &avuOp); return _rei->status; - } -extern "C" -irods::ms_table_entry* plugin_factory() { +extern "C" irods::ms_table_entry* plugin_factory() +{ irods::ms_table_entry* msvc = new irods::ms_table_entry(5); - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msiAddAVU", - std::function(msiAddAVU)); + msvc->add_operation( + "msiAddAVU", + std::function(msiAddAVU)); return msvc; } \ No newline at end of file diff --git a/src/msi_json_arrayops.cc b/src/msi_json_arrayops.cc index 3533763..7071433 100644 --- a/src/msi_json_arrayops.cc +++ b/src/msi_json_arrayops.cc @@ -12,133 +12,137 @@ //#include extern "C" { - // =-=-=-=-=-=-=- - int msi_json_arrayops(msParam_t* json_str, msParam_t* val, msParam_t* ops, msParam_t* sizeOrIndex, ruleExecInfo_t* rei) { - using std::cout; - using std::endl; - using std::string; - - // input type check - const char *inJsonStr = parseMspForStr( json_str ); - const char *inVal = parseMspForStr( val ); - const char *inOps = parseMspForStr( ops ); - const int inIdx = parseMspForPosInt( sizeOrIndex ); - - if( ! inJsonStr ) { - cout << "msi_json_arrayops - invalid inJsonStr" << endl; - return SYS_INVALID_INPUT_PARAM; - } - if( ! inOps ) { - cout << "msi_json_arrayops - invalid inOps" << endl; - return SYS_INVALID_INPUT_PARAM; - } - if( ! inVal ) { - cout << "msi_json_arrayops - invalid inVal" << endl; - return SYS_INVALID_INPUT_PARAM; - } +// =-=-=-=-=-=-=- +int msi_json_arrayops(msParam_t* json_str, msParam_t* val, msParam_t* ops, msParam_t* sizeOrIndex, ruleExecInfo_t* rei) +{ + using std::cout; + using std::endl; + using std::string; + + // input type check + const char* inJsonStr = parseMspForStr(json_str); + const char* inVal = parseMspForStr(val); + const char* inOps = parseMspForStr(ops); + const int inIdx = parseMspForPosInt(sizeOrIndex); + + if (!inJsonStr) { + cout << "msi_json_arrayops - invalid inJsonStr" << endl; + return SYS_INVALID_INPUT_PARAM; + } + if (!inOps) { + cout << "msi_json_arrayops - invalid inOps" << endl; + return SYS_INVALID_INPUT_PARAM; + } + if (!inVal) { + cout << "msi_json_arrayops - invalid inVal" << endl; + return SYS_INVALID_INPUT_PARAM; + } - string strOps(inOps); + string strOps(inOps); - json_error_t error; - json_t *root; + json_error_t error; + json_t* root; - // try to make initial inJsonStr if it's an empty string - if ( strcmp(inJsonStr, "") == 0 ) { - inJsonStr = "[]"; - } + // try to make initial inJsonStr if it's an empty string + if (strcmp(inJsonStr, "") == 0) { + inJsonStr = "[]"; + } - // try to load JSON object - root = json_loads(inJsonStr, 0, &error); - if ( ! root || ! json_is_array(root) ) { - cout << "msi_json_arrayops - invalid json document" << endl; - json_decref(root); - return SYS_INVALID_INPUT_PARAM; - } + // try to load JSON object + root = json_loads(inJsonStr, 0, &error); + if (!root || !json_is_array(root)) { + cout << "msi_json_arrayops - invalid json document" << endl; + json_decref(root); + return SYS_INVALID_INPUT_PARAM; + } - int outSizeOrIndex = (int) json_array_size(root); - json_t *jval; - if (strcmp(inVal, "null") == 0) { - jval = json_null(); - } else if (strcmp(inVal, "true") == 0 ) { - jval = json_true(); - } else if (strcmp(inVal, "false") == 0 ) { - jval = json_false(); - } else { - jval = json_loads(inVal, 0, &error); - if ( ! jval ) jval = json_string(inVal); - } + int outSizeOrIndex = (int) json_array_size(root); + json_t* jval; + if (strcmp(inVal, "null") == 0) { + jval = json_null(); + } + else if (strcmp(inVal, "true") == 0) { + jval = json_true(); + } + else if (strcmp(inVal, "false") == 0) { + jval = json_false(); + } + else { + jval = json_loads(inVal, 0, &error); + if (!jval) + jval = json_string(inVal); + } - // find if jval is already presented in array - size_t i_match = outSizeOrIndex; - for( int i=0; i < outSizeOrIndex; i++ ) { - json_t *ov = json_array_get(root, i); - if ( json_equal(ov, jval) ) { i_match = i; break; } + // find if jval is already presented in array + size_t i_match = outSizeOrIndex; + for (int i = 0; i < outSizeOrIndex; i++) { + json_t* ov = json_array_get(root, i); + if (json_equal(ov, jval)) { + i_match = i; + break; } + } - if ( strOps == "add" ) { - // append value only if it's a boolean, or it's not presented in the array - if ( json_is_boolean(jval) || i_match == outSizeOrIndex ) { - json_array_append_new(root, jval); - outSizeOrIndex = (int) json_array_size(root); - } - } else if ( strOps == "find" || strOps == "rm" ) { - - if ( i_match < outSizeOrIndex ) { - if ( strOps == "rm" ) { - json_array_remove(root, i_match); - outSizeOrIndex = (int) json_array_size(root); - } else { - outSizeOrIndex = i_match; - } - } else if ( strOps == "find" ) { - outSizeOrIndex = -1; - } - } else if ( strOps == "size" ) { + if (strOps == "add") { + // append value only if it's a boolean, or it's not presented in the array + if (json_is_boolean(jval) || i_match == outSizeOrIndex) { + json_array_append_new(root, jval); outSizeOrIndex = (int) json_array_size(root); - } else if ( strOps == "get" ) { - json_t *elem = json_array_get(root, inIdx); - if (elem == NULL) { - json_decref(root); - return SYS_INVALID_INPUT_PARAM; + } + } + else if (strOps == "find" || strOps == "rm") { + if (i_match < outSizeOrIndex) { + if (strOps == "rm") { + json_array_remove(root, i_match); + outSizeOrIndex = (int) json_array_size(root); } - - /* output a string directly, but encode other json types using json_dumps with JSON_ENCODE_ANY set */ - if ( json_is_string(elem)) { - fillStrInMsParam(val, json_string_value(elem)); - } else { - fillStrInMsParam(val, json_dumps(elem, JSON_ENCODE_ANY)); + else { + outSizeOrIndex = i_match; } + } + else if (strOps == "find") { + outSizeOrIndex = -1; + } + } + else if (strOps == "size") { + outSizeOrIndex = (int) json_array_size(root); + } + else if (strOps == "get") { + json_t* elem = json_array_get(root, inIdx); + if (elem == NULL) { + json_decref(root); + return SYS_INVALID_INPUT_PARAM; + } - - outSizeOrIndex = inIdx; + /* output a string directly, but encode other json types using json_dumps with JSON_ENCODE_ANY set */ + if (json_is_string(elem)) { + fillStrInMsParam(val, json_string_value(elem)); + } + else { + fillStrInMsParam(val, json_dumps(elem, JSON_ENCODE_ANY)); } - fillStrInMsParam(json_str, json_dumps(root, 0)); - fillIntInMsParam(sizeOrIndex, outSizeOrIndex); + outSizeOrIndex = inIdx; + } - json_decref(root); + fillStrInMsParam(json_str, json_dumps(root, 0)); + fillIntInMsParam(sizeOrIndex, outSizeOrIndex); - // Done - return 0; - } + json_decref(root); - irods::ms_table_entry* plugin_factory() { + // Done + return 0; +} + +irods::ms_table_entry* plugin_factory() +{ irods::ms_table_entry* msvc = new irods::ms_table_entry(4); - - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msi_json_arrayops", - std::function(msi_json_arrayops)); + + msvc->add_operation( + "msi_json_arrayops", + std::function(msi_json_arrayops)); return msvc; - } +} } // extern "C" diff --git a/src/msi_json_objops.cc b/src/msi_json_objops.cc index ec0a2d2..680fadf 100644 --- a/src/msi_json_objops.cc +++ b/src/msi_json_objops.cc @@ -12,136 +12,143 @@ #include extern "C" { - // =-=-=-=-=-=-=- - int msi_json_objops(msParam_t* json_str, msParam_t* kvp, msParam_t* ops, ruleExecInfo_t* rei) { - using std::cout; - using std::endl; - using std::string; - - char *null_cstr = new char[5]; - char *true_cstr = new char[5]; - char *false_cstr = new char[6]; - - strcpy(null_cstr, "null"); - strcpy(true_cstr, "true"); - strcpy(false_cstr, "false"); - - // input type check - const char *inJsonStr = parseMspForStr( json_str ); - const char *inOps = parseMspForStr( ops ); - if( ! inJsonStr || ! inOps) { - cout << "msi_json_objops - invalid input for string" << endl; - return SYS_INVALID_INPUT_PARAM; - } +// =-=-=-=-=-=-=- +int msi_json_objops(msParam_t* json_str, msParam_t* kvp, msParam_t* ops, ruleExecInfo_t* rei) +{ + using std::cout; + using std::endl; + using std::string; + + char* null_cstr = new char[5]; + char* true_cstr = new char[5]; + char* false_cstr = new char[6]; + + strcpy(null_cstr, "null"); + strcpy(true_cstr, "true"); + strcpy(false_cstr, "false"); + + // input type check + const char* inJsonStr = parseMspForStr(json_str); + const char* inOps = parseMspForStr(ops); + if (!inJsonStr || !inOps) { + cout << "msi_json_objops - invalid input for string" << endl; + return SYS_INVALID_INPUT_PARAM; + } - if (kvp == NULL || kvp->inOutStruct == NULL || - kvp->type == NULL || strcmp(kvp->type, KeyValPair_MS_T) != 0) { - cout << "msi_json_objops - invalid input for key-value pairs" << endl; - return SYS_INVALID_INPUT_PARAM; - } + if (kvp == NULL || kvp->inOutStruct == NULL || kvp->type == NULL || strcmp(kvp->type, KeyValPair_MS_T) != 0) { + cout << "msi_json_objops - invalid input for key-value pairs" << endl; + return SYS_INVALID_INPUT_PARAM; + } - keyValPair_t *inKVP; - inKVP = (keyValPair_t*) kvp->inOutStruct; + keyValPair_t* inKVP; + inKVP = (keyValPair_t*) kvp->inOutStruct; - string strOps(inOps); + string strOps(inOps); - json_error_t error; - json_t *root; + json_error_t error; + json_t* root; - // try to make initial inJsonStr if it's an empty string - if ( strcmp(inJsonStr, "") == 0 ) { - inJsonStr = "{}"; - } + // try to make initial inJsonStr if it's an empty string + if (strcmp(inJsonStr, "") == 0) { + inJsonStr = "{}"; + } - // try to load JSON object - root = json_loads(inJsonStr, 0, &error); - if ( ! root ) { - cout << "msi_json_objops - invalid json document" << endl; - json_decref(root); - return SYS_INVALID_INPUT_PARAM; - } + // try to load JSON object + root = json_loads(inJsonStr, 0, &error); + if (!root) { + cout << "msi_json_objops - invalid json document" << endl; + json_decref(root); + return SYS_INVALID_INPUT_PARAM; + } - for (int ik=0; iklen; ik++) { + for (int ik = 0; ik < inKVP->len; ik++) { + char* inKey = inKVP->keyWord[ik]; + char* inVal = inKVP->value[ik]; - char* inKey = inKVP->keyWord[ik]; - char* inVal = inKVP->value[ik]; + json_t* jval; + if (strcmp(inVal, null_cstr) == 0) { + jval = json_null(); + } + else { + jval = json_loads(inVal, 0, &error); + if (!jval) + jval = json_string(inVal); + } - json_t *jval; - if (strcmp(inVal, null_cstr) == 0) { - jval = json_null(); - } else { - jval = json_loads(inVal, 0, &error); - if ( ! jval ) jval = json_string(inVal); + // try to find objects in the key + json_t* data = json_object_get(root, inKey); + + if (strOps == "get") { + if (json_is_null(data)) { + inKVP->value[ik] = null_cstr; } - - // try to find objects in the key - json_t *data = json_object_get(root, inKey); - - if ( strOps == "get" ) { - if ( json_is_null(data) ) { - inKVP->value[ik] = null_cstr; - } else if ( json_is_true(data) ) { - inKVP->value[ik] = true_cstr; - } else if ( json_is_false(data) ) { - inKVP->value[ik] = false_cstr; - } else if ( json_is_string(data) ) { - const char* val_str = json_string_value(data); - char *val_cstr = new char[strlen(val_str) + 1]; - strcpy(val_cstr, val_str); - inKVP->value[ik] = val_cstr; - } else { - inKVP->value[ik] = json_dumps(data,0); - } - } else if ( strOps == "add" ) { - if (json_is_array( data )) { - json_array_append_new(data, jval); - } else { - json_object_set_new(root, inKey, jval); - } - } else if ( strOps == "set" ) { + else if (json_is_true(data)) { + inKVP->value[ik] = true_cstr; + } + else if (json_is_false(data)) { + inKVP->value[ik] = false_cstr; + } + else if (json_is_string(data)) { + const char* val_str = json_string_value(data); + char* val_cstr = new char[strlen(val_str) + 1]; + strcpy(val_cstr, val_str); + inKVP->value[ik] = val_cstr; + } + else { + inKVP->value[ik] = json_dumps(data, 0); + } + } + else if (strOps == "add") { + if (json_is_array(data)) { + json_array_append_new(data, jval); + } + else { json_object_set_new(root, inKey, jval); - } else if ( strOps == "rm" ) { - if ( data ) { - if ( json_is_array( data ) ) { - size_t i_match = json_array_size(data); - for( int i=0; iinOutStruct = (void *) inKVP; - kvp->type = (char *) strdup(KeyValPair_MS_T); + kvp->inOutStruct = (void*) inKVP; + kvp->type = (char*) strdup(KeyValPair_MS_T); - fillStrInMsParam(json_str, json_dumps(root, 0)); + fillStrInMsParam(json_str, json_dumps(root, 0)); - json_decref(root); + json_decref(root); - // Done - return 0; - } + // Done + return 0; +} - irods::ms_table_entry* plugin_factory() { - irods::ms_table_entry* msvc = new irods::ms_table_entry(3); - - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msi_json_objops", - std::function(msi_json_objops)); - - return msvc; - } +irods::ms_table_entry* plugin_factory() +{ + irods::ms_table_entry* msvc = new irods::ms_table_entry(3); + + msvc->add_operation( + "msi_json_objops", std::function(msi_json_objops)); + + return msvc; +} } // extern "C" diff --git a/src/msi_rmw_avu.cpp b/src/msi_rmw_avu.cpp index b00b016..6a172cb 100644 --- a/src/msi_rmw_avu.cpp +++ b/src/msi_rmw_avu.cpp @@ -2,40 +2,39 @@ #include "irods_ms_plugin.hpp" #include "rsModAVUMetadata.hpp" -int msiRmwAVU( - msParam_t* _item_type, - msParam_t* _item_name, - msParam_t* _attr_name, - msParam_t* _attr_val, - msParam_t* _attr_unit, - ruleExecInfo_t* _rei ) { - - char *it_str = parseMspForStr( _item_type ); - if( !it_str ) { +int msiRmwAVU(msParam_t* _item_type, + msParam_t* _item_name, + msParam_t* _attr_name, + msParam_t* _attr_val, + msParam_t* _attr_unit, + ruleExecInfo_t* _rei) +{ + char* it_str = parseMspForStr(_item_type); + if (!it_str) { return SYS_INVALID_INPUT_PARAM; } - char *in_str = parseMspForStr( _item_name ); - if( !in_str ) { + char* in_str = parseMspForStr(_item_name); + if (!in_str) { return SYS_INVALID_INPUT_PARAM; } - char *an_str = parseMspForStr( _attr_name ); - if( !an_str ) { + char* an_str = parseMspForStr(_attr_name); + if (!an_str) { return SYS_INVALID_INPUT_PARAM; } - char *av_str = parseMspForStr( _attr_val ); - if( !av_str ) { + char* av_str = parseMspForStr(_attr_val); + if (!av_str) { return SYS_INVALID_INPUT_PARAM; } - char *au_str = parseMspForStr( _attr_unit ); - if( !au_str ) { + char* au_str = parseMspForStr(_attr_unit); + if (!au_str) { return SYS_INVALID_INPUT_PARAM; } - char op[] = "rmw"; + char op[] = "rmw"; modAVUMetadataInp_t avuOp; memset(&avuOp, 0, sizeof(avuOp)); @@ -49,26 +48,14 @@ int msiRmwAVU( _rei->status = rsModAVUMetadata(_rei->rsComm, &avuOp); return _rei->status; - } -extern "C" -irods::ms_table_entry* plugin_factory() { +extern "C" irods::ms_table_entry* plugin_factory() +{ irods::ms_table_entry* msvc = new irods::ms_table_entry(5); - msvc->add_operation< - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - msParam_t*, - ruleExecInfo_t*>("msiRmwAVU", - std::function(msiRmwAVU)); + msvc->add_operation( + "msiRmwAVU", + std::function(msiRmwAVU)); return msvc; } \ No newline at end of file