Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/utils.c @ 1598:a087125d8fc8
Replace libjabber with loudmouth
author | franky |
---|---|
date | Sun, 11 Oct 2009 15:38:32 +0200 |
parents | e89787ee40f7 |
children | dcd5d4c75199 |
comparison
equal
deleted
inserted
replaced
1597:4f59a414217e | 1598:a087125d8fc8 |
---|---|
24 #include <stdio.h> | 24 #include <stdio.h> |
25 #include <stdlib.h> | 25 #include <stdlib.h> |
26 #include <string.h> | 26 #include <string.h> |
27 #include <stdarg.h> | 27 #include <stdarg.h> |
28 | 28 |
29 #include <glib/gprintf.h> | |
30 | |
29 /* For Cygwin (thanks go to Yitzchak Scott-Thoennes) */ | 31 /* For Cygwin (thanks go to Yitzchak Scott-Thoennes) */ |
30 #ifdef __CYGWIN__ | 32 #ifdef __CYGWIN__ |
31 # define timezonevar | 33 # define timezonevar |
32 extern long timezone; | 34 extern long timezone; |
33 #endif | 35 #endif |
43 #include "logprint.h" | 45 #include "logprint.h" |
44 | 46 |
45 static int DebugEnabled; | 47 static int DebugEnabled; |
46 static char *FName; | 48 static char *FName; |
47 | 49 |
50 // jidtodisp(jid) | |
51 // Strips the resource part from the jid | |
52 // The caller should g_free the result after use. | |
53 char *jidtodisp(const char *fjid) | |
54 { | |
55 char *ptr; | |
56 char *alias; | |
57 | |
58 alias = g_strdup(fjid); | |
59 | |
60 if ((ptr = strchr(alias, JID_RESOURCE_SEPARATOR)) != NULL) { | |
61 *ptr = 0; | |
62 } | |
63 return alias; | |
64 } | |
65 | |
66 char *compose_jid(const char *username, const char *servername, | |
67 const char *resource) | |
68 { | |
69 char *fjid; | |
70 | |
71 if (!strchr(username, JID_DOMAIN_SEPARATOR)) { | |
72 fjid = g_strdup_printf("%s%c%s%c%s", username, | |
73 JID_DOMAIN_SEPARATOR, servername, | |
74 JID_RESOURCE_SEPARATOR, resource); | |
75 } else { | |
76 fjid = g_strdup_printf("%s%c%s", username, | |
77 JID_RESOURCE_SEPARATOR, resource); | |
78 } | |
79 return fjid; | |
80 } | |
81 | |
82 gboolean jid_equal(const char *jid1, const char *jid2) | |
83 { | |
84 char *a,*b; | |
85 int ret; | |
86 if (!jid1 && !jid2) | |
87 return TRUE; | |
88 if (!jid1 || !jid2) | |
89 return FALSE; | |
90 | |
91 a = jidtodisp(jid1); | |
92 b = jidtodisp(jid2); | |
93 ret = strcasecmp(a, b); | |
94 g_free(a); | |
95 g_free(b); | |
96 return (ret == 0) ? TRUE : FALSE; | |
97 } | |
98 | |
48 // expand_filename(filename) | 99 // expand_filename(filename) |
49 // Expand "~/" with the $HOME env. variable in a file name. | 100 // Expand "~/" with the $HOME env. variable in a file name. |
50 // The caller must free the string after use. | 101 // The caller must free the string after use. |
51 char *expand_filename(const char *fname) | 102 char *expand_filename(const char *fname) |
52 { | 103 { |
56 char *homedir = getenv("HOME"); | 107 char *homedir = getenv("HOME"); |
57 if (homedir) | 108 if (homedir) |
58 return g_strdup_printf("%s%s", homedir, fname+1); | 109 return g_strdup_printf("%s%s", homedir, fname+1); |
59 } | 110 } |
60 return g_strdup(fname); | 111 return g_strdup(fname); |
112 } | |
113 | |
114 void fingerprint_to_hex(const unsigned char *fpr, char hex[49]) | |
115 { | |
116 int i; | |
117 char *p; | |
118 | |
119 for (p = hex, i = 0; i < 15; i++, p+=3) | |
120 g_sprintf(p, "%02X:", fpr[i]); | |
121 g_sprintf(p, "%02X", fpr[i]); | |
122 hex[48] = '\0'; | |
123 } | |
124 | |
125 gboolean hex_to_fingerprint(const char *hex, char fpr[16]) | |
126 { | |
127 int i; | |
128 char *p; | |
129 | |
130 if (strlen(hex) != 47) | |
131 return FALSE; | |
132 for (i = 0, p = (char*)hex; *p && *(p+1); i++, p += 3) | |
133 fpr[i] = (char) g_ascii_strtoull (p, NULL, 16); | |
134 return TRUE; | |
61 } | 135 } |
62 | 136 |
63 void ut_InitDebug(int level, const char *filename) | 137 void ut_InitDebug(int level, const char *filename) |
64 { | 138 { |
65 FILE *fp; | 139 FILE *fp; |