libmm-glib,3gpp-profile: new print() method
Can be used right away in the mmcli output generation logic.
This commit is contained in:
@@ -938,72 +938,17 @@ static void
|
||||
build_profile_human (GPtrArray *array,
|
||||
MM3gppProfile *profile)
|
||||
{
|
||||
const gchar *aux;
|
||||
MMBearerAllowedAuth allowed_auth;
|
||||
MMBearerIpFamily ip_type;
|
||||
MMBearerApnType apn_type;
|
||||
MMBearerAccessTypePreference access_type_preference;
|
||||
MMBearerRoamingAllowance roaming_allowance;
|
||||
MMBearerProfileSource profile_source;
|
||||
g_autoptr(GPtrArray) profile_print = NULL;
|
||||
guint i;
|
||||
|
||||
g_ptr_array_add (array, g_strdup_printf ("profile-id: %u", mm_3gpp_profile_get_profile_id (profile)));
|
||||
g_ptr_array_add (array, g_strdup_printf (" profile enabled: %s",
|
||||
mm_3gpp_profile_get_enabled (profile) ? "yes" : "no"));
|
||||
|
||||
if ((aux = mm_3gpp_profile_get_profile_name (profile)) != NULL)
|
||||
g_ptr_array_add (array, g_strdup_printf (" profile name: %s", aux));
|
||||
|
||||
if ((aux = mm_3gpp_profile_get_apn (profile)) != NULL)
|
||||
g_ptr_array_add (array, g_strdup_printf (" apn: %s", aux));
|
||||
|
||||
allowed_auth = mm_3gpp_profile_get_allowed_auth (profile);
|
||||
if (allowed_auth != MM_BEARER_ALLOWED_AUTH_NONE) {
|
||||
g_autofree gchar *allowed_auth_str = NULL;
|
||||
|
||||
allowed_auth_str = mm_bearer_allowed_auth_build_string_from_mask (allowed_auth);
|
||||
g_ptr_array_add (array, g_strdup_printf (" allowed auth: %s", allowed_auth_str));
|
||||
}
|
||||
|
||||
if ((aux = mm_3gpp_profile_get_user (profile)) != NULL)
|
||||
g_ptr_array_add (array, g_strdup_printf (" user: %s", aux));
|
||||
|
||||
if ((aux = mm_3gpp_profile_get_password (profile)) != NULL)
|
||||
g_ptr_array_add (array, g_strdup_printf (" password: %s", aux));
|
||||
|
||||
ip_type = mm_3gpp_profile_get_ip_type (profile);
|
||||
if (ip_type != MM_BEARER_IP_FAMILY_NONE) {
|
||||
g_autofree gchar *ip_type_str = NULL;
|
||||
|
||||
ip_type_str = mm_bearer_ip_family_build_string_from_mask (ip_type);
|
||||
g_ptr_array_add (array, g_strdup_printf (" ip type: %s", ip_type_str));
|
||||
}
|
||||
|
||||
apn_type = mm_3gpp_profile_get_apn_type (profile);
|
||||
if (apn_type != MM_BEARER_APN_TYPE_NONE) {
|
||||
g_autofree gchar *apn_type_str = NULL;
|
||||
|
||||
apn_type_str = mm_bearer_apn_type_build_string_from_mask (apn_type);
|
||||
g_ptr_array_add (array, g_strdup_printf (" apn type: %s", apn_type_str));
|
||||
}
|
||||
|
||||
access_type_preference = mm_3gpp_profile_get_access_type_preference (profile);
|
||||
if (access_type_preference != MM_BEARER_ACCESS_TYPE_PREFERENCE_NONE) {
|
||||
aux = mm_bearer_access_type_preference_get_string (access_type_preference);
|
||||
g_ptr_array_add (array, g_strdup_printf (" access type preference: %s", aux));
|
||||
}
|
||||
|
||||
roaming_allowance = mm_3gpp_profile_get_roaming_allowance (profile);
|
||||
if (roaming_allowance != MM_BEARER_ROAMING_ALLOWANCE_NONE) {
|
||||
g_autofree gchar *roaming_allowance_str = NULL;
|
||||
|
||||
roaming_allowance_str = mm_bearer_roaming_allowance_build_string_from_mask (roaming_allowance);
|
||||
g_ptr_array_add (array, g_strdup_printf (" roaming allowance: %s", roaming_allowance_str));
|
||||
}
|
||||
|
||||
profile_source = mm_3gpp_profile_get_profile_source (profile);
|
||||
if (profile_source != MM_BEARER_PROFILE_SOURCE_UNKNOWN) {
|
||||
aux = mm_bearer_profile_source_get_string (profile_source);
|
||||
g_ptr_array_add (array, g_strdup_printf (" profile source: %s", aux));
|
||||
profile_print = mm_3gpp_profile_print (profile, TRUE);
|
||||
mm_common_str_array_human_keys (profile_print);
|
||||
for (i = 0; i < profile_print->len; i++) {
|
||||
/* First string is profile id always, all the remaining ones will be
|
||||
* indented some whitespaces right */
|
||||
g_ptr_array_add (array, g_strdup_printf ("%s%s",
|
||||
i == 0 ? "" : " ",
|
||||
(const gchar *)g_ptr_array_index (profile_print, i)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1011,67 +956,17 @@ static void
|
||||
build_profile_keyvalue (GPtrArray *array,
|
||||
MM3gppProfile *profile)
|
||||
{
|
||||
g_autoptr(GPtrArray) profile_print = NULL;
|
||||
guint i;
|
||||
GString *str;
|
||||
const gchar *aux;
|
||||
MMBearerAllowedAuth allowed_auth;
|
||||
MMBearerIpFamily ip_type;
|
||||
MMBearerApnType apn_type;
|
||||
MMBearerAccessTypePreference access_type_preference;
|
||||
MMBearerRoamingAllowance roaming_allowance;
|
||||
|
||||
str = g_string_new ("");
|
||||
g_string_append_printf (str, "profile-id: %u", mm_3gpp_profile_get_profile_id (profile));
|
||||
|
||||
if ((aux = mm_3gpp_profile_get_profile_name (profile)) != NULL)
|
||||
g_string_append_printf (str, ", profile-name: %s", aux);
|
||||
|
||||
if ((aux = mm_3gpp_profile_get_apn (profile)) != NULL)
|
||||
g_string_append_printf (str, ", apn: %s", aux);
|
||||
|
||||
allowed_auth = mm_3gpp_profile_get_allowed_auth (profile);
|
||||
if (allowed_auth != MM_BEARER_ALLOWED_AUTH_NONE) {
|
||||
g_autofree gchar *allowed_auth_str = NULL;
|
||||
|
||||
allowed_auth_str = mm_bearer_allowed_auth_build_string_from_mask (allowed_auth);
|
||||
g_string_append_printf (str, ", allowed-auth: %s", allowed_auth_str);
|
||||
profile_print = mm_3gpp_profile_print (profile, TRUE);
|
||||
for (i = 0; i < profile_print->len; i++) {
|
||||
g_string_append_printf (str, "%s%s",
|
||||
i == 0 ? "" : ", ",
|
||||
(const gchar *)g_ptr_array_index (profile_print, i));
|
||||
}
|
||||
|
||||
if ((aux = mm_3gpp_profile_get_user (profile)) != NULL)
|
||||
g_string_append_printf (str, ", user: %s", aux);
|
||||
|
||||
if ((aux = mm_3gpp_profile_get_password (profile)) != NULL)
|
||||
g_string_append_printf (str, ", password: %s", aux);
|
||||
|
||||
ip_type = mm_3gpp_profile_get_ip_type (profile);
|
||||
if (ip_type != MM_BEARER_IP_FAMILY_NONE) {
|
||||
g_autofree gchar *ip_type_str = NULL;
|
||||
|
||||
ip_type_str = mm_bearer_ip_family_build_string_from_mask (ip_type);
|
||||
g_string_append_printf (str, ", ip-type: %s", ip_type_str);
|
||||
}
|
||||
|
||||
apn_type = mm_3gpp_profile_get_apn_type (profile);
|
||||
if (apn_type != MM_BEARER_APN_TYPE_NONE) {
|
||||
g_autofree gchar *apn_type_str = NULL;
|
||||
|
||||
apn_type_str = mm_bearer_apn_type_build_string_from_mask (apn_type);
|
||||
g_string_append_printf (str, ", apn-type: %s", apn_type_str);
|
||||
}
|
||||
|
||||
access_type_preference = mm_3gpp_profile_get_access_type_preference (profile);
|
||||
if (access_type_preference != MM_BEARER_ACCESS_TYPE_PREFERENCE_NONE) {
|
||||
aux = mm_bearer_access_type_preference_get_string (access_type_preference);
|
||||
g_string_append_printf (str, ", access-type-preference: %s", aux);
|
||||
}
|
||||
|
||||
roaming_allowance = mm_3gpp_profile_get_roaming_allowance (profile);
|
||||
if (roaming_allowance != MM_BEARER_ROAMING_ALLOWANCE_NONE) {
|
||||
g_autofree gchar *roaming_allowance_str = NULL;
|
||||
|
||||
roaming_allowance_str = mm_bearer_roaming_allowance_build_string_from_mask (roaming_allowance);
|
||||
g_string_append_printf (str, ", roaming-allowance: %s", roaming_allowance_str);
|
||||
}
|
||||
|
||||
g_ptr_array_add (array, g_string_free (str, FALSE));
|
||||
}
|
||||
|
||||
|
@@ -17,11 +17,13 @@
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2021 Aleksander Morgado <aleksander@aleksander.es>
|
||||
* Copyright (C) 2021-2022 Aleksander Morgado <aleksander@aleksander.es>
|
||||
* Copyright (C) 2022 Google, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "mm-enums-types.h"
|
||||
#include "mm-errors-types.h"
|
||||
#include "mm-common-helpers.h"
|
||||
#include "mm-3gpp-profile.h"
|
||||
@@ -938,6 +940,64 @@ mm_3gpp_profile_new_from_dictionary (GVariant *dictionary,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* mm_3gpp_profile_print: (skip)
|
||||
*/
|
||||
GPtrArray *
|
||||
mm_3gpp_profile_print (MM3gppProfile *self,
|
||||
gboolean show_personal_info)
|
||||
{
|
||||
GPtrArray *array;
|
||||
g_autofree gchar *ip_type_str = NULL;
|
||||
g_autofree gchar *apn_type_str = NULL;
|
||||
g_autofree gchar *roaming_allowance_str = NULL;
|
||||
g_autofree gchar *allowed_auth_str = NULL;
|
||||
const gchar *aux;
|
||||
|
||||
array = g_ptr_array_new_with_free_func ((GDestroyNotify)g_free);
|
||||
if (self->priv->profile_id != MM_3GPP_PROFILE_ID_UNKNOWN)
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_ID ": %d", self->priv->profile_id));
|
||||
if (self->priv->profile_name)
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_NAME ": %s", self->priv->profile_name));
|
||||
if (self->priv->enabled_set) {
|
||||
aux = mm_common_str_boolean (self->priv->enabled);
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_ENABLED ": %s", aux));
|
||||
}
|
||||
if (self->priv->apn)
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_APN ": %s", self->priv->apn));
|
||||
if (self->priv->ip_type != MM_BEARER_IP_FAMILY_NONE) {
|
||||
ip_type_str = mm_bearer_ip_family_build_string_from_mask (self->priv->ip_type);
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_IP_TYPE ": %s", ip_type_str));
|
||||
}
|
||||
if (self->priv->apn_type != MM_BEARER_APN_TYPE_NONE) {
|
||||
apn_type_str = mm_bearer_apn_type_build_string_from_mask (self->priv->apn_type);
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_APN_TYPE ": %s", apn_type_str));
|
||||
}
|
||||
if (self->priv->access_type_preference != MM_BEARER_ACCESS_TYPE_PREFERENCE_NONE) {
|
||||
aux = mm_bearer_access_type_preference_get_string (self->priv->access_type_preference);
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_ACCESS_TYPE_PREFERENCE ": %s", aux));
|
||||
}
|
||||
if (self->priv->roaming_allowance != MM_BEARER_ROAMING_ALLOWANCE_NONE) {
|
||||
roaming_allowance_str = mm_bearer_roaming_allowance_build_string_from_mask (self->priv->roaming_allowance);
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_ROAMING_ALLOWANCE ": %s", roaming_allowance_str));
|
||||
}
|
||||
if (self->priv->profile_source != MM_BEARER_PROFILE_SOURCE_UNKNOWN) {
|
||||
aux = mm_bearer_profile_source_get_string (self->priv->profile_source);
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_SOURCE ": %s", aux));
|
||||
}
|
||||
if (self->priv->allowed_auth != MM_BEARER_ALLOWED_AUTH_NONE) {
|
||||
allowed_auth_str = mm_bearer_allowed_auth_build_string_from_mask (self->priv->allowed_auth);
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_ALLOWED_AUTH ": %s", allowed_auth_str));
|
||||
}
|
||||
if (self->priv->user)
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_USER ": %s", mm_common_str_personal_info (self->priv->user, show_personal_info)));
|
||||
if (self->priv->password)
|
||||
g_ptr_array_add (array, g_strdup_printf (PROPERTY_PASSWORD ": %s", mm_common_str_personal_info (self->priv->password, show_personal_info)));
|
||||
return array;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* mm_3gpp_profile_new:
|
||||
*
|
||||
|
@@ -17,7 +17,8 @@
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2021 Aleksander Morgado <aleksander@aleksander.es>
|
||||
* Copyright (C) 2021-2022 Aleksander Morgado <aleksander@aleksander.es>
|
||||
* Copyright (C) 2022 Google, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_3GPP_PROFILE_H
|
||||
@@ -151,6 +152,8 @@ gboolean mm_3gpp_profile_cmp (MM3gppProfile *a,
|
||||
GEqualFunc cmp_apn,
|
||||
MM3gppProfileCmpFlags flags);
|
||||
|
||||
GPtrArray *mm_3gpp_profile_print (MM3gppProfile *self,
|
||||
gboolean show_personal_info);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
Reference in New Issue
Block a user