[Commits] utils.c 1.11 1.12 utils.h 1.10 1.11

miras at claws-mail.org miras at claws-mail.org
Sat Dec 17 03:52:25 CET 2011


Update of /home/claws-mail/contacts/src
In directory claws-mail:/tmp/cvs-serv16939/src

Modified Files:
	utils.c utils.h 
Log Message:
2011-12-17 [mir]	0.6.0cvs48

	* plugins/ldap/ldap-plugin.c
	* src/utils.c
	* src/utils.h
	    More user friendly error message when adding
	    and updating contacts.
	    Move some useful methods to utils.{c,h}.

Index: utils.c
===================================================================
RCS file: /home/claws-mail/contacts/src/utils.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- utils.c	13 Dec 2011 10:56:40 -0000	1.11
+++ utils.c	17 Dec 2011 02:52:22 -0000	1.12
@@ -2111,4 +2111,34 @@
 	g_object_unref(pl);
 	
 	return base64;
-}
\ No newline at end of file
+}
+
+const gchar* native2ldap(const gchar* attr) {
+	if (strcasecmp(attr, "email") == 0)
+		return "mail";
+	else if (strcasecmp(attr, "first-name") == 0)
+		return "givenName";
+	else if (strcasecmp(attr, "last-name") == 0)
+		return "sn";
+	else if (strcasecmp(attr, "nick-name") == 0)
+		return "displayName";
+	else if (strcasecmp(attr, "image") == 0)
+		return "jpegPhoto";
+	else
+		return attr;
+}
+
+const gchar* ldap2native(const gchar* attr) {
+	if (strcasecmp(attr, "mail") == 0)
+		return "email";
+	else if (strcasecmp(attr, "givenName") == 0)
+		return "first-name";
+	else if (strcasecmp(attr, "sn") == 0)
+		return "last-name";
+	else if (strcasecmp(attr, "displayName") == 0)
+		return "nick-name";
+	else if (strcasecmp(attr, "jpegPhoto") == 0)
+		return "image";
+	else
+		return attr;
+}

Index: utils.h
===================================================================
RCS file: /home/claws-mail/contacts/src/utils.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- utils.h	13 Dec 2011 10:56:40 -0000	1.10
+++ utils.h	17 Dec 2011 02:52:22 -0000	1.11
@@ -46,9 +46,63 @@
 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
     #define ___FUNC___ __func__
 #else
-    #define ___FUNC___ "Missing function"
+    #define ___FUNC___ (const char *) "Missing function"
+#endif
+
+/* stolen from claws-mail:-) */
+/* from NetworkManager */
+#if (defined(HAVE_BACKTRACE) && !defined(__FreeBSD__))
+#include <execinfo.h>
+#include <stdlib.h>
+#define print_backtrace()                                               \
+G_STMT_START                                                            \
+{                                                                       \
+        void *_call_stack[512];                                         \
+        int  _call_stack_size;                                          \
+        char **_symbols;                                                \
+        _call_stack_size = backtrace (_call_stack,                      \
+                                      G_N_ELEMENTS (_call_stack));      \
+        _symbols = backtrace_symbols (_call_stack, _call_stack_size);   \
+        if (_symbols != NULL)                                           \
+        {                                                               \
+                int _i;                                                 \
+                _i = 0;                                                 \
+                g_print ("traceback:\n");                               \
+                while (_i < _call_stack_size)                           \
+                {                                                       \
+                        g_print ("%d:\t%s\n", _i, _symbols[_i]);        \
+                        _i++;                                           \
+                }                                                       \
+                free (_symbols);                                        \
+        }                                                               \
+}                                                                       \
+G_STMT_END
+#else
+#define print_backtrace()                                               \
+G_STMT_START                                                            \
+{                                                                       \
+}                                                                       \
+G_STMT_END
 #endif
 
+#define cm_return_val_if_fail(expr,val) G_STMT_START {                  \
+        if (!(expr)) {                                                  \
+                g_print("%s:%d Condition %s failed\n", __FILE__, __LINE__, #expr);\
+                print_backtrace();                                      \
+                g_print("\n");                                          \
+                return val;                                             \
+        }                                                               \
+} G_STMT_END
+
+#define cm_return_if_fail(expr) G_STMT_START {                          \
+        if (!(expr)) {                                                  \
+                g_print("%s:%d Condition %s failed\n", __FILE__, __LINE__, #expr);\
+                print_backtrace();                                      \
+                g_print("\n");                                          \
+                return;                                                 \
+        }                                                               \
+} G_STMT_END
+
 #define debug_print \
 	debug_print_real("%s:%d:[%s]: ", debug_srcname(__FILE__), __LINE__, ___FUNC___), \
 	debug_print_real
@@ -169,6 +223,8 @@
 gchar* get_domain_name(void);
 gchar* base64_pixbuf_to_jpeg(gchar* base64_png, gsize* length);
 gchar* jpeg_to_png_base64(guchar* jpeg, gsize length);
+const gchar* native2ldap(const gchar* attr);
+const gchar* ldap2native(const gchar* attr);
 
 G_END_DECLS
 



More information about the Commits mailing list