static corto_int16 html_copyFiles(htmlData_t *data) { corto_string doc; corto_asprintf(&doc, "%s/doc", CORTO_GEN_DOC_HTML_ETC); corto_ll files = corto_opendir(doc); if (!files) { goto error; } corto_iter it = corto_llIter(files); while (corto_iterHasNext(&it)) { corto_string f = corto_iterNext(&it); corto_id file; sprintf(file, "%s/%s", doc, f); if (corto_cp(file, data->output)) { goto error; } } corto_closedir(files); corto_dealloc(doc); return 0; error: return -1; }
cdiff_file cdiff_file_open (char* filename) { cdiff_file result = malloc(sizeof(struct cdiff_file_s)); /* Store current working directory in case the application using this * function changes the cwd before closing the file. */ corto_asprintf(&result->name, "%s/%s", corto_cwd(), filename); result->elements = NULL; result->legacyElements = NULL; result->isChanged = false; result->writeBuffer = CORTO_BUFFER_INIT; result->writeTo = 0; result->indent = 0; result->newLine = true; result->cur = NULL; char *source = corto_fileLoad(result->name); if (source) { result->isNew = false; /* Check for legacy */ if (strstr(source, "$CORTO_GENERATED")) { if (strstr(source, "$begin") || strstr(source, "$header")) { result->legacyElements = cdiff_parseLegacy(source); if (!result->legacyElements) { goto error; } result->isChanged = true; result->isNew = true; } } /* Parse file (only when not parsing legacy file) */ if (!result->legacyElements) { result->elements = cdiff_parse(source); if (!result->elements) { goto error; } } free(source); } else { corto_lasterr(); /* silence warning */ result->isNew = true; } return result; error: if (source) { free(source); } return NULL; }
corto_int16 json_deserialize(corto_value *v, corto_string s) { corto_assert(v != NULL, "NULL passed to json_deserialize"); char *json = s; if ((json[0] != '{') && (json[1] != '[') && (json[0] != '[')) { corto_asprintf(&json, "{\"value\": %s}", json); } JSON_Value *jsonValue = json_parse_string(json); if (!jsonValue) { corto_seterr("invalid JSON '%s'", json); goto error; } corto_type type = corto_value_getType(v); if (type->kind == CORTO_PRIMITIVE) { JSON_Object* jsonObj = json_value_get_object(jsonValue); if (!jsonObj) { corto_seterr("json: invalid JSON for primitive value '%s'", json); goto error; } JSON_Value *jsonValue = json_object_get_value(jsonObj, "value"); if (!jsonValue) { corto_seterr("json: missing 'value' field for primitive value '%s'", json); goto error; } } if (json_deserialize_from_JSON_Value(v, jsonValue)) { goto error; } if (json != s) { corto_dealloc(json); } return 0; error: if (json != s) { corto_dealloc(json); } if (jsonValue) { json_value_free(jsonValue); } return -1; }
/* Convert package identifier to filename */ static corto_string corto_packageToFile(corto_string package) { corto_string path; #ifdef CORTO_REDIS corto_asprintf(&path, "lib%s.so", package[0] == '/' ? package + 1 : package); char ch, *ptr; for (ptr = path; (ch = *ptr); ptr++) { if (ch == '/') *ptr = '_'; } #else corto_string fileName; int fileNameLength; path = malloc(strlen(package) * 2 + strlen("/lib.so") + 1); fileName = corto_replaceColons(path, package); fileNameLength = strlen(fileName); memcpy(fileName + fileNameLength, "/lib", 4); memcpy(fileName + fileNameLength + 4, fileName, fileNameLength); memcpy(fileName + fileNameLength * 2 + 4, ".so\0", 4); #endif return path; }
influxdb_mount this, corto_query *query); corto_string influxdb_mount_query_builder_soffset( influxdb_mount this, corto_query *query); corto_string influxdb_mount_query_builder_url( influxdb_mount this) { corto_string user = ""; corto_string pass = ""; bool userFree = false; bool passFree = false; corto_string rp = corto_asprintf("&rp=%s", influxdb_mount_retention_policy(this)); if (this->username) { user = corto_asprintf("&u=%s", this->username); userFree = true; } if (this->password) { pass = corto_asprintf("&p=%s", this->password); passFree = true; } corto_string url = corto_asprintf("%s:%d/write?db=%s%s%s%s", this->host, this->port, this->db, rp, user, pass); corto_dealloc(rp);