Skip to content

Commit

Permalink
Fix some static analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
EionRobb committed Aug 24, 2020
1 parent a049f3e commit 2295eb2
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 43 deletions.
6 changes: 3 additions & 3 deletions skypeweb/libskypeweb.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ skypeweb_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gbool
g_free(escaped);
}
if (sbuddy->fullname && *sbuddy->fullname) {
gchar *escaped = g_markup_printf_escaped("%s", sbuddy->display_name);
purple_notify_user_info_add_pair_html(user_info, "Full Name", sbuddy->fullname);
gchar *escaped = g_markup_printf_escaped("%s", sbuddy->fullname);
purple_notify_user_info_add_pair_html(user_info, "Full Name", escaped);
g_free(escaped);
}
}
Expand Down Expand Up @@ -520,7 +520,7 @@ skypeweb_cmd_topic(PurpleConversation *conv, const gchar *cmd, gchar **args, gch
return PURPLE_CMD_RET_OK;
}

skypeweb_chat_set_topic(pc, id, args ? args[0] : NULL);
skypeweb_chat_set_topic(pc, id, args[0]);

return PURPLE_CMD_RET_OK;
}
Expand Down
14 changes: 7 additions & 7 deletions skypeweb/libskypeweb.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@
#include <json-glib/json-glib.h>

#define json_object_get_int_member(JSON_OBJECT, MEMBER) \
(JSON_OBJECT && json_object_has_member(JSON_OBJECT, MEMBER) ? json_object_get_int_member(JSON_OBJECT, MEMBER) : 0)
((JSON_OBJECT) && json_object_has_member((JSON_OBJECT), (MEMBER)) ? json_object_get_int_member((JSON_OBJECT), (MEMBER)) : 0)
#define json_object_get_string_member(JSON_OBJECT, MEMBER) \
(JSON_OBJECT && json_object_has_member(JSON_OBJECT, MEMBER) ? json_object_get_string_member(JSON_OBJECT, MEMBER) : NULL)
((JSON_OBJECT) && json_object_has_member((JSON_OBJECT), (MEMBER)) ? json_object_get_string_member((JSON_OBJECT), (MEMBER)) : NULL)
#define json_object_get_array_member(JSON_OBJECT, MEMBER) \
(JSON_OBJECT && json_object_has_member(JSON_OBJECT, MEMBER) ? json_object_get_array_member(JSON_OBJECT, MEMBER) : NULL)
((JSON_OBJECT) && json_object_has_member((JSON_OBJECT), (MEMBER)) ? json_object_get_array_member((JSON_OBJECT), (MEMBER)) : NULL)
#define json_object_get_object_member(JSON_OBJECT, MEMBER) \
(JSON_OBJECT && json_object_has_member(JSON_OBJECT, MEMBER) ? json_object_get_object_member(JSON_OBJECT, MEMBER) : NULL)
((JSON_OBJECT) && json_object_has_member((JSON_OBJECT), (MEMBER)) ? json_object_get_object_member((JSON_OBJECT), (MEMBER)) : NULL)
#define json_object_get_boolean_member(JSON_OBJECT, MEMBER) \
(JSON_OBJECT && json_object_has_member(JSON_OBJECT, MEMBER) ? json_object_get_boolean_member(JSON_OBJECT, MEMBER) : FALSE)
((JSON_OBJECT) && json_object_has_member((JSON_OBJECT), (MEMBER)) ? json_object_get_boolean_member((JSON_OBJECT), (MEMBER)) : FALSE)
#define json_array_get_length(JSON_ARRAY) \
(JSON_ARRAY ? json_array_get_length(JSON_ARRAY) : 0)
((JSON_ARRAY) ? json_array_get_length(JSON_ARRAY) : 0)
#define json_node_get_array(JSON_NODE) \
(JSON_NODE && JSON_NODE_TYPE(JSON_NODE) == JSON_NODE_ARRAY ? json_node_get_array(JSON_NODE) : NULL)
((JSON_NODE) && JSON_NODE_TYPE(JSON_NODE) == (JSON_NODE_ARRAY) ? json_node_get_array(JSON_NODE) : NULL)

#include "accountopt.h"
#include "core.h"
Expand Down
23 changes: 12 additions & 11 deletions skypeweb/purple2compat/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#define PURPLE_HTTP_REQUEST_DEFAULT_MAX_REDIRECTS 20
#define PURPLE_HTTP_REQUEST_DEFAULT_TIMEOUT 30
#define PURPLE_HTTP_REQUEST_DEFAULT_MAX_LENGTH 1048576
#define PURPLE_HTTP_REQUEST_HARD_MAX_LENGTH G_MAXINT32-1
#define PURPLE_HTTP_REQUEST_HARD_MAX_LENGTH (G_MAXINT32-1)
#define PURPLE_HTTP_PROGRESS_WATCHER_DEFAULT_INTERVAL 250000
Expand Down Expand Up @@ -334,7 +334,7 @@ static time_t purple_http_rfc1123_to_time(const gchar *str)
g_free(d_time);

if (month > 12) {
purple_debug_warning("http", "Invalid month: %s\n", d_month);
purple_debug_warning("http", "Invalid month: %d\n", month);
g_free(iso_date);
return 0;
}
Expand Down Expand Up @@ -405,7 +405,6 @@ purple_http_gz_put(PurpleHttpGzStream *gzs, const gchar *buf, gsize len)
gsize decompressed_len;

zs->next_out = (Bytef*)decompressed_buff;
zs->avail_out = sizeof(decompressed_buff);
decompressed_len = zs->avail_out = sizeof(decompressed_buff);
gzres = inflate(zs, Z_FULL_FLUSH);
decompressed_len -= zs->avail_out;
Expand All @@ -431,7 +430,8 @@ purple_http_gz_put(PurpleHttpGzStream *gzs, const gchar *buf, gsize len)
purple_debug_error("http",
"Decompression failed (%d): %s\n", gzres,
zs->msg);
gzs->failed = TRUE;
gzs->failed = TRUE;
g_string_free(ret, TRUE);
return NULL;
}
}
Expand Down Expand Up @@ -777,7 +777,7 @@ static void _purple_http_gen_headers(PurpleHttpConnection *hc)
purple_http_request_is_method(req, "post")))
{
g_string_append_printf(h, "Content-Length: %u\r\n",
req->contents_length);
(unsigned int) req->contents_length);
}

if (proxy_http)
Expand Down Expand Up @@ -1602,7 +1602,7 @@ PurpleHttpConnection * purple_http_request(PurpleConnection *gc,
hc, request->url);
else
purple_debug_misc("http", "Performing new request %p to %s.\n",
hc, hc->url ? hc->url->host : NULL);
hc, hc->url ? hc->url->host : "");

if (!hc->url || hc->url->host == NULL || hc->url->host[0] == '\0') {
purple_debug_error("http", "Invalid URL requested.\n");
Expand Down Expand Up @@ -2025,7 +2025,7 @@ void purple_http_cookie_jar_set(PurpleHttpCookieJar *cookie_jar,
gchar *escaped_name = g_strdup(purple_url_encode(name));
gchar *escaped_value = NULL;

if (escaped_value) {
if (value) {
escaped_value = g_strdup(purple_url_encode(value));
}

Expand Down Expand Up @@ -3077,7 +3077,7 @@ purple_http_url_print(PurpleHttpURL *parsed_url)
if (parsed_url->username || parsed_url->password) {
if (parsed_url->username)
g_string_append(url, parsed_url->username);
g_string_append_printf(url, ":%s", parsed_url->password);
g_string_append_printf(url, ":%s", parsed_url->password ? parsed_url->password : "");
g_string_append(url, "@");
before_host_printed = TRUE;
}
Expand Down Expand Up @@ -3222,9 +3222,10 @@ void purple_http_uninit(void)
purple_http_re_url_host = NULL;
g_regex_unref(purple_http_re_rfc1123);
purple_http_re_rfc1123 = NULL;

g_list_foreach(purple_http_hc_list, purple_http_foreach_conn_cancel,
NULL);

if (purple_http_hc_list != NULL)
g_list_foreach(purple_http_hc_list, purple_http_foreach_conn_cancel,
NULL);

if (purple_http_hc_list != NULL ||
0 != g_hash_table_size(purple_http_hc_by_ptr) ||
Expand Down
8 changes: 5 additions & 3 deletions skypeweb/purple2compat/purple-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ handle_remove(PurpleSocket *ps)
PurpleConnection *gc = ps->gc;
GSList *l;

l = g_hash_table_lookup(handles, gc);
l = g_slist_remove(l, ps);
g_hash_table_insert(handles, gc, l);
l = g_hash_table_lookup(handles, gc);
if (l != NULL) {
l = g_slist_remove(l, ps);
g_hash_table_insert(handles, gc, l);
}
}

void
Expand Down
2 changes: 1 addition & 1 deletion skypeweb/purplecompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ purple_blist_node_set_transient(PurpleBlistNode *node, gboolean transient)
#define purple_conversations_find_im_with_account(name, account) \
PURPLE_CONV_IM(purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, name, account))
#define purple_im_conversation_new(account, from) PURPLE_CONV_IM(purple_conversation_new(PURPLE_CONV_TYPE_IM, account, from))
#define PURPLE_CONVERSATION(chatorim) (chatorim == NULL ? NULL : chatorim->conv)
#define PURPLE_CONVERSATION(chatorim) ((chatorim) == NULL ? NULL : (chatorim)->conv)
#define PURPLE_IM_CONVERSATION(conv) PURPLE_CONV_IM(conv)
#define PURPLE_CHAT_CONVERSATION(conv) PURPLE_CONV_CHAT(conv)
#define PURPLE_IS_IM_CONVERSATION(conv) (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
Expand Down
15 changes: 11 additions & 4 deletions skypeweb/skypeweb_contacts.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static void purple_conversation_write_system_message_ts(
PurpleMessage *pmsg = purple_message_new_system(msg, flags);
purple_message_set_time(pmsg, ts);
purple_conversation_write_message(conv, pmsg);
purple_message_destroy(pmsg);
}
static void purple_conversation_write_img_message(
PurpleConversation *conv, const char* who, const gchar *msg,
Expand All @@ -46,6 +47,7 @@ static void purple_conversation_write_img_message(
}

purple_conversation_write_message(conv, pmsg);
purple_message_destroy(pmsg);
}

// Check that the conversation hasn't been closed
Expand Down Expand Up @@ -104,11 +106,16 @@ skypeweb_get_icon_now(PurpleBuddy *buddy)
purple_debug_info("skypeweb", "getting new buddy icon for %s\n", purple_buddy_get_name(buddy));

sbuddy = purple_buddy_get_protocol_data(buddy);
if (sbuddy != NULL && sbuddy->avatar_url && sbuddy->avatar_url[0]) {

if (!sbuddy || !sbuddy->sa || !sbuddy->sa->pc)
return;

if (sbuddy->avatar_url && sbuddy->avatar_url[0]) {
url = g_strdup(sbuddy->avatar_url);
} else {
url = g_strdup_printf("https://avatar.skype.com/v1/avatars/%s/public?returnDefaultImage=false", purple_url_encode(purple_buddy_get_name(buddy)));
}

sa = sbuddy->sa;

purple_http_get(sa->pc, skypeweb_get_icon_cb, buddy, url);
Expand Down Expand Up @@ -486,7 +493,7 @@ skypeweb_got_file_info(PurpleHttpConnection *http_conn, PurpleHttpResponse *resp
} */
purple_debug_info("skypeweb", "File info: %s\n", data);

if (!json_object_has_member(obj, "content_state") || !g_str_equal(json_object_get_string_member(obj, "content_state"), "ready")) {
if (!json_object_has_member(obj, "content_state") || !purple_strequal(json_object_get_string_member(obj, "content_state"), "ready")) {
skypeweb_present_uri_as_filetransfer(sa, json_object_get_string_member(obj, "status_location"), swft->from);
g_free(swft->url);
g_free(swft->from);
Expand Down Expand Up @@ -567,7 +574,7 @@ got_file_send_progress(PurpleHttpConnection *http_conn, PurpleHttpResponse *resp
swft->url = g_strdup(json_object_get_string_member(obj, "status_location"));
}

if (json_object_has_member(obj, "content_state") && g_str_equal(json_object_get_string_member(obj, "content_state"), "ready")) {
if (json_object_has_member(obj, "content_state") && purple_strequal(json_object_get_string_member(obj, "content_state"), "ready")) {
PurpleXmlNode *uriobject = purple_xmlnode_new("URIObject");
PurpleXmlNode *title = purple_xmlnode_new_child(uriobject, "Title");
PurpleXmlNode *description = purple_xmlnode_new_child(uriobject, "Description");
Expand Down Expand Up @@ -877,7 +884,7 @@ skypeweb_got_self_details(SkypeWebAccount *sa, JsonNode *node, gpointer user_dat
if (!old_alias || !*old_alias) {
if (json_object_has_member(userobj, "displayname"))
displayname = json_object_get_string_member(userobj, "displayname");
if (!displayname || g_str_equal(displayname, username))
if (!displayname || purple_strequal(displayname, username))
displayname = json_object_get_string_member(userobj, "firstname");

if (displayname)
Expand Down
1 change: 1 addition & 0 deletions skypeweb/skypeweb_login.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ skypeweb_login_did_auth(PurpleHttpConnection *http_conn, PurpleHttpResponse *res
purple_connection_error(sa->pc,
PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
_("Failed getting Skype Token, please try logging in via browser first"));
return;
}

if (refresh_token == NULL) {
Expand Down
43 changes: 29 additions & 14 deletions skypeweb/skypeweb_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ process_message_resource(SkypeWebAccount *sa, JsonObject *resource)
PurpleConversation *conv = NULL;
gchar *convname = NULL;

g_return_if_fail(messagetype != NULL);

messagetype_parts = g_strsplit(messagetype, "/", -1);

if (json_object_has_member(resource, "clientmessageid"))
Expand Down Expand Up @@ -178,7 +180,11 @@ process_message_resource(SkypeWebAccount *sa, JsonObject *resource)
PurpleChatUser *cb;

from = skypeweb_contact_url_to_name(from);
g_return_if_fail(from);
if (from == NULL) {
g_strfreev(messagetype_parts);
g_return_if_reached();
return;
}

// typing notification text, not personalized because of multiple "typing" events
if (purple_account_get_bool(sa->account, "show-typing-as-text", FALSE)) {
Expand All @@ -188,7 +194,7 @@ process_message_resource(SkypeWebAccount *sa, JsonObject *resource)
// get last message (first in GList)
if (conv && g_list_length(purple_conversation_get_message_history(conv))) {
PurpleMessage *last = g_list_nth_data(g_list_first(purple_conversation_get_message_history(conv)),0);
last_message = g_strdup(purple_message_get_contents(last));
last_message = purple_message_get_contents(last);
}

// add typing notification to chat
Expand Down Expand Up @@ -227,7 +233,11 @@ process_message_resource(SkypeWebAccount *sa, JsonObject *resource)
}

from = skypeweb_contact_url_to_name(from);
g_return_if_fail(from);
if (from == NULL) {
g_free(messagetype_parts);
g_return_if_reached();
return;
}

// Remove typing notification icon w/o "show-typing-as-icon" option check.
// Hard reset cbflags even if user changed settings while someone typing message.
Expand Down Expand Up @@ -348,7 +358,12 @@ process_message_resource(SkypeWebAccount *sa, JsonObject *resource)
convname = g_strconcat(skypeweb_user_url_prefix(convbuddyname), convbuddyname, NULL);

from = skypeweb_contact_url_to_name(from);
g_return_if_fail(from);
if (from == NULL) {
g_free(convbuddyname);
g_free(convname);
g_return_if_reached();
return;
}

if (g_str_equal(messagetype_parts[0], "Control")) {
if (g_str_equal(messagetype_parts[1], "ClearTyping")) {
Expand Down Expand Up @@ -596,7 +611,7 @@ process_message_resource(SkypeWebAccount *sa, JsonObject *resource)
gchar *post, *url;

url = g_strdup_printf("/v1/users/ME/conversations/%s/properties?name=consumptionhorizon", purple_url_encode(convname));
post = g_strdup_printf("{\"consumptionhorizon\":\"%s;%" G_GINT64_FORMAT ";%s\"}", id, skypeweb_get_js_time(), id);
post = g_strdup_printf("{\"consumptionhorizon\":\"%s;%" G_GINT64_FORMAT ";%s\"}", id ? id : "", skypeweb_get_js_time(), id ? id : "");

skypeweb_post_or_get(sa, SKYPEWEB_METHOD_PUT | SKYPEWEB_METHOD_SSL, sa->messages_host, url, post, NULL, NULL, TRUE);

Expand Down Expand Up @@ -669,7 +684,7 @@ process_endpointpresence_resource(SkypeWebAccount *sa, JsonObject *resource)
case 1: //SkypeWeb
break;
default:
purple_debug_warning("skypeweb", "Unknown typ %d: %s\n", typ, skypeNameVersion);
purple_debug_warning("skypeweb", "Unknown typ %d: %s\n", typ, skypeNameVersion ? skypeNameVersion : "");
break;
}
}
Expand Down Expand Up @@ -723,19 +738,19 @@ skypeweb_poll_cb(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
const gchar *resourceType = json_object_get_string_member(message, "resourceType");
JsonObject *resource = json_object_get_object_member(message, "resource");

if (g_str_equal(resourceType, "NewMessage"))
if (purple_strequal(resourceType, "NewMessage"))
{
process_message_resource(sa, resource);
} else if (g_str_equal(resourceType, "UserPresence"))
} else if (purple_strequal(resourceType, "UserPresence"))
{
process_userpresence_resource(sa, resource);
} else if (g_str_equal(resourceType, "EndpointPresence"))
} else if (purple_strequal(resourceType, "EndpointPresence"))
{
process_endpointpresence_resource(sa, resource);
} else if (g_str_equal(resourceType, "ConversationUpdate"))
} else if (purple_strequal(resourceType, "ConversationUpdate"))
{
process_conversation_resource(sa, resource);
} else if (g_str_equal(resourceType, "ThreadUpdate"))
} else if (purple_strequal(resourceType, "ThreadUpdate"))
{
process_thread_resource(sa, resource);
}
Expand Down Expand Up @@ -775,7 +790,7 @@ skypeweb_mark_conv_seen(PurpleConversation *conv, PurpleConversationUpdateType t
if (!PURPLE_CONNECTION_IS_CONNECTED(pc))
return;

if (g_strcmp0(purple_protocol_get_id(purple_connection_get_protocol(pc)), SKYPEWEB_PLUGIN_ID))
if (!purple_strequal(purple_protocol_get_id(purple_connection_get_protocol(pc)), SKYPEWEB_PLUGIN_ID))
return;

if (type == PURPLE_CONVERSATION_UPDATE_UNSEEN) {
Expand Down Expand Up @@ -1344,7 +1359,7 @@ skypeweb_conv_send_typing(PurpleConversation *conv, PurpleIMTypingState state)
if (!PURPLE_CONNECTION_IS_CONNECTED(pc))
return 0;

if (g_strcmp0(purple_protocol_get_id(purple_connection_get_protocol(pc)), SKYPEWEB_PLUGIN_ID))
if (!purple_strequal(purple_protocol_get_id(purple_connection_get_protocol(pc)), SKYPEWEB_PLUGIN_ID))
return 0;

url = g_strdup_printf("/v1/users/ME/conversations/%s/messages", purple_url_encode(purple_conversation_get_name(conv)));
Expand Down Expand Up @@ -1542,7 +1557,7 @@ const gchar *message, PurpleMessageFlags flags)
chatname = purple_conversation_get_name(PURPLE_CONVERSATION(chatconv));
if (!chatname)
return -1;
}
}

skypeweb_send_message(sa, chatname, message);

Expand Down

0 comments on commit 2295eb2

Please sign in to comment.