diff --git a/src/libvirt_xenconfig.syms b/src/libvirt_xenconfig.syms index 603f1ce420489637fe6cea3cd2465ea1f06df755..ddaecd68509005cc5699dc94fb0f4bf389486f0a 100644 --- a/src/libvirt_xenconfig.syms +++ b/src/libvirt_xenconfig.syms @@ -5,7 +5,6 @@ # xenconfig/xen_sxpr.h xenGetDomIdFromSxpr; xenGetDomIdFromSxprString; -xenParseSxprChar; # xenconfig/xen_xm.h xenFormatXM; diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index a647088e06f1c9e0b70f65eed314e5ec5cf98f7c..7eb52c8c84bba028e0adbe2fa1b5c12d60adc547 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -763,6 +763,152 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def) } +/** + * xenParseSxprChar: + * @value: A string describing a character device. + * @tty: the console pty path + * + * Parse the xend S-expression for description of a character device. + * + * Returns a character device object or NULL in case of failure. + */ +static virDomainChrDefPtr +xenParseSxprChar(const char *value, + const char *tty) +{ + const char *prefix; + char *tmp; + virDomainChrDefPtr def; + + if (!(def = virDomainChrDefNew(NULL))) + return NULL; + + prefix = value; + + if (value[0] == '/') { + def->source->type = VIR_DOMAIN_CHR_TYPE_DEV; + if (VIR_STRDUP(def->source->data.file.path, value) < 0) + goto error; + } else { + if ((tmp = strchr(value, ':')) != NULL) { + *tmp = '\0'; + value = tmp + 1; + } + + if (STRPREFIX(prefix, "telnet")) { + def->source->type = VIR_DOMAIN_CHR_TYPE_TCP; + def->source->data.tcp.protocol = VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET; + } else { + if ((def->source->type = virDomainChrTypeFromString(prefix)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unknown chr device type '%s'"), prefix); + goto error; + } + } + } + + switch (def->source->type) { + case VIR_DOMAIN_CHR_TYPE_PTY: + if (VIR_STRDUP(def->source->data.file.path, tty) < 0) + goto error; + break; + + case VIR_DOMAIN_CHR_TYPE_FILE: + case VIR_DOMAIN_CHR_TYPE_PIPE: + if (VIR_STRDUP(def->source->data.file.path, value) < 0) + goto error; + break; + + case VIR_DOMAIN_CHR_TYPE_TCP: + { + const char *offset = strchr(value, ':'); + const char *offset2; + + if (offset == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("malformed char device string")); + goto error; + } + + if (offset != value && + VIR_STRNDUP(def->source->data.tcp.host, value, offset - value) < 0) + goto error; + + offset2 = strchr(offset, ','); + offset++; + if (VIR_STRNDUP(def->source->data.tcp.service, offset, + offset2 ? offset2 - offset : -1) < 0) + goto error; + + if (offset2 && strstr(offset2, ",server")) + def->source->data.tcp.listen = true; + } + break; + + case VIR_DOMAIN_CHR_TYPE_UDP: + { + const char *offset = strchr(value, ':'); + const char *offset2, *offset3; + + if (offset == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("malformed char device string")); + goto error; + } + + if (offset != value && + VIR_STRNDUP(def->source->data.udp.connectHost, value, offset - value) < 0) + goto error; + + offset2 = strchr(offset, '@'); + if (offset2 != NULL) { + if (VIR_STRNDUP(def->source->data.udp.connectService, + offset + 1, offset2 - offset - 1) < 0) + goto error; + + offset3 = strchr(offset2, ':'); + if (offset3 == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("malformed char device string")); + goto error; + } + + if (offset3 > (offset2 + 1) && + VIR_STRNDUP(def->source->data.udp.bindHost, + offset2 + 1, offset3 - offset2 - 1) < 0) + goto error; + + if (VIR_STRDUP(def->source->data.udp.bindService, offset3 + 1) < 0) + goto error; + } else { + if (VIR_STRDUP(def->source->data.udp.connectService, offset + 1) < 0) + goto error; + } + } + break; + + case VIR_DOMAIN_CHR_TYPE_UNIX: + { + const char *offset = strchr(value, ','); + if (VIR_STRNDUP(def->source->data.nix.path, value, + offset ? offset - value : -1) < 0) + goto error; + + if (offset != NULL && + strstr(offset, ",server") != NULL) + def->source->data.nix.listen = true; + } + break; + } + + return def; + + error: + virDomainChrDefFree(def); + return NULL; +} + + static int xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat) { diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index 953909e7b422678f6463f30c38d8d3a7a7c8288a..f087464c4d0bf62917f131573e1838e449d9efbf 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -62,149 +62,3 @@ int xenGetDomIdFromSxpr(const struct sexpr *root, int *id) *id = tmp ? sexpr_int(root, "domain/domid") : -1; return 0; } - - -/** - * xenParseSxprChar: - * @value: A string describing a character device. - * @tty: the console pty path - * - * Parse the xend S-expression for description of a character device. - * - * Returns a character device object or NULL in case of failure. - */ -virDomainChrDefPtr -xenParseSxprChar(const char *value, - const char *tty) -{ - const char *prefix; - char *tmp; - virDomainChrDefPtr def; - - if (!(def = virDomainChrDefNew(NULL))) - return NULL; - - prefix = value; - - if (value[0] == '/') { - def->source->type = VIR_DOMAIN_CHR_TYPE_DEV; - if (VIR_STRDUP(def->source->data.file.path, value) < 0) - goto error; - } else { - if ((tmp = strchr(value, ':')) != NULL) { - *tmp = '\0'; - value = tmp + 1; - } - - if (STRPREFIX(prefix, "telnet")) { - def->source->type = VIR_DOMAIN_CHR_TYPE_TCP; - def->source->data.tcp.protocol = VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET; - } else { - if ((def->source->type = virDomainChrTypeFromString(prefix)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown chr device type '%s'"), prefix); - goto error; - } - } - } - - switch (def->source->type) { - case VIR_DOMAIN_CHR_TYPE_PTY: - if (VIR_STRDUP(def->source->data.file.path, tty) < 0) - goto error; - break; - - case VIR_DOMAIN_CHR_TYPE_FILE: - case VIR_DOMAIN_CHR_TYPE_PIPE: - if (VIR_STRDUP(def->source->data.file.path, value) < 0) - goto error; - break; - - case VIR_DOMAIN_CHR_TYPE_TCP: - { - const char *offset = strchr(value, ':'); - const char *offset2; - - if (offset == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("malformed char device string")); - goto error; - } - - if (offset != value && - VIR_STRNDUP(def->source->data.tcp.host, value, offset - value) < 0) - goto error; - - offset2 = strchr(offset, ','); - offset++; - if (VIR_STRNDUP(def->source->data.tcp.service, offset, - offset2 ? offset2 - offset : -1) < 0) - goto error; - - if (offset2 && strstr(offset2, ",server")) - def->source->data.tcp.listen = true; - } - break; - - case VIR_DOMAIN_CHR_TYPE_UDP: - { - const char *offset = strchr(value, ':'); - const char *offset2, *offset3; - - if (offset == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("malformed char device string")); - goto error; - } - - if (offset != value && - VIR_STRNDUP(def->source->data.udp.connectHost, value, offset - value) < 0) - goto error; - - offset2 = strchr(offset, '@'); - if (offset2 != NULL) { - if (VIR_STRNDUP(def->source->data.udp.connectService, - offset + 1, offset2 - offset - 1) < 0) - goto error; - - offset3 = strchr(offset2, ':'); - if (offset3 == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("malformed char device string")); - goto error; - } - - if (offset3 > (offset2 + 1) && - VIR_STRNDUP(def->source->data.udp.bindHost, - offset2 + 1, offset3 - offset2 - 1) < 0) - goto error; - - if (VIR_STRDUP(def->source->data.udp.bindService, offset3 + 1) < 0) - goto error; - } else { - if (VIR_STRDUP(def->source->data.udp.connectService, offset + 1) < 0) - goto error; - } - } - break; - - case VIR_DOMAIN_CHR_TYPE_UNIX: - { - const char *offset = strchr(value, ','); - if (VIR_STRNDUP(def->source->data.nix.path, value, - offset ? offset - value : -1) < 0) - goto error; - - if (offset != NULL && - strstr(offset, ",server") != NULL) - def->source->data.nix.listen = true; - } - break; - } - - return def; - - error: - virDomainChrDefFree(def); - return NULL; -} diff --git a/src/xenconfig/xen_sxpr.h b/src/xenconfig/xen_sxpr.h index f7112bc6eefbda625066c95f2684925539f89336..ad6e293e5794dc9b783c521fd815abec2c8f9044 100644 --- a/src/xenconfig/xen_sxpr.h +++ b/src/xenconfig/xen_sxpr.h @@ -30,5 +30,3 @@ /* helper functions to get the dom id from a sexpr */ int xenGetDomIdFromSxprString(const char *sexpr, int *id); int xenGetDomIdFromSxpr(const struct sexpr *root, int *id); - -virDomainChrDefPtr xenParseSxprChar(const char *value, const char *tty);