Mercurial > pidgin.yaz
annotate src/protocols/jabber/jutil.c @ 7274:448e39ace278
[gaim-migrate @ 7851]
Added a parameter to gaim_ssl_connect() to specify an optional error
callback. MSN takes advantage of it, but since I can't reproduce the errors
here, I'm not positive it works. It should though! Famous last words.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 15 Oct 2003 06:32:13 +0000 |
parents | 85fcaff1505d |
children | 7c12dab8e513 |
rev | line source |
---|---|
7014 | 1 /* |
2 * gaim - Jabber Protocol Plugin | |
3127 | 3 * |
7014 | 4 * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> |
3127 | 5 * |
7014 | 6 * This program is free software; you can redistribute it and/or modify |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
3127 | 10 * |
7014 | 11 * This program is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
3127 | 19 * |
7014 | 20 */ |
21 #include "internal.h" | |
22 #include "server.h" | |
23 | |
24 #include "presence.h" | |
25 #include "jutil.h" | |
3127 | 26 |
7014 | 27 time_t str_to_time(const char *timestamp) |
28 { | |
29 struct tm t; | |
30 time_t retval = 0; | |
31 char buf[32]; | |
32 char *c; | |
33 int tzoff = 0; | |
2086 | 34 |
7014 | 35 time(&retval); |
36 localtime_r(&retval, &t); | |
37 | |
38 snprintf(buf, sizeof(buf), "%s", timestamp); | |
39 c = buf; | |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3127
diff
changeset
|
40 |
7014 | 41 /* 4 digit year */ |
42 if(!sscanf(c, "%04d", &t.tm_year)) return 0; | |
43 c+=4; | |
44 if(*c == '-') | |
45 c++; | |
2086 | 46 |
7014 | 47 t.tm_year -= 1900; |
48 | |
49 /* 2 digit month */ | |
50 if(!sscanf(c, "%02d", &t.tm_mon)) return 0; | |
51 c+=2; | |
52 if(*c == '-') | |
53 c++; | |
54 | |
55 t.tm_mon -= 1; | |
2086 | 56 |
7014 | 57 /* 2 digit day */ |
58 if(!sscanf(c, "%02d", &t.tm_mday)) return 0; | |
59 c+=2; | |
60 if(*c == 'T') { /* we have more than a date, keep going */ | |
61 c++; /* skip the "T" */ | |
2086 | 62 |
7014 | 63 /* 2 digit hour */ |
64 if(sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec)) { | |
65 int tzhrs, tzmins; | |
66 c+=8; | |
67 if(*c == '.') /* dealing with precision we don't care about */ | |
68 c += 4; | |
2086 | 69 |
7014 | 70 if((*c == '+' || *c == '-') && |
71 sscanf(c+1, "%02d:%02d", &tzhrs, &tzmins)) { | |
72 tzoff = tzhrs*60*60 + tzmins*60; | |
73 if(*c == '+') | |
74 tzoff *= -1; | |
75 } | |
2086 | 76 |
7014 | 77 #ifdef HAVE_TM_GMTOFF |
78 tzoff += t.tm_gmtoff; | |
79 #else | |
80 # ifdef HAVE_TIMEZONE | |
81 tzset(); /* making sure */ | |
82 tzoff -= timezone; | |
83 # endif | |
84 #endif | |
85 } | |
2086 | 86 } |
7014 | 87 retval = mktime(&t); |
2086 | 88 |
7014 | 89 retval += tzoff; |
2086 | 90 |
7014 | 91 return retval; |
2086 | 92 } |
93 | |
7014 | 94 const char *jabber_get_state_string(int s) { |
95 switch(s) { | |
96 case JABBER_STATE_AWAY: | |
97 return _("Away"); | |
98 break; | |
99 case JABBER_STATE_CHAT: | |
100 return _("Chatty"); | |
101 break; | |
102 case JABBER_STATE_XA: | |
103 return _("Extended Away"); | |
104 break; | |
105 case JABBER_STATE_DND: | |
106 return _("Do Not Disturb"); | |
107 break; | |
108 default: | |
109 return _("Available"); | |
110 break; | |
111 } | |
2086 | 112 } |
113 | |
7014 | 114 JabberID* |
115 jabber_id_new(const char *str) | |
2086 | 116 { |
7014 | 117 char *at; |
118 char *slash; | |
119 | |
120 JabberID *jid; | |
2086 | 121 |
7014 | 122 if(!str) |
123 return NULL; | |
2086 | 124 |
7014 | 125 jid = g_new0(JabberID, 1); |
126 | |
127 at = strchr(str, '@'); | |
128 slash = strchr(str, '/'); | |
2086 | 129 |
7014 | 130 if(at) { |
131 jid->node = g_strndup(str, at-str); | |
132 if(slash) { | |
133 jid->domain = g_strndup(at+1, slash-(at+1)); | |
134 jid->resource = g_strdup(slash+1); | |
135 } else { | |
136 jid->domain = g_strdup(at+1); | |
137 } | |
138 } else { | |
139 if(slash) { | |
140 jid->domain = g_strndup(str, slash-str); | |
141 jid->resource = g_strdup(slash+1); | |
142 } else { | |
143 jid->domain = g_strdup(str); | |
144 } | |
145 } | |
2086 | 146 |
7014 | 147 return jid; |
2086 | 148 } |
149 | |
7014 | 150 void |
151 jabber_id_free(JabberID *jid) | |
2086 | 152 { |
7014 | 153 if(jid) { |
154 if(jid->node) | |
155 g_free(jid->node); | |
156 if(jid->domain) | |
157 g_free(jid->domain); | |
158 if(jid->resource) | |
159 g_free(jid->resource); | |
160 g_free(jid); | |
161 } | |
2086 | 162 } |
163 | |
7014 | 164 |
165 const char *jabber_get_resource(const char *jid) | |
166 { | |
167 char *slash; | |
168 | |
169 slash = strrchr(jid, '/'); | |
170 if(slash) | |
171 return slash+1; | |
172 else | |
173 return NULL; | |
174 } | |
175 | |
176 char *jabber_get_bare_jid(const char *jid) | |
177 { | |
178 char *slash; | |
179 slash = strrchr(jid, '/'); | |
180 | |
181 if(slash) | |
7262 | 182 return g_utf8_strdown(jid, slash - jid); |
7014 | 183 else |
7262 | 184 return g_utf8_strdown(jid, -1); |
7014 | 185 } |
7261 | 186 |
7262 | 187 const char *jabber_normalize(const char *in) |
7261 | 188 { |
189 static char buf[2048]; /* maximum legal length of a jabber jid */ | |
190 char *tmp; | |
191 | |
192 tmp = jabber_get_bare_jid(in); | |
193 g_snprintf(buf, sizeof(buf), "%s", tmp); | |
194 g_free(tmp); | |
195 return buf; | |
196 } |