[network-manager-openconnect] shared: re-import shared files



commit 319f2d8ab3ad7621fff5d1ffc263ca0ae352dda1
Author: Thomas Haller <thaller redhat com>
Date:   Wed Jul 6 13:57:14 2016 +0200

    shared: re-import shared files

 shared/nm-utils/nm-glib.h              |   31 +++++++++++++++++++++++---
 shared/nm-utils/nm-macros-internal.h   |   37 ++++++++++++++++++++++++++++++++
 shared/nm-utils/nm-vpn-plugin-macros.h |    2 +-
 3 files changed, 65 insertions(+), 5 deletions(-)
---
diff --git a/shared/nm-utils/nm-glib.h b/shared/nm-utils/nm-glib.h
index 46a8bb2..2818074 100644
--- a/shared/nm-utils/nm-glib.h
+++ b/shared/nm-utils/nm-glib.h
@@ -313,14 +313,14 @@ _g_key_file_save_to_file (GKeyFile     *key_file,
 
 #if GLIB_CHECK_VERSION (2, 36, 0)
 #define g_credentials_get_unix_pid(creds, error) \
-       G_GNUC_EXTENSION ({ \
+       ({ \
                G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
                        (g_credentials_get_unix_pid) ((creds), (error)); \
                G_GNUC_END_IGNORE_DEPRECATIONS \
        })
 #else
 #define g_credentials_get_unix_pid(creds, error) \
-       G_GNUC_EXTENSION ({ \
+       ({ \
                struct ucred *native_creds; \
                 \
                native_creds = g_credentials_get_native ((creds), G_CREDENTIALS_TYPE_LINUX_UCRED); \
@@ -357,12 +357,12 @@ _nm_g_hash_table_get_keys_as_array (GHashTable *hash_table,
 #endif
 #if !GLIB_CHECK_VERSION(2, 40, 0)
 #define g_hash_table_get_keys_as_array(hash_table, length) \
-       G_GNUC_EXTENSION ({ \
+       ({ \
                _nm_g_hash_table_get_keys_as_array (hash_table, length); \
        })
 #else
 #define g_hash_table_get_keys_as_array(hash_table, length) \
-       G_GNUC_EXTENSION ({ \
+       ({ \
                G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
                        (g_hash_table_get_keys_as_array) ((hash_table), (length)); \
                G_GNUC_END_IGNORE_DEPRECATIONS \
@@ -394,4 +394,27 @@ g_steal_pointer (gpointer pp)
   (0 ? (*(pp)) : (g_steal_pointer) (pp))
 #endif
 
+
+static inline gboolean
+_nm_g_strv_contains (const gchar * const *strv,
+                     const gchar         *str)
+{
+#if !GLIB_CHECK_VERSION(2, 44, 0)
+       g_return_val_if_fail (strv != NULL, FALSE);
+       g_return_val_if_fail (str != NULL, FALSE);
+
+       for (; *strv != NULL; strv++) {
+               if (g_str_equal (str, *strv))
+                       return TRUE;
+       }
+
+       return FALSE;
+#else
+       G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+       return g_strv_contains (strv, str);
+       G_GNUC_END_IGNORE_DEPRECATIONS
+#endif
+}
+#define g_strv_contains _nm_g_strv_contains
+
 #endif  /* __NM_GLIB_H__ */
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h
index 603689a..73075c6 100644
--- a/shared/nm-utils/nm-macros-internal.h
+++ b/shared/nm-utils/nm-macros-internal.h
@@ -51,6 +51,14 @@ _nm_auto_unset_gvalue_impl (GValue *v)
 }
 #define nm_auto_unset_gvalue nm_auto(_nm_auto_unset_gvalue_impl)
 
+static inline void
+_nm_auto_free_gstring_impl (GString **str)
+{
+       if (*str)
+               g_string_free (*str, TRUE);
+}
+#define nm_auto_free_gstring nm_auto(_nm_auto_free_gstring_impl)
+
 /********************************************************/
 
 /* http://stackoverflow.com/a/11172679 */
@@ -532,6 +540,35 @@ nm_decode_version (guint version, guint *major, guint *minor, guint *micro) {
 }
 /*****************************************************************************/
 
+/* if @str is NULL, return "(null)". Otherwise, allocate a buffer using
+ * alloca() of size @bufsize and fill it with @str. @str will be quoted with
+ * single quote, and in case @str is too long, the final quote will be '^'. */
+#define nm_strquote_a(bufsize, str) \
+       ({ \
+               G_STATIC_ASSERT ((bufsize) >= 6); \
+               const gsize _BUFSIZE = (bufsize); \
+               const char *const _s = (str); \
+               char *_r; \
+               gsize _l; \
+               gboolean _truncated; \
+               \
+               nm_assert (_BUFSIZE >= 6); \
+               \
+               if (_s) { \
+                       _l = strlen (_s) + 3; \
+                       if ((_truncated = (_BUFSIZE < _l))) \
+                               _l = _BUFSIZE; \
+                       \
+                       _r = g_alloca (_l); \
+                       _r[0] = '\''; \
+                       memcpy (&_r[1], _s, _l - 3); \
+                       _r[_l - 2] = _truncated ? '^' : '\''; \
+                       _r[_l - 1] = '\0'; \
+               } else \
+                       _r = "(null)"; \
+               _r; \
+       })
+
 #define nm_sprintf_buf(buf, format, ...) ({ \
                char * _buf = (buf); \
                \
diff --git a/shared/nm-utils/nm-vpn-plugin-macros.h b/shared/nm-utils/nm-vpn-plugin-macros.h
index f67a061..06f5b28 100644
--- a/shared/nm-utils/nm-vpn-plugin-macros.h
+++ b/shared/nm-utils/nm-vpn-plugin-macros.h
@@ -44,7 +44,7 @@ nm_utils_syslog_to_str (int syslog_level)
 /* possibly missing defines from newer libnm API. */
 
 #ifndef NM_VPN_PLUGIN_CONFIG_PROXY_PAC
-#define NM_VPN_PLUGIN_CONFIG_PROXY_PAC   "pac"
+#define NM_VPN_PLUGIN_CONFIG_PROXY_PAC "pac"
 #endif
 
 #ifndef NM_VPN_PLUGIN_IP4_CONFIG_PRESERVE_ROUTES


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]