/* * Created 07/25/2015 * @brief creates new jsoj string object * @param record_name: the nemae of the json record * @param value: staring value * @return 0 - faile, pointer to initiated json_record_t at type JS_OBJECT */ json_record_t *json_record_new_object(char *record_name) { /* * Inittiates new json_record_t * TODO: check for memory faile at json_string_new */ json_record_t *json_record = json_record_new(); /* * creates json string , * TODO: check for memory faile at json_string_new */ //json_string_init(&json_record->name,record_name); json_string_set(&json_record->name,record_name); // json_object_set(&json_record->value.u.object); /* *set json value as JS_OBJECT */ json_record->value.type = JS_OBJECT; link_list_init(&json_record->value.u.object.json_objects); return json_record; }
/** * Created 07/25/2015 * @brief creates new json_value_t structure * @param * @return 0 - success,1 fail */ json_value_t * json_string(char *str) { json_value_t *json_value= malloc(sizeof(json_value_t)); json_string_set (&json_value->u.string,str); json_value->type = JS_STRING; return json_value; }
/* * Created 07/25/2015 * @brief creates new jsoj string object * @param record_name: the nemae of the json record * @param value: staring value * @return 0 - faile, pointer to initiated json_record_t at type JS_BOOLIAN */ json_record_t *json_record_new_boolian(char *record_name,char value) { /* * Inittiates new json_record_t * TODO: check for memory faile at json_string_new */ json_record_t *json_record = json_record_new(); /* * creates json string , * TODO: check for memory faile at json_string_new */ //json_string_init(&json_record->name,record_name); json_string_set(&json_record->name,record_name); /* *set json value as JS_INTEGER */ json_record->value.type = JS_BOOLIAN; json_record->value.u.boolian = value; return json_record; }
/* * Created 07/25/2015 * @brief creates new jsoj string object * @param record_name: the nemae of the json record * @param value: staring value * @return 0 - faile, pointer to initiated json_record_t at type JS_DOUBLE */ json_record_t *json_record_new_double(char *record_name,double value) { /* * Inittiates new json_record_t * TODO: check for memory faile at json_string_new */ json_record_t *json_record = json_record_new(); /* * creates json string , * TODO: check for memory faile at json_string_new */ json_string_set(&json_record->name,record_name); //json_double_set(&json_record->value.u.real,value); /* *set json value as JS_DOUBLE */ json_record->value.type = JS_DOUBLE; json_record->value.u.real = value; return json_record; }
GhbValue* ghb_string_value(const gchar *str) { static GhbValue *gval = NULL; if (gval == NULL) gval = json_string(str); else json_string_set(gval, str); return gval; }
/* * Created 07/25/2015 * @brief creates new jsoj string object * @param record_name: the nemae of the json record * @param value: staring value * @return 0 - faile, pointer to initiated json_object_t at type JS_STRING */ json_record_t *json_record_new_string(char *record_name,char *value) { /* * Inittiates new json_record_t * TODO: check for memory faile at json_string_new */ json_record_t *json_record = json_record_new(); /* * creates json string , * TODO: check for memory faile at json_string_new */ json_string_set(&json_record->name,record_name); /* *set json value as JS_STRING */ // json_record->js_type = JS_STRING; json_string_set (&json_record->value.u.string,value); return json_record; }
/* * Created 07/25/2015 * @brief creates new jsoj string object * @param record_name: the nemae of the json record * @param value: staring value * @return 0 - faile, pointer to initiated json_record_t at type JS_ARRAY */ struct json_record_s *json_record_new_array(char *record_name) { /* * Inittiates new json_record_t * TODO: check for memory faile at json_string_new */ json_record_t *json_record = json_record_new(); /* * creates json string , * TODO: check for memory faile at json_string_new */ json_string_set(&json_record->name,record_name); // json_record_set(&json_record->value.u.array); /* *set json value as JS_ARRAY */ json_record->value.type = JS_ARRAY; link_list_init (&json_record->value.u.array.json_records); return json_record; }
/* Call the simple functions not covered by other tests of the public API */ int main() { json_t *value; value = json_integer(1); if(json_typeof(value) != JSON_INTEGER) fail("json_typeof failed"); if(json_is_object(value)) fail("json_is_object failed"); if(json_is_array(value)) fail("json_is_array failed"); if(json_is_string(value)) fail("json_is_string failed"); if(!json_is_integer(value)) fail("json_is_integer failed"); if(json_is_real(value)) fail("json_is_real failed"); if(!json_is_number(value)) fail("json_is_number failed"); if(json_is_true(value)) fail("json_is_true failed"); if(json_is_false(value)) fail("json_is_false failed"); if(json_is_boolean(value)) fail("json_is_boolean failed"); if(json_is_null(value)) fail("json_is_null failed"); json_decref(value); value = json_string("foo"); if(!value) fail("json_string failed"); if(strcmp(json_string_value(value), "foo")) fail("invalid string value"); if(json_string_set(value, "bar")) fail("json_string_set failed"); if(strcmp(json_string_value(value), "bar")) fail("invalid string value"); json_decref(value); value = json_string(NULL); if(value) fail("json_string(NULL) failed"); /* invalid UTF-8 */ value = json_string("a\xefz"); if(value) fail("json_string(<invalid utf-8>) failed"); value = json_string_nocheck("foo"); if(!value) fail("json_string_nocheck failed"); if(strcmp(json_string_value(value), "foo")) fail("invalid string value"); if(json_string_set_nocheck(value, "bar")) fail("json_string_set_nocheck failed"); if(strcmp(json_string_value(value), "bar")) fail("invalid string value"); json_decref(value); /* invalid UTF-8 */ value = json_string_nocheck("qu\xff"); if(!value) fail("json_string_nocheck failed"); if(strcmp(json_string_value(value), "qu\xff")) fail("invalid string value"); if(json_string_set_nocheck(value, "\xfd\xfe\xff")) fail("json_string_set_nocheck failed"); if(strcmp(json_string_value(value), "\xfd\xfe\xff")) fail("invalid string value"); json_decref(value); value = json_integer(123); if(!value) fail("json_integer failed"); if(json_integer_value(value) != 123) fail("invalid integer value"); if(json_number_value(value) != 123.0) fail("invalid number value"); if(json_integer_set(value, 321)) fail("json_integer_set failed"); if(json_integer_value(value) != 321) fail("invalid integer value"); if(json_number_value(value) != 321.0) fail("invalid number value"); json_decref(value); value = json_real(123.123); if(!value) fail("json_real failed"); if(json_real_value(value) != 123.123) fail("invalid integer value"); if(json_number_value(value) != 123.123) fail("invalid number value"); if(json_real_set(value, 321.321)) fail("json_real_set failed"); if(json_real_value(value) != 321.321) fail("invalid real value"); if(json_number_value(value) != 321.321) fail("invalid number value"); json_decref(value); value = json_true(); if(!value) fail("json_true failed"); json_decref(value); value = json_false(); if(!value) fail("json_false failed"); json_decref(value); value = json_null(); if(!value) fail("json_null failed"); json_decref(value); /* Test reference counting on singletons (true, false, null) */ value = json_true(); if(value->refcount != (size_t)-1) fail("refcounting true works incorrectly"); json_decref(value); if(value->refcount != (size_t)-1) fail("refcounting true works incorrectly"); json_incref(value); if(value->refcount != (size_t)-1) fail("refcounting true works incorrectly"); value = json_false(); if(value->refcount != (size_t)-1) fail("refcounting false works incorrectly"); json_decref(value); if(value->refcount != (size_t)-1) fail("refcounting false works incorrectly"); json_incref(value); if(value->refcount != (size_t)-1) fail("refcounting false works incorrectly"); value = json_null(); if(value->refcount != (size_t)-1) fail("refcounting null works incorrectly"); json_decref(value); if(value->refcount != (size_t)-1) fail("refcounting null works incorrectly"); json_incref(value); if(value->refcount != (size_t)-1) fail("refcounting null works incorrectly"); return 0; }
void ghb_string_value_set(GhbValue *gval, const gchar *str) { json_string_set(gval, str); }
int ast_json_string_set(struct ast_json *string, const char *value) { return json_string_set((json_t *)string, value); }
int la_codec_string_set(la_codec_value_t *string, const char *value) { return json_string_set((json_t *) string, value); }
int main(int argc, char *argv[]) { //setHttpAuth("admin:admin"); //setHttpData("{\"ins_api\":{\"version\":\"1.2\",\"type\":\"cli_show\",\"chunk\":\"0\",\"sid\":\"1\",\"input\":\"show version\",\"output_format\":\"json\"}}"); //appendHttpHeader("Content-Type: application/json"); //printf("%s\n",httpFunction("http://192.168.113.50/ins")); OV_Version = OV200; char *oneViewAddress; //main2(); //sleep(40); // Check for Debug Mode if (getenv("OV_DEBUG")) { debug = 1; // debug mode enabled } else { debug = 0; // debug mode disabled } // Peform an initial check to see what parameters have been passed char path[100]; if (argc >1) { oneViewAddress = argv[1]; if (is_valid_ip(oneViewAddress)) { // Create a string based upon the path to the sessionID identifySystem(oneViewAddress); sprintf(path, "/.%s_ov",oneViewAddress); } else { printMessage(YELLOW, "DEBUG", "Invalid IP Address"); return 1; } } if(argc < 3) { printMessage(YELLOW, "DEBUG", "No parameters passed"); fprintf(stderr, "usage: %s ADDRESS COMMAND <parameters>\n", argv[0]); // Somewhat over the top logo fprintf(stderr, " \ _ _ ____ ___ __ ___\n\ | | | | _ \\ / _ \\ _ __ __\\ \\ / (_) _____ __\n\ | |_| | |_) | | | | | '_ \\ / _ \\ \\ / /| |/ _ \\ \\ /\\ / /\n\ | _ | __/ | |_| | | | | __/\\ V / | | __/\\ V V /\n\ |_| |_|_| \\___/|_| |_|\\___| \\_/ |_|\\___| \\_/\\_/ \n\n"); //Print the relevant helps ovCreatePrintHelp(); ovShowPrintHelp(); ovCopyPrintHelp(); ovMessageBusHelp(); return 1; } char url[URL_SIZE]; char *httpData; json_t *root = NULL; json_error_t error; // Determine the action to be executed if (stringMatch(argv[2], "LOGIN")) { // Login to HP OneView SetHttpMethod(DCHTTPPOST); ovLogin(argv, path); return 0; } else if (stringMatch(argv[2], "SHOW")) { // Show/Query information from HP OneView char *sessionID = readSessionIDforHost(path); if (!sessionID) { printf("[ERROR] No session ID\n"); return 1; } ovShow(sessionID, argc, argv); return 0; // return sucess } else if (stringMatch(argv[2], "CREATE")) { char *sessionID = readSessionIDforHost(path); if (!sessionID) { printf("[ERROR] No session ID\n"); return 1; } ovCreate(sessionID, argv); return 0; // Return success } else if (strstr(argv[2], "COPY")) { char *sessionID = readSessionIDforHost(path); if (!sessionID) { printf("[ERROR] No session ID\n"); return 1; } ovCopy(sessionID, argv); return 0; //return success } else if (strstr(argv[2], "CLONE")) { char *sessionID = readSessionIDforHost(path); if (!sessionID) { printf("[ERROR] No session ID"); return 1; } // DEBUG OVID output //printf("[DEBUG] OVID:\t %s\n",sessionID); if (strstr(argv[3], "SERVER-PROFILES")) { snprintf(url, URL_SIZE, URL_FORMAT, argv[1], "server-profiles"); // Call to HP OneView API httpData = getRequestWithUrlAndHeader(url, sessionID); if(!httpData) return 1; //printf("[DEBUG] JSON: %s\n", httpData); root = json_loads(httpData, 0, &error); // Find Server Profile first //int fieldCount = argc -5; //argv[0] is the path to the program json_t *memberArray = json_object_get(root, "members"); if (json_array_size(memberArray) != 0) { size_t index; json_t *serverProfile = NULL; //char *json_text; json_array_foreach(memberArray, index, serverProfile) { const char *uri = json_string_value(json_object_get(serverProfile, "uri")); char *cloneuri = argv[4]; printf ("%s / %s /n", cloneuri, url); if (uri != NULL) { if (stringMatch(cloneuri, (char *)uri)) { //json_text = json_dumps(serverProfile, JSON_INDENT(4)); //4 is close to a tab //printf("%s\n", json_text); // json_object_del(serverProfile, "uri"); json_object_del(serverProfile, "serialNumber"); json_object_del(serverProfile, "uuid"); json_object_del(serverProfile, "taskUri"); json_object_del(serverProfile, "status"); json_object_del(serverProfile, "inProgress"); json_object_del(serverProfile, "modified"); json_object_del(serverProfile, "eTag"); json_object_del(serverProfile, "created"); json_object_del(serverProfile, "serverHardwareUri"); json_object_del(serverProfile, "enclosureBay"); json_object_del(serverProfile, "enclosureUri"); //json_object_del(serverProfile, "connections"); json_t *connections, *connectionsArray= json_object_get(serverProfile, "connections"); json_array_foreach(connectionsArray, index, connections) { json_object_del(connections, "mac"); json_object_del(connections, "wwnn"); json_object_del(connections, "wwpn"); } int profileCount = atoi(argv[5]); if (profileCount != 0){ char name[100]; //strcat(name, json_string_value(json_object_get(serverProfile, "name"))); //strcat(name, ) //const char *profileName = json_string_value(json_object_get(serverProfile, "name")); char profileName[100]; strcpy(profileName, json_string_value(json_object_get(serverProfile, "name"))); for (int i =0; i <profileCount; i++) { sprintf(name, "%s_%d",profileName, i); printf("%s\n", name); json_string_set( json_object_get(serverProfile, "name"), name); httpData = postRequestWithUrlAndDataAndHeader(url, json_dumps(serverProfile, JSON_ENSURE_ASCII), sessionID); if(!httpData) return 1; } } //printf("%s\n", json_string_value(json_object_get(serverProfile, "name"))); //json_dumps(root, JSON_ENSURE_ASCII) /* httpData = postRequestWithUrlAndDataAndHeader(url, json_dumps(serverProfile, JSON_ENSURE_ASCII), sessionID); if(!httpData) return 1; //free(json_text); json_text = json_dumps(serverProfile, JSON_INDENT(4)); //4 is close to a tab printf("%s\n", json_text); free(json_text); */ } }