From d19ddb6571cb39a62f66762baded30f71a883e2a Mon Sep 17 00:00:00 2001 From: pier11 Date: Mon, 1 Feb 2010 22:57:29 +0000 Subject: [PATCH] refactoring: time_to_str for ease of porting --- src/core/sipe-conf.c | 7 ++++--- src/core/sipe-ews.c | 4 ++-- src/core/sipe-utils.c | 8 ++++++++ src/core/sipe-utils.h | 11 +++++++++++ src/core/sipe.c | 16 ++++++++-------- src/core/sipe.h | 2 -- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/core/sipe-conf.c b/src/core/sipe-conf.c index 7cc8bde5..dd9755b0 100644 --- a/src/core/sipe-conf.c +++ b/src/core/sipe-conf.c @@ -597,7 +597,7 @@ sipe_conf_add(struct sipe_account_data *sip, struct transaction *trans; struct sip_dialog *dialog = NULL; time_t expiry = time(NULL) + 7*60*60; /* 7 hours */ - const char *expiry_time; + char *expiry_time; struct transaction_payload *payload; contact = get_contact(sip); @@ -608,7 +608,7 @@ sipe_conf_add(struct sipe_account_data *sip, contact); g_free(contact); - expiry_time = purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(&expiry)); + expiry_time = sipe_utils_time_to_str(expiry); self = sip_uri_self(sip); conference_id = genconfid(); body = g_strdup_printf( @@ -618,8 +618,9 @@ sipe_conf_add(struct sipe_account_data *sip, rand(), conference_id, expiry_time); - g_free(conference_id); g_free(self); + g_free(conference_id); + g_free(expiry_time); trans = send_sip_request( sip->gc, "SERVICE", diff --git a/src/core/sipe-ews.c b/src/core/sipe-ews.c index 87b28000..4384d457 100644 --- a/src/core/sipe-ews.c +++ b/src/core/sipe-ews.c @@ -511,8 +511,8 @@ sipe_ews_do_avail_request(struct sipe_ews *ews) /* end = start + 4 days - 1 sec */ end = ews->fb_start + 4*(24*60*60) - 1; - start_str = g_strdup(purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(&ews->fb_start))); - end_str = g_strdup(purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(&end))); + start_str = sipe_utils_time_to_str(ews->fb_start); + end_str = sipe_utils_time_to_str(end); body = g_strdup_printf(SIPE_EWS_USER_AVAILABILITY_REQUEST, ews->email, start_str, end_str); ews->http_conn = http_conn_create( diff --git a/src/core/sipe-utils.c b/src/core/sipe-utils.c index 3e31fbac..110806ee 100644 --- a/src/core/sipe-utils.c +++ b/src/core/sipe-utils.c @@ -289,6 +289,14 @@ sipe_utils_str_to_time(const char *timestamp) return purple_str_to_time(timestamp, TRUE, NULL, NULL, NULL); } +char * +sipe_utils_time_to_str(time_t timestamp) +{ +#define SIPE_XML_DATE_PATTERN "%Y-%m-%dT%H:%M:%SZ" + return g_strdup(purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(×tamp))); +} + + /* Local Variables: mode: c diff --git a/src/core/sipe-utils.h b/src/core/sipe-utils.h index 9bea1043..1bbda252 100644 --- a/src/core/sipe-utils.h +++ b/src/core/sipe-utils.h @@ -251,3 +251,14 @@ fix_newlines(const char *st); */ time_t sipe_utils_str_to_time(const char *timestamp); + +/** + * Converts time_t to ISO8601 string. + * Timezone is UTC. + * + * Must be g_free()'d after use. + * + * Example: 2010-02-03T23:59:59Z + */ +char * +sipe_utils_time_to_str(time_t timestamp); diff --git a/src/core/sipe.c b/src/core/sipe.c index f7472364..7a220e7c 100644 --- a/src/core/sipe.c +++ b/src/core/sipe.c @@ -6581,7 +6581,7 @@ send_presence_soap0(struct sipe_account_data *sip, gchar *calendar_data = NULL; gchar *epid = get_epid(sip); time_t now = time(NULL); - gchar *since_time_str = g_strdup(purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(&now))); + gchar *since_time_str = sipe_utils_time_to_str(now); const gchar *oof_note = ews ? sipe_ews_get_oof_note(ews) : NULL; const char *user_input; gboolean pub_oof = ews && oof_note && (!sip->note || ews->updated > sip->note_since); @@ -6663,7 +6663,7 @@ send_presence_soap0(struct sipe_account_data *sip, /* CalendarInfo */ if (ews && (!is_empty(ews->legacy_dn) || !is_empty(ews->email)) && ews->fb_start && !is_empty(ews->free_busy)) { - char *fb_start_str = g_strdup(purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(&ews->fb_start))); + char *fb_start_str = sipe_utils_time_to_str(ews->fb_start); char *free_busy_base64 = sipe_cal_get_freebusy_base64(ews->free_busy); calendar_data = g_strdup_printf(SIPE_SOAP_SET_PRESENCE_CALENDAR, !is_empty(ews->legacy_dn) ? ews->legacy_dn : ews->email, @@ -6946,7 +6946,7 @@ sipe_publish_get_category_state_calendar(struct sipe_account_data *sip, "minAvailability=\"12000\"", ""); } - start_time_str = g_strdup(purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(&event->start_time))); + start_time_str = sipe_utils_time_to_str(event->start_time); res = g_strdup_printf(SIPE_PUB_XML_STATE_CALENDAR, instance, @@ -7064,10 +7064,10 @@ sipe_publish_get_category_note(struct sipe_account_data *sip, return NULL; /* nothing to update */ } - start_time_attr = note_start ? g_strdup_printf(" startTime=\"%s\"", - purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(¬e_start))) : NULL; - end_time_attr = note_end ? g_strdup_printf(" endTime=\"%s\"", - purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(¬e_end))) : NULL; + start_time_attr = note_start ? g_strdup_printf(" startTime=\"%s\"", (tmp = sipe_utils_time_to_str(note_start))) : NULL; + g_free(tmp); + end_time_attr = note_end ? g_strdup_printf(" endTime=\"%s\"", (tmp = sipe_utils_time_to_str(note_end))) : NULL; + g_free(tmp); if (n1) { tmp1 = g_strdup_printf(SIPE_PUB_XML_NOTE, @@ -7251,7 +7251,7 @@ sipe_publish_get_category_cal_free_busy(struct sipe_account_data *sip) return NULL; } - fb_start_str = g_strdup(purple_utf8_strftime(SIPE_XML_DATE_PATTERN, gmtime(&ews->fb_start))); + fb_start_str = sipe_utils_time_to_str(ews->fb_start); free_busy_base64 = sipe_cal_get_freebusy_base64(ews->free_busy); st = publication_cal_300 ? publication_cal_300->fb_start_str : NULL; diff --git a/src/core/sipe.h b/src/core/sipe.h index 3e79f887..0d550c84 100644 --- a/src/core/sipe.h +++ b/src/core/sipe.h @@ -403,8 +403,6 @@ sipe_process_pending_invite_queue(struct sipe_account_data *sip, /*** THE BIG SPLIT END ***/ -#define SIPE_XML_DATE_PATTERN "%Y-%m-%dT%H:%M:%SZ" - #define SIPE_INVITE_TEXT "ms-text-format: text/plain; charset=UTF-8%s;ms-body=%s\r\n" #define SIPE_SEND_TYPING \ -- 2.11.4.GIT