Wrap debug messages in Config.DEBUG checks
This commit is contained in:
		| @@ -295,7 +295,9 @@ public class Matrix.Event : GLib.Object, GLib.Initable { | ||||
|             return klass.get_type(); | ||||
|         } | ||||
|  | ||||
|         warning("UsingMatrix.Event for %s", event_type); | ||||
|         if (Config.DEBUG) { | ||||
|             warning("Using Matrix.Event for %s", event_type); | ||||
|         } | ||||
|  | ||||
|         return typeof(Matrix.Event); | ||||
|     } | ||||
|   | ||||
| @@ -69,8 +69,10 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { | ||||
|                 _homeserver = null; | ||||
|                 _user_id = null; | ||||
|  | ||||
|                 debug("API URL: %s", api_uri.to_string(false)); | ||||
|                 debug("Media URL: %s", media_uri.to_string(false)); | ||||
|                 if (Config.DEBUG) { | ||||
|                     debug("API URL: %s", api_uri.to_string(false)); | ||||
|                     debug("Media URL: %s", media_uri.to_string(false)); | ||||
|                 } | ||||
|             } else { | ||||
|                 warning("Invalid base URL: %s", value); | ||||
|             } | ||||
| @@ -186,7 +188,9 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { | ||||
|         } | ||||
|  | ||||
|         if (token != null) { | ||||
|             debug("Adding access token '%s'", token); | ||||
|             if (Config.DEBUG) { | ||||
|                 debug("Adding access token '%s'", token); | ||||
|             } | ||||
|  | ||||
|             parms.replace("access_token", token); | ||||
|         } | ||||
| @@ -208,13 +212,15 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { | ||||
|             request_data = "{}".data; | ||||
|         } | ||||
|  | ||||
|         debug("Sending %d bytes (%s %s): %s", | ||||
|               request_data.length, | ||||
|               method, | ||||
|               request_path.to_string(false), | ||||
|               (raw_content != null) | ||||
|                   ? "<Binary data>" | ||||
|                   : (string)request_data); | ||||
|         if (Config.DEBUG) { | ||||
|             debug("Sending %d bytes (%s %s): %s", | ||||
|                   request_data.length, | ||||
|                   method, | ||||
|                   request_path.to_string(false), | ||||
|                   (raw_content != null) | ||||
|                       ? "<Binary data>" | ||||
|                       : (string)request_data); | ||||
|         } | ||||
|  | ||||
|         message.set_flags(Soup.MessageFlags.NO_REDIRECT); | ||||
|         message.set_request( | ||||
| @@ -276,7 +282,9 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { | ||||
|             } | ||||
|  | ||||
|             if (is_json) { | ||||
|                 debug("Response (%s): %s", request_url, data); | ||||
|                 if (Config.DEBUG) { | ||||
|                     debug("Response (%s): %s", request_url, data); | ||||
|                 } | ||||
|  | ||||
|                 content = parser.get_root(); | ||||
|  | ||||
| @@ -290,7 +298,10 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { | ||||
|                         string? access_token; | ||||
|  | ||||
|                         if ((access_token = node.get_string()) != null) { | ||||
|                             debug("Got new access token: %s", access_token); | ||||
|                             if (Config.DEBUG) { | ||||
|                                 debug("Got new access token: %s", access_token); | ||||
|                             } | ||||
|  | ||||
|                             token = access_token; | ||||
|                         } | ||||
|                     } | ||||
| @@ -301,8 +312,11 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { | ||||
|                         string? refresh_token; | ||||
|  | ||||
|                         if ((refresh_token = node.get_string()) != null) { | ||||
|                             debug("Got new refresh token: %s", | ||||
|                                   refresh_token); | ||||
|                             if (Config.DEBUG) { | ||||
|                                 debug("Got new refresh token: %s", | ||||
|                                       refresh_token); | ||||
|                             } | ||||
|  | ||||
|                             this.refresh_token = refresh_token; | ||||
|                         } | ||||
|                     } | ||||
| @@ -311,7 +325,11 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { | ||||
|                     if ((node = root.get_member("home_server")) != null) { | ||||
|                         string homeserver = node.get_string(); | ||||
|  | ||||
|                         debug("Our home server calls itself %s", homeserver); | ||||
|                         if (Config.DEBUG) { | ||||
|                             debug("Our home server calls itself %s", | ||||
|                                   homeserver); | ||||
|                         } | ||||
|  | ||||
|                         this._homeserver = homeserver; | ||||
|                     } | ||||
|  | ||||
| @@ -320,7 +338,11 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { | ||||
|                     if ((node = root.get_member("user_id")) != null) { | ||||
|                         string user_id = node.get_string(); | ||||
|  | ||||
|                         debug("We are reported to be logged in as %s", user_id); | ||||
|                         if (Config.DEBUG) { | ||||
|                             debug("We are reported to be logged in as %s", | ||||
|                                   user_id); | ||||
|                         } | ||||
|  | ||||
|                         this._user_id = user_id; | ||||
|                     } | ||||
|  | ||||
| @@ -403,11 +425,18 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { | ||||
|                 if (accept_non_json) { | ||||
|                     raw_content = new ByteArray.sized((uint)datalen); | ||||
|                     raw_content.append(buffer.data); | ||||
|                     debug("Binary data (%s): %u bytes", request_url, (uint)datalen); | ||||
|  | ||||
|                     if (Config.DEBUG) { | ||||
|                         debug("Binary data (%s): %u bytes", | ||||
|                               request_url, (uint)datalen); | ||||
|                     } | ||||
|                 } else { | ||||
|                     err = new Matrix.Error.BAD_RESPONSE( | ||||
|                             "Malformed response (invalid JSON)"); | ||||
|                     debug("Malformed response (%s): %s", request_url, data); | ||||
|  | ||||
|                     if (Config.DEBUG) { | ||||
|                         debug("Malformed response (%s): %s", request_url, data); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -84,7 +84,9 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { | ||||
|         Matrix.Event evt; | ||||
|  | ||||
|         if (event_node.get_node_type() != Json.NodeType.OBJECT) { | ||||
|             warning("Received event that is not an object."); | ||||
|             if (Config.DEBUG) { | ||||
|                 warning("Received event that is not an object."); | ||||
|             } | ||||
|  | ||||
|             return; | ||||
|         } | ||||
| @@ -92,7 +94,9 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { | ||||
|         root_obj = event_node.get_object(); | ||||
|  | ||||
|         if ((node = root_obj.get_member("type")) == null) { | ||||
|             warning("Received event without type."); | ||||
|             if (Config.DEBUG) { | ||||
|                 warning("Received event without type."); | ||||
|             } | ||||
|  | ||||
|             return; | ||||
|         } | ||||
| @@ -102,11 +106,15 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { | ||||
|         try { | ||||
|             evt = Matrix.Event.new_from_json(event_type, room_id, event_node); | ||||
|         } catch (Matrix.Error e) { | ||||
|             warning("Error during event creation: %s", e.message); | ||||
|             if (Config.DEBUG) { | ||||
|                 warning("Error during event creation: %s", e.message); | ||||
|             } | ||||
|  | ||||
|             return; | ||||
|         } catch (GLib.Error e) { | ||||
|             warning("Error during event creation: %s", e.message); | ||||
|             if (Config.DEBUG) { | ||||
|                 warning("Error during event creation: %s", e.message); | ||||
|             } | ||||
|  | ||||
|             return; | ||||
|         } | ||||
| @@ -143,11 +151,17 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { | ||||
|             var root_obj = json_content.get_object(); | ||||
|             Json.Node? node; | ||||
|  | ||||
|             debug("Processing account data"); | ||||
|             if (Config.DEBUG) { | ||||
|                 debug("Processing account data"); | ||||
|             } | ||||
|  | ||||
|             _process_event_list_obj(root_obj.get_member("account_data"), | ||||
|                                     null); | ||||
|  | ||||
|             debug("Processing presence"); | ||||
|             if (Config.DEBUG) { | ||||
|                 debug("Processing presence"); | ||||
|             } | ||||
|  | ||||
|             _process_event_list_obj(root_obj.get_member("presence"), | ||||
|                                     null); | ||||
|  | ||||
| @@ -156,7 +170,9 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client { | ||||
|                     Json.Object rooms_object = node.get_object(); | ||||
|                     Json.Node rooms_node; | ||||
|  | ||||
|                     debug("Processing rooms"); | ||||
|                     if (Config.DEBUG) { | ||||
|                         debug("Processing rooms"); | ||||
|                     } | ||||
|  | ||||
|                     if ((rooms_node = rooms_object.get_member( | ||||
|                                  "invite")) != null) { | ||||
|   | ||||
| @@ -40,8 +40,8 @@ public class Matrix.PresenceEvent : Matrix.Event { | ||||
|  | ||||
|         if ((node = content_root.get_member("user_id")) != null) { | ||||
|             _sender = node.get_string(); | ||||
|         } else { | ||||
|             GLib.warning("user_id is missing from the m.presence event"); | ||||
|         } else if (Config.DEBUG) { | ||||
|             warning("user_id is missing from the m.presence event"); | ||||
|         } | ||||
|  | ||||
|         if ((node = content_root.get_member("last_active_ago")) != null) { | ||||
| @@ -67,8 +67,8 @@ public class Matrix.PresenceEvent : Matrix.Event { | ||||
|             } else { | ||||
|                 _presence = Matrix.Presence.UNKNOWN; | ||||
|             } | ||||
|         } else { | ||||
|             GLib.warning("presence is missing from the m.presence event"); | ||||
|         } else if (Config.DEBUG) { | ||||
|             warning("presence is missing from the m.presence event"); | ||||
|         } | ||||
|  | ||||
|         base.from_json(json_data); | ||||
|   | ||||
| @@ -40,14 +40,14 @@ public class Matrix.RoomMemberEvent : Matrix.RoomEvent { | ||||
|  | ||||
|         if ((node = root.get_member("state_key")) != null) { | ||||
|             _state_key = node.get_string(); | ||||
|         } else { | ||||
|             GLib.warning("state_key is missing from the m.room.member event"); | ||||
|         } else if (Config.DEBUG) { | ||||
|             warning("state_key is missing from the m.room.member event"); | ||||
|         } | ||||
|  | ||||
|         if ((node = root.get_member("room_id")) != null) { | ||||
|             _room_id = node.get_string(); | ||||
|         } else { | ||||
|             GLib.warning("room_id is missing from the m.room.member event"); | ||||
|         } else if (Config.DEBUG) { | ||||
|             warning("room_id is missing from the m.room.member event"); | ||||
|         } | ||||
|  | ||||
|         if ((node = content_root.get_member("membership")) != null) { | ||||
| @@ -58,8 +58,8 @@ public class Matrix.RoomMemberEvent : Matrix.RoomEvent { | ||||
|             if (mship != null) { | ||||
|                 _membership = mship; | ||||
|             } | ||||
|         } else { | ||||
|             GLib.warning("membership key is missing from the m.room.member event"); | ||||
|         } else if (Config.DEBUG) { | ||||
|             warning("membership key is missing from the m.room.member event"); | ||||
|         } | ||||
|  | ||||
|         if ((node = content_root.get_member("avatar_url")) != null) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user