static char * testFilterXML(char *xml) { virBuffer buf = VIR_BUFFER_INITIALIZER; char **xmlLines = NULL; char **xmlLine; char *ret = NULL; if (!(xmlLines = virStringSplit(xml, "\n", 0))) { VIR_FREE(xml); goto cleanup; } VIR_FREE(xml); for (xmlLine = xmlLines; *xmlLine; xmlLine++) { if (regexec(testSnapshotXMLVariableLineRegex, *xmlLine, 0, NULL, 0) == 0) continue; virBufferStrcat(&buf, *xmlLine, "\n", NULL); } if (virBufferCheckError(&buf) < 0) goto cleanup; ret = virBufferContentAndReset(&buf); cleanup: virBufferFreeAndReset(&buf); virStringFreeList(xmlLines); return ret; }
char * qparam_get_query (const struct qparam_set *ps) { virBuffer buf = VIR_BUFFER_INITIALIZER; int i, amp = 0; for (i = 0; i < ps->n; ++i) { if (!ps->p[i].ignore) { if (amp) virBufferAddChar (&buf, '&'); virBufferStrcat (&buf, ps->p[i].name, "=", NULL); virBufferURIEncodeString (&buf, ps->p[i].value); amp = 1; } } if (virBufferError(&buf)) { virBufferFreeAndReset(&buf); virReportOOMError(); return NULL; } return virBufferContentAndReset(&buf); }
static int testQEMUSchemaValidateObjectMember(const char *key, virJSONValuePtr value, void *opaque) { struct testQEMUSchemaValidateObjectMemberData *data = opaque; virJSONValuePtr keymember = NULL; const char *keytype; virJSONValuePtr keyschema = NULL; int ret = -1; virBufferStrcat(data->debug, key, ": ", NULL); /* lookup 'member' entry for key */ if (!(keymember = testQEMUSchemaStealObjectMemberByName(key, data->rootmembers))) { virBufferAddLit(data->debug, "ERROR: attribute not in schema"); goto cleanup; } /* lookup schema entry for keytype */ if (!(keytype = virJSONValueObjectGetString(keymember, "type")) || !(keyschema = virHashLookup(data->schema, keytype))) { virBufferAsprintf(data->debug, "ERROR: can't find schema for type '%s'", NULLSTR(keytype)); ret = -2; goto cleanup; } /* recurse */ ret = testQEMUSchemaValidateRecurse(value, keyschema, data->schema, data->debug); cleanup: virBufferAddLit(data->debug, "\n"); virJSONValueFree(keymember); return ret; }
static char * xenFormatXLDiskSrcNet(virStorageSourcePtr src) { char *ret = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; size_t i; switch ((virStorageNetProtocol) src->protocol) { case VIR_STORAGE_NET_PROTOCOL_NBD: case VIR_STORAGE_NET_PROTOCOL_HTTP: case VIR_STORAGE_NET_PROTOCOL_HTTPS: case VIR_STORAGE_NET_PROTOCOL_FTP: case VIR_STORAGE_NET_PROTOCOL_FTPS: case VIR_STORAGE_NET_PROTOCOL_TFTP: case VIR_STORAGE_NET_PROTOCOL_ISCSI: case VIR_STORAGE_NET_PROTOCOL_GLUSTER: case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: case VIR_STORAGE_NET_PROTOCOL_LAST: case VIR_STORAGE_NET_PROTOCOL_NONE: virReportError(VIR_ERR_NO_SUPPORT, _("Unsupported network block protocol '%s'"), virStorageNetProtocolTypeToString(src->protocol)); goto cleanup; case VIR_STORAGE_NET_PROTOCOL_RBD: if (strchr(src->path, ':')) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("':' not allowed in RBD source volume name '%s'"), src->path); goto cleanup; } virBufferStrcat(&buf, "rbd:", src->path, NULL); virBufferAddLit(&buf, ":auth_supported=none"); if (src->nhosts > 0) { virBufferAddLit(&buf, ":mon_host="); for (i = 0; i < src->nhosts; i++) { if (i) virBufferAddLit(&buf, "\\\\;"); /* assume host containing : is ipv6 */ if (strchr(src->hosts[i].name, ':')) virBufferEscape(&buf, '\\', ":", "[%s]", src->hosts[i].name); else virBufferAsprintf(&buf, "%s", src->hosts[i].name); if (src->hosts[i].port) virBufferAsprintf(&buf, "\\\\:%s", src->hosts[i].port); } } if (virBufferCheckError(&buf) < 0) goto cleanup; ret = virBufferContentAndReset(&buf); break; } cleanup: virBufferFreeAndReset(&buf); return ret; }