]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: typedparam: Move and unexport virTypedParameterAssignFromStr
authorPeter Krempa <pkrempa@redhat.com>
Tue, 17 Sep 2019 17:45:39 +0000 (19:45 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 25 Sep 2019 11:02:48 +0000 (13:02 +0200)
The function is only used as a helper in virTypedParamsAddFromString.
Make it static and move it to virtypedparam-public.c.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/virtypedparam-public.c
src/util/virtypedparam.c
src/util/virtypedparam.h

index 39812227aa22177ffd33f33b51d34ff328337676..8af9e7c95e6da38aad484e7c768e29b09864b737 100644 (file)
@@ -3229,7 +3229,6 @@ virTPMSwtpmSetupFeatureTypeFromString;
 
 # util/virtypedparam.h
 virTypedParameterAssign;
-virTypedParameterAssignFromStr;
 virTypedParameterToString;
 virTypedParameterTypeFromString;
 virTypedParameterTypeToString;
index 585e851f388756ff40dad4fa4696e72f6f80428c..fb7f178c6c17b7a6e7ef9233372414037c2ec110 100644 (file)
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
+/* Assign name, type, and convert the argument from a const string.
+ * In case of a string, the string is copied.
+ * Return 0 on success, -1 after an error message on failure.  */
+static int
+virTypedParameterAssignFromStr(virTypedParameterPtr param,
+                               const char *name,
+                               int type,
+                               const char *val)
+{
+    int ret = -1;
+
+    if (!val) {
+        virReportError(VIR_ERR_INVALID_ARG, _("NULL value for field '%s'"),
+                       name);
+        goto cleanup;
+    }
+
+    if (virStrcpyStatic(param->field, name) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
+                       name);
+        goto cleanup;
+    }
+
+    param->type = type;
+    switch (type) {
+    case VIR_TYPED_PARAM_INT:
+        if (virStrToLong_i(val, NULL, 10, &param->value.i) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': expected int"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_UINT:
+        if (virStrToLong_ui(val, NULL, 10, &param->value.ui) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': "
+                             "expected unsigned int"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_LLONG:
+        if (virStrToLong_ll(val, NULL, 10, &param->value.l) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': "
+                             "expected long long"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_ULLONG:
+        if (virStrToLong_ull(val, NULL, 10, &param->value.ul) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': "
+                             "expected unsigned long long"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_DOUBLE:
+        if (virStrToDouble(val, NULL, &param->value.d) < 0) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid value for field '%s': "
+                             "expected double"),
+                           name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_BOOLEAN:
+        if (STRCASEEQ(val, "true") || STREQ(val, "1")) {
+            param->value.b = true;
+        } else if (STRCASEEQ(val, "false") || STREQ(val, "0")) {
+            param->value.b = false;
+        } else {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("Invalid boolean value for field '%s'"), name);
+            goto cleanup;
+        }
+        break;
+    case VIR_TYPED_PARAM_STRING:
+        if (VIR_STRDUP(param->value.s, val) < 0)
+            goto cleanup;
+        break;
+    default:
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected type %d for field %s"), type, name);
+        goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    return ret;
+}
+
 /* The following APIs are public and their signature may never change. */
 
 /**
index acf8c396021b7a8064b5f86b912abdfc6a7e70e8..d9f8203796c1b3af6f51c6ad6791aaeb2589f7eb 100644 (file)
@@ -260,99 +260,6 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name,
     return ret;
 }
 
-/* Assign name, type, and convert the argument from a const string.
- * In case of a string, the string is copied.
- * Return 0 on success, -1 after an error message on failure.  */
-int
-virTypedParameterAssignFromStr(virTypedParameterPtr param, const char *name,
-                               int type, const char *val)
-{
-    int ret = -1;
-
-    if (!val) {
-        virReportError(VIR_ERR_INVALID_ARG, _("NULL value for field '%s'"),
-                       name);
-        goto cleanup;
-    }
-
-    if (virStrcpyStatic(param->field, name) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
-                       name);
-        goto cleanup;
-    }
-
-    param->type = type;
-    switch (type) {
-    case VIR_TYPED_PARAM_INT:
-        if (virStrToLong_i(val, NULL, 10, &param->value.i) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': expected int"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_UINT:
-        if (virStrToLong_ui(val, NULL, 10, &param->value.ui) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': "
-                             "expected unsigned int"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_LLONG:
-        if (virStrToLong_ll(val, NULL, 10, &param->value.l) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': "
-                             "expected long long"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_ULLONG:
-        if (virStrToLong_ull(val, NULL, 10, &param->value.ul) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': "
-                             "expected unsigned long long"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_DOUBLE:
-        if (virStrToDouble(val, NULL, &param->value.d) < 0) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid value for field '%s': "
-                             "expected double"),
-                           name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_BOOLEAN:
-        if (STRCASEEQ(val, "true") || STREQ(val, "1")) {
-            param->value.b = true;
-        } else if (STRCASEEQ(val, "false") || STREQ(val, "0")) {
-            param->value.b = false;
-        } else {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("Invalid boolean value for field '%s'"), name);
-            goto cleanup;
-        }
-        break;
-    case VIR_TYPED_PARAM_STRING:
-        if (VIR_STRDUP(param->value.s, val) < 0)
-            goto cleanup;
-        break;
-    default:
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("unexpected type %d for field %s"), type, name);
-        goto cleanup;
-    }
-
-    ret = 0;
- cleanup:
-    return ret;
-}
-
 
 /**
  * virTypedParamsReplaceString:
index f9d22b24fb3faa733c02bcf52b3c4629d5598233..cad6953f5d686b4e4ea60724f24d0ee05d51b6d2 100644 (file)
@@ -85,12 +85,6 @@ int virTypedParameterAssign(virTypedParameterPtr param, const char *name,
                             int type, /* TYPE arg */ ...)
     ATTRIBUTE_RETURN_CHECK;
 
-int virTypedParameterAssignFromStr(virTypedParameterPtr param,
-                                   const char *name,
-                                   int type,
-                                   const char *val)
-    ATTRIBUTE_RETURN_CHECK;
-
 int virTypedParamsReplaceString(virTypedParameterPtr *params,
                                 int *nparams,
                                 const char *name,