diff --git a/src/stk.c b/src/stk.c index a9c73fc5..dcb3ef06 100644 --- a/src/stk.c +++ b/src/stk.c @@ -34,6 +34,8 @@ #include #include +#include + #include "ofono.h" #include "common.h" @@ -363,17 +365,15 @@ static struct stk_menu *stk_menu_create(const char *title, if (item_icon_ids && item_icon_ids->len && item_icon_ids->len != len) return NULL; - ret = g_try_new(struct stk_menu, 1); - if (ret == NULL) - return NULL; + ret = l_new(struct stk_menu, 1); ret->title = dbus_apply_text_attributes(title ? title : "", title_attr); if (ret->title == NULL) - ret->title = g_strdup(title ? title : ""); + ret->title = l_strdup(title ? title : ""); memcpy(&ret->icon, icon, sizeof(ret->icon)); - ret->items = g_new0(struct stk_menu_item, len + 1); + ret->items = l_new(struct stk_menu_item, len + 1); ret->default_item = -1; ret->soft_key = soft_key; ret->has_help = has_help; @@ -394,7 +394,7 @@ static struct stk_menu *stk_menu_create(const char *title, } if (text == NULL) - text = strdup(item->text); + text = l_strdup(item->text); ret->items[i].text = text; @@ -448,11 +448,11 @@ static void stk_menu_free(struct stk_menu *menu) struct stk_menu_item *i; for (i = menu->items; i->text; i++) - g_free(i->text); + l_free(i->text); - g_free(menu->items); - g_free(menu->title); - g_free(menu); + l_free(menu->items); + l_free(menu->title); + l_free(menu); } static void emit_menu_changed(struct ofono_stk *stk) @@ -561,7 +561,7 @@ static gboolean stk_alpha_id_set(struct ofono_stk *stk, else stk_agent_display_action_info(stk->current_agent, alpha, icon); - g_free(alpha); + l_free(alpha); return TRUE; } @@ -986,7 +986,7 @@ static gboolean handle_command_set_idle_text(const struct stk_command *cmd, } if (stk->idle_mode_text) - g_free(stk->idle_mode_text); + l_free(stk->idle_mode_text); if (sim->icon_id.id != 0 && sim->icon_id.qualifier == STK_ICON_QUALIFIER_TYPE_SELF_EXPLANATORY) @@ -1403,7 +1403,7 @@ static gboolean handle_command_display_text(const struct stk_command *cmd, err = stk_agent_display_text(stk->current_agent, text, &dt->icon_id, priority, display_text_cb, stk, display_text_destroy, timeout); - g_free(text); + l_free(text); /* We most likely got an out of memory error, tell SIM to retry */ if (err < 0) { @@ -1610,7 +1610,7 @@ static gboolean handle_command_get_inkey(const struct stk_command *cmd, &gi->icon_id, request_key_cb, stk, NULL, timeout); - g_free(text); + l_free(text); if (err < 0) { unsigned char no_cause_result[] = { 0x00 }; @@ -1704,7 +1704,7 @@ static gboolean handle_command_get_input(const struct stk_command *cmd, request_string_cb, stk, NULL, timeout); - g_free(text); + l_free(text); if (err < 0) { unsigned char no_cause_result[] = { 0x00 }; @@ -1829,7 +1829,7 @@ static void confirm_call_cb(enum stk_agent_result result, gboolean confirm, alpha_id, sc->icon_id_call_setup.id, qualifier >> 1, call_setup_connected, stk); - g_free(alpha_id); + l_free(alpha_id); if (err >= 0) { stk->cancel_cmd = call_setup_cancel; @@ -1961,7 +1961,7 @@ static gboolean handle_command_set_up_call(const struct stk_command *cmd, err = stk_agent_confirm_call(stk->current_agent, alpha_id, &sc->icon_id_usr_cfm, confirm_call_cb, stk, NULL, stk->timeout * 1000); - g_free(alpha_id); + l_free(alpha_id); if (err < 0) { unsigned char no_cause_result[] = { 0x00 }; @@ -2148,7 +2148,7 @@ static gboolean handle_command_send_ussd(const struct stk_command *cmd, static void free_idle_mode_text(struct ofono_stk *stk) { - g_free(stk->idle_mode_text); + l_free(stk->idle_mode_text); stk->idle_mode_text = NULL; memset(&stk->idle_mode_icon, 0, sizeof(stk->idle_mode_icon)); @@ -2662,7 +2662,7 @@ static gboolean handle_command_play_tone(const struct stk_command *cmd, play_tone_cb, stk, NULL, timeout); - g_free(text); + l_free(text); if (err < 0) { unsigned char no_cause_result[] = { 0x00 }; @@ -2734,7 +2734,7 @@ static gboolean handle_command_launch_browser(const struct stk_command *cmd, lb->icon_id.id, lb->url, confirm_launch_browser_cb, stk, NULL, stk->timeout * 1000); - g_free(alpha_id); + l_free(alpha_id); if (err < 0) { unsigned char no_cause_result[] = { 0x00 }; @@ -2785,7 +2785,7 @@ static gboolean handle_setup_call_confirmation_req(struct stk_command *cmd, confirm_handled_call_cb, stk, NULL, stk->timeout * 1000); - g_free(alpha_id); + l_free(alpha_id); if (err < 0) goto out; @@ -3150,7 +3150,7 @@ static void stk_unregister(struct ofono_atom *atom) stk->cancel_cmd = NULL; } - g_free(stk->idle_mode_text); + l_free(stk->idle_mode_text); stk->idle_mode_text = NULL; if (stk->timers_source) { diff --git a/src/stkutil.c b/src/stkutil.c index a0cf0a8d..01d65788 100644 --- a/src/stkutil.c +++ b/src/stkutil.c @@ -6223,41 +6223,41 @@ enum stk_text_format_code { STK_TEXT_FORMAT_STYLE_STRIKETHROUGH = 0x80, }; -static void end_format(GString *string, guint16 attr) +static void end_format(struct l_string *string, uint16_t attr) { - guint code = attr & 0xFF; - guint color = (attr >> 8) & 0xFF; + uint8_t code = attr & 0xFF; + uint8_t color = (attr >> 8) & 0xFF; if ((code & ~STK_TEXT_FORMAT_ALIGN_MASK) || color) - g_string_append(string, ""); + l_string_append(string, ""); if ((code & STK_TEXT_FORMAT_ALIGN_MASK) != STK_TEXT_FORMAT_NO_ALIGN) - g_string_append(string, ""); + l_string_append(string, ""); } -static void start_format(GString *string, guint16 attr) +static void start_format(struct l_string *string, uint16_t attr) { - guint8 code = attr & 0xFF; - guint8 color = (attr >> 8) & 0xFF; - guint8 align = code & STK_TEXT_FORMAT_ALIGN_MASK; - guint8 font = code & STK_TEXT_FORMAT_FONT_MASK; - guint8 style = code & STK_TEXT_FORMAT_STYLE_MASK; + uint8_t code = attr & 0xFF; + uint8_t color = (attr >> 8) & 0xFF; + uint8_t align = code & STK_TEXT_FORMAT_ALIGN_MASK; + uint8_t font = code & STK_TEXT_FORMAT_FONT_MASK; + uint8_t style = code & STK_TEXT_FORMAT_STYLE_MASK; int fg = color & 0x0f; int bg = (color >> 4) & 0x0f; /* align formatting applies to a block of text */ if (align != STK_TEXT_FORMAT_NO_ALIGN) - g_string_append(string, "
"); + l_string_append(string, "text-align: right;\">"); break; case STK_TEXT_FORMAT_CENTER_ALIGN: - g_string_append(string, "text-align: center;\">"); + l_string_append(string, "text-align: center;\">"); break; case STK_TEXT_FORMAT_LEFT_ALIGN: - g_string_append(string, "text-align: left;\">"); + l_string_append(string, "text-align: left;\">"); break; } @@ -6265,50 +6265,46 @@ static void start_format(GString *string, guint16 attr) return; /* font, style, and color are inline */ - g_string_append(string, ""); + l_string_append(string, "\">"); } char *stk_text_to_html(const char *utf8, const unsigned short *attrs, int num_attrs) { - long text_len = g_utf8_strlen(utf8, -1); - GString *string = g_string_sized_new(strlen(utf8) + 1); + long text_len = l_utf8_strlen(utf8); + struct l_string *string = l_string_new(strlen(utf8) + 1); short *formats; int pos, i, j; - guint16 start, end, len, attr, prev_attr; - guint8 code, color, align; + uint16_t start, end, len, attr, prev_attr; + uint8_t code, color, align; const char *text = utf8; int attrs_len = num_attrs * 4; - formats = g_try_new0(gint16, (text_len + 1)); - if (formats == NULL) { - g_string_free(string, TRUE); - return NULL; - } + formats = l_new(int16_t, text_len + 1); /* we will need formatting at the position beyond the last char */ for (i = 0; i <= text_len; i++) @@ -6353,6 +6349,9 @@ char *stk_text_to_html(const char *utf8, prev_attr = STK_TEXT_FORMAT_INIT; for (pos = 0; pos <= text_len; pos++) { + wchar_t c; + int len; + attr = formats[pos]; if (attr != prev_attr) { if (prev_attr != STK_TEXT_FORMAT_INIT) @@ -6367,43 +6366,40 @@ char *stk_text_to_html(const char *utf8, if (pos == text_len) break; - switch (g_utf8_get_char(text)) { + len = l_utf8_get_codepoint(text, 4, &c); + switch (c) { case '\n': - g_string_append(string, "
"); + l_string_append(string, "
"); break; case '\r': - { - char *next = g_utf8_next_char(text); - gunichar c = g_utf8_get_char(next); - - g_string_append(string, "
"); - - if ((pos + 1 < text_len) && (c == '\n')) { - text = g_utf8_next_char(text); - pos++; + /* If the next character is a newline, consume it */ + if ((pos + 1 < text_len) && (text[len] == '\n')) { + pos += 1; + len += 1; } + + l_string_append(string, "
"); break; - } case '<': - g_string_append(string, "<"); + l_string_append(string, "<"); break; case '>': - g_string_append(string, ">"); + l_string_append(string, ">"); break; case '&': - g_string_append(string, "&"); + l_string_append(string, "&"); break; default: - g_string_append_unichar(string, g_utf8_get_char(text)); + l_string_append_fixed(string, text, len); } - text = g_utf8_next_char(text); + text += len; } - g_free(formats); + l_free(formats); /* return characters from string. Caller must free char data */ - return g_string_free(string, FALSE); + return l_string_unwrap(string); } static const char chars_table[] = {