418
esxUtil_GetConfigString(virConfPtr conf, const char *name, char **string,
421
virConfValuePtr value;
424
value = virConfGetValue(conf, name);
431
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
432
_("Missing essential config entry '%s'"), name);
436
if (value->type != VIR_CONF_STRING) {
437
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
438
_("Config entry '%s' must be a string"), name);
442
if (value->str == NULL) {
447
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
448
_("Missing essential config entry '%s'"), name);
452
*string = strdup(value->str);
454
if (*string == NULL) {
465
esxUtil_GetConfigUUID(virConfPtr conf, const char *name, unsigned char *uuid,
468
virConfValuePtr value;
470
value = virConfGetValue(conf, name);
476
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
477
_("Missing essential config entry '%s'"), name);
482
if (value->type != VIR_CONF_STRING) {
483
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
484
_("Config entry '%s' must be a string"), name);
488
if (value->str == NULL) {
492
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
493
_("Missing essential config entry '%s'"), name);
498
if (virUUIDParse(value->str, uuid) < 0) {
499
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
500
_("Could not parse UUID from string '%s'"), value->str);
510
esxUtil_GetConfigLong(virConfPtr conf, const char *name, long long *number,
511
long long default_, bool optional)
513
virConfValuePtr value;
516
value = virConfGetValue(conf, name);
522
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
523
_("Missing essential config entry '%s'"), name);
528
if (value->type == VIR_CONF_STRING) {
529
if (value->str == NULL) {
533
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
534
_("Missing essential config entry '%s'"), name);
539
if (STREQ(value->str, "unlimited")) {
541
} else if (virStrToLong_ll(value->str, NULL, 10, number) < 0) {
542
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
543
_("Config entry '%s' must represent an integer value"),
548
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
549
_("Config entry '%s' must be a string"), name);
559
esxUtil_GetConfigBoolean(virConfPtr conf, const char *name, bool *boolean_,
560
bool default_, bool optional)
562
virConfValuePtr value;
564
*boolean_ = default_;
565
value = virConfGetValue(conf, name);
571
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
572
_("Missing essential config entry '%s'"), name);
577
if (value->type == VIR_CONF_STRING) {
578
if (value->str == NULL) {
582
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
583
_("Missing essential config entry '%s'"), name);
588
if (STRCASEEQ(value->str, "true")) {
590
} else if (STRCASEEQ(value->str, "false")) {
593
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
594
_("Config entry '%s' must represent a boolean value "
595
"(true|false)"), name);
599
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
600
_("Config entry '%s' must be a string"), name);
610
418
esxUtil_ReformatUuid(const char *input, char *output)
612
420
unsigned char uuid[VIR_UUID_BUFLEN];
629
esxUtil_EscapeHex(const char *string, char escape, const char *special)
631
char *escaped = NULL;
632
size_t length = 1; /* 1 byte for termination */
633
const char *tmp1 = string;
636
/* Calculate length of escaped string */
637
while (*tmp1 != '\0') {
638
if (*tmp1 == escape || strspn(tmp1, special) > 0) {
646
if (VIR_ALLOC_N(escaped, length) < 0) {
651
tmp1 = string; /* reading from this one */
652
tmp2 = escaped; /* writing to this one */
654
/* Escape to 'cXX' where c is the escape char and X is a hex digit */
655
while (*tmp1 != '\0') {
656
if (*tmp1 == escape || strspn(tmp1, special) > 0) {
659
snprintf(tmp2, 3, "%02x", (unsigned int)*tmp1);
677
esxUtil_UnescapeHex(char *string, char escape)
679
char *tmp1 = string; /* reading from this one */
680
char *tmp2 = string; /* writing to this one */
682
/* Unescape from 'cXX' where c is the escape char and X is a hex digit */
683
while (*tmp1 != '\0') {
684
if (*tmp1 == escape) {
685
if (!c_isxdigit(tmp1[1]) || !c_isxdigit(tmp1[2])) {
689
*tmp2++ = virHexToBin(tmp1[1]) * 16 + virHexToBin(tmp1[2]);
704
437
esxUtil_EscapeBase64(const char *string)
706
439
/* 'normal' characters don't get base64 encoded */
826
esxUtil_ConvertToUTF8(const char *encoding, const char *string)
829
xmlCharEncodingHandlerPtr handler;
833
handler = xmlFindCharEncodingHandler(encoding);
835
if (handler == NULL) {
836
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
837
_("libxml2 doesn't handle %s encoding"), encoding);
841
input = xmlBufferCreateStatic((char *)string, strlen(string));
842
utf8 = xmlBufferCreate();
844
if (xmlCharEncInFunc(handler, utf8, input) < 0) {
845
ESX_ERROR(VIR_ERR_INTERNAL_ERROR,
846
_("Could not convert from %s to UTF-8 encoding"), encoding);
850
result = (char *)utf8->content;
851
utf8->content = NULL;
854
xmlCharEncCloseFunc(handler);
855
xmlBufferFree(input);