| 181 static void jabber_time_parse(JabberStream *js, const char *from, |
181 static void jabber_time_parse(JabberStream *js, const char *from, |
| 182 JabberIqType type, const char *id, |
182 JabberIqType type, const char *id, |
| 183 PurpleXmlNode *child) |
183 PurpleXmlNode *child) |
| 184 { |
184 { |
| 185 JabberIq *iq; |
185 JabberIq *iq; |
| 186 time_t now_t; |
|
| 187 struct tm *tm; |
|
| 188 |
|
| 189 time(&now_t); |
|
| 190 |
186 |
| 191 if(type == JABBER_IQ_GET) { |
187 if(type == JABBER_IQ_GET) { |
| 192 PurpleXmlNode *tzo, *utc; |
188 PurpleXmlNode *tzo, *utc; |
| 193 const char *date, *tz; |
189 GDateTime *now, *now_utc; |
| |
190 gchar *date, *tz; |
| 194 |
191 |
| 195 iq = jabber_iq_new(js, JABBER_IQ_RESULT); |
192 iq = jabber_iq_new(js, JABBER_IQ_RESULT); |
| 196 jabber_iq_set_id(iq, id); |
193 jabber_iq_set_id(iq, id); |
| 197 if (from) |
194 if (from) |
| 198 purple_xmlnode_set_attrib(iq->node, "to", from); |
195 purple_xmlnode_set_attrib(iq->node, "to", from); |
| 199 |
196 |
| 200 child = purple_xmlnode_new_child(iq->node, child->name); |
197 child = purple_xmlnode_new_child(iq->node, child->name); |
| 201 purple_xmlnode_set_namespace(child, NS_ENTITY_TIME); |
198 purple_xmlnode_set_namespace(child, NS_ENTITY_TIME); |
| 202 |
199 |
| 203 /* <tzo>-06:00</tzo> */ |
200 /* <tzo>-06:00</tzo> */ |
| 204 tm = localtime(&now_t); |
201 now = g_date_time_new_now_local(); |
| 205 tz = purple_get_tzoff_str(tm, TRUE); |
202 tz = g_date_time_format(now, "%:z"); |
| 206 tzo = purple_xmlnode_new_child(child, "tzo"); |
203 tzo = purple_xmlnode_new_child(child, "tzo"); |
| 207 purple_xmlnode_insert_data(tzo, tz, -1); |
204 purple_xmlnode_insert_data(tzo, tz, -1); |
| |
205 g_free(tz); |
| 208 |
206 |
| 209 /* <utc>2006-12-19T17:58:35Z</utc> */ |
207 /* <utc>2006-12-19T17:58:35Z</utc> */ |
| 210 tm = gmtime(&now_t); |
208 now_utc = g_date_time_to_utc(now); |
| 211 date = purple_utf8_strftime("%Y-%m-%dT%H:%M:%SZ", tm); |
209 date = g_date_time_format(now_utc, "%FT%TZ"); |
| 212 utc = purple_xmlnode_new_child(child, "utc"); |
210 utc = purple_xmlnode_new_child(child, "utc"); |
| 213 purple_xmlnode_insert_data(utc, date, -1); |
211 purple_xmlnode_insert_data(utc, date, -1); |
| |
212 g_free(date); |
| |
213 |
| |
214 g_date_time_unref(now); |
| |
215 g_date_time_unref(now_utc); |
| 214 |
216 |
| 215 jabber_iq_send(iq); |
217 jabber_iq_send(iq); |
| 216 } else { |
218 } else { |
| 217 /* TODO: Errors */ |
219 /* TODO: Errors */ |
| 218 } |
220 } |