comparison libpurple/plugins/log_reader.c @ 20329:24ce4fcce5b0

applied changes from e56db1b8a7bb8729e30fb3bf99a94ff7887fe4ec through 3efb5d625e5a73423be8be77a6baeed0b65f7e55 applied changes from 74f0e6698f9f17bc8335cf2454c06e6b13748039 through 017296ee954fb91349806c809983c916842603da applied changes from c8ff393c43d8a5f4136c653853a95284cc5710dc through f53dbbff44537aa86b1cb8788fd306c90e6ccca9 applied changes from f53dbbff44537aa86b1cb8788fd306c90e6ccca9 through 5798594431164383deacd7d4aad5a9a0d5b867ae applied changes from 5798594431164383deacd7d4aad5a9a0d5b867ae through 0822c640f22b63d7bc8992e62b80bccd1eea12a2 applied changes from 703c3f9437d5e71255819c747f9690d19c6ba6e3 through b7a2c4d81867c3bbd262c2a4b1d924ea7fd3afb6 applied changes from b7a2c4d81867c3bbd262c2a4b1d924ea7fd3afb6 through 5ea15b000ee727088be88bb335c2ded6b2ab96e3 applied changes from 5ea15b000ee727088be88bb335c2ded6b2ab96e3 through c5051010dd50f9fdb7f85d779d882ce8bbc149f2
author Luke Schierer <lschiere@pidgin.im>
date Fri, 19 Oct 2007 18:14:53 +0000
parents 615f6343035f
children 3a9709bfde65
comparison
equal deleted inserted replaced
20328:dc7f87da7e95 20329:24ce4fcce5b0
230 static char *adium_logger_read (PurpleLog *log, PurpleLogReadFlags *flags) 230 static char *adium_logger_read (PurpleLog *log, PurpleLogReadFlags *flags)
231 { 231 {
232 struct adium_logger_data *data; 232 struct adium_logger_data *data;
233 GError *error = NULL; 233 GError *error = NULL;
234 gchar *read = NULL; 234 gchar *read = NULL;
235 gsize length;
236 235
237 /* XXX: TODO: We probably want to set PURPLE_LOG_READ_NO_NEWLINE 236 /* XXX: TODO: We probably want to set PURPLE_LOG_READ_NO_NEWLINE
238 * XXX: TODO: for HTML logs. */ 237 * XXX: TODO: for HTML logs. */
239 if (flags != NULL) 238 if (flags != NULL)
240 *flags = 0; 239 *flags = 0;
244 data = log->logger_data; 243 data = log->logger_data;
245 244
246 g_return_val_if_fail(data->path != NULL, g_strdup("")); 245 g_return_val_if_fail(data->path != NULL, g_strdup(""));
247 246
248 purple_debug_info("Adium log read", "Reading %s\n", data->path); 247 purple_debug_info("Adium log read", "Reading %s\n", data->path);
249 if (!g_file_get_contents(data->path, &read, &length, &error)) { 248 if (!g_file_get_contents(data->path, &read, NULL, &error)) {
250 purple_debug_error("Adium log read", "Error reading log\n"); 249 purple_debug_error("Adium log read", "Error reading log: %s\n",
250 (error && error->message) ? error->message : "Unknown error");
251 if (error) 251 if (error)
252 g_error_free(error); 252 g_error_free(error);
253 return g_strdup(""); 253 return g_strdup("");
254 } 254 }
255 255
1806 purple_debug_info("QIP logger", "Reading %s\n", path); 1806 purple_debug_info("QIP logger", "Reading %s\n", path);
1807 1807
1808 error = NULL; 1808 error = NULL;
1809 if (!g_file_get_contents(path, &contents, NULL, &error)) { 1809 if (!g_file_get_contents(path, &contents, NULL, &error)) {
1810 purple_debug_error("QIP logger", 1810 purple_debug_error("QIP logger",
1811 "Couldn't read file %s: %s \n", path, error->message); 1811 "Couldn't read file %s: %s \n", path,
1812 g_error_free(error); 1812 (error && error->message) ? error->message : "Unknown error");
1813 if (error)
1814 g_error_free(error);
1813 g_free(path); 1815 g_free(path);
1814 return list; 1816 return list;
1815 } 1817 }
1816 1818
1817 c = contents; 1819 c = contents;
1953 1955
1954 /* Convert file contents from Cp1251 to UTF-8 codeset */ 1956 /* Convert file contents from Cp1251 to UTF-8 codeset */
1955 error = NULL; 1957 error = NULL;
1956 if (!(utf8_string = g_convert(contents, -1, "UTF-8", "Cp1251", NULL, NULL, &error))) { 1958 if (!(utf8_string = g_convert(contents, -1, "UTF-8", "Cp1251", NULL, NULL, &error))) {
1957 purple_debug_error("QIP logger", 1959 purple_debug_error("QIP logger",
1958 "Couldn't convert file %s to UTF-8: %s\n", data->path, error->message); 1960 "Couldn't convert file %s to UTF-8: %s\n", data->path,
1959 g_error_free(error); 1961 (error && error->message) ? error->message : "Unknown error");
1962 if (error)
1963 g_error_free(error);
1960 g_free(contents); 1964 g_free(contents);
1961 return g_strdup(""); 1965 return g_strdup("");
1962 } 1966 }
1963 1967
1964 g_free(contents); 1968 g_free(contents);
2149 /* Add Messenger Plus! log directory preference. */ 2153 /* Add Messenger Plus! log directory preference. */
2150 purple_prefs_add_none("/plugins/core/log_reader/messenger_plus"); 2154 purple_prefs_add_none("/plugins/core/log_reader/messenger_plus");
2151 2155
2152 /* Calculate default Messenger Plus! log directory. */ 2156 /* Calculate default Messenger Plus! log directory. */
2153 #ifdef _WIN32 2157 #ifdef _WIN32
2158 path = NULL;
2154 folder = wpurple_get_special_folder(CSIDL_PERSONAL); 2159 folder = wpurple_get_special_folder(CSIDL_PERSONAL);
2155 if (folder) { 2160 if (folder) {
2156 path = g_build_filename(folder, "My Chat Logs", NULL); 2161 path = g_build_filename(folder, "My Chat Logs", NULL);
2157 g_free(folder); 2162 g_free(folder);
2158 } else 2163 }
2159 path = g_strdup("");
2160 #else 2164 #else
2161 path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, 2165 path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT,
2162 "Documents and Settings", g_get_user_name(), 2166 "Documents and Settings", g_get_user_name(),
2163 "My Documents", "My Chat Logs", NULL); 2167 "My Documents", "My Chat Logs", NULL);
2164 #endif 2168 #endif
2165 purple_prefs_add_string("/plugins/core/log_reader/messenger_plus/log_directory", path); 2169 purple_prefs_add_string("/plugins/core/log_reader/messenger_plus/log_directory", path ? path : "");
2166 g_free(path); 2170 g_free(path);
2167 2171
2168 2172
2169 /* Add MSN Messenger log directory preference. */ 2173 /* Add MSN Messenger log directory preference. */
2170 purple_prefs_add_none("/plugins/core/log_reader/msn"); 2174 purple_prefs_add_none("/plugins/core/log_reader/msn");
2171 2175
2172 /* Calculate default MSN message history directory. */ 2176 /* Calculate default MSN message history directory. */
2173 #ifdef _WIN32 2177 #ifdef _WIN32
2178 path = NULL;
2174 folder = wpurple_get_special_folder(CSIDL_PERSONAL); 2179 folder = wpurple_get_special_folder(CSIDL_PERSONAL);
2175 if (folder) { 2180 if (folder) {
2176 path = g_build_filename(folder, "My Received Files", NULL); 2181 path = g_build_filename(folder, "My Received Files", NULL);
2177 g_free(folder); 2182 g_free(folder);
2178 } else 2183 }
2179 path = g_strdup("");
2180 #else 2184 #else
2181 path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, 2185 path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT,
2182 "Documents and Settings", g_get_user_name(), 2186 "Documents and Settings", g_get_user_name(),
2183 "My Documents", "My Received Files", NULL); 2187 "My Documents", "My Received Files", NULL);
2184 #endif 2188 #endif
2185 purple_prefs_add_string("/plugins/core/log_reader/msn/log_directory", path); 2189 purple_prefs_add_string("/plugins/core/log_reader/msn/log_directory", path ? path : "");
2186 g_free(path); 2190 g_free(path);
2187 2191
2188 2192
2189 /* Add Trillian log directory preference. */ 2193 /* Add Trillian log directory preference. */
2190 purple_prefs_add_none("/plugins/core/log_reader/trillian"); 2194 purple_prefs_add_none("/plugins/core/log_reader/trillian");
2259 } 2263 }
2260 2264
2261 g_key_file_free(key_file); 2265 g_key_file_free(key_file);
2262 } 2266 }
2263 #else /* !GLIB_CHECK_VERSION(2,6,0) */ 2267 #else /* !GLIB_CHECK_VERSION(2,6,0) */
2264 gsize length;
2265 gchar *contents = NULL; 2268 gchar *contents = NULL;
2266 2269
2267 purple_debug_info("Trillian talk.ini read", 2270 purple_debug_info("Trillian talk.ini read",
2268 "Reading %s\n", path); 2271 "Reading %s\n", path);
2269 if (!g_file_get_contents(path, &contents, &length, &error)) { 2272 if (!g_file_get_contents(path, &contents, NULL, &error)) {
2270 purple_debug_error("Trillian talk.ini read", 2273 purple_debug_error("Trillian talk.ini read",
2271 "Error reading talk.ini\n"); 2274 "Error reading talk.ini: %s\n",
2275 (error && error->message) ? error->message : "Unknown error");
2272 if (error) 2276 if (error)
2273 g_error_free(error); 2277 g_error_free(error);
2274 g_free(path);
2275 } else { 2278 } else {
2276 char *line = contents; 2279 char *cursor, *line;
2277 while (*contents) { 2280 line = cursor = contents;
2278 if (*contents == '\n') { 2281 while (*cursor) {
2279 *contents = '\0'; 2282 if (*cursor == '\n') {
2283 *cursor = '\0';
2280 2284
2281 /* XXX: This assumes the first Directory key is under [Logging]. */ 2285 /* XXX: This assumes the first Directory key is under [Logging]. */
2282 if (purple_str_has_prefix(line, "Directory=")) { 2286 if (purple_str_has_prefix(line, "Directory=")) {
2283 line += (sizeof("Directory=") - 1); 2287 line += (sizeof("Directory=") - 1);
2284 g_strchomp(line); 2288 g_strchomp(line);
2286 "/plugins/core/log_reader/trillian/log_directory", 2290 "/plugins/core/log_reader/trillian/log_directory",
2287 line); 2291 line);
2288 found = TRUE; 2292 found = TRUE;
2289 } 2293 }
2290 2294
2291 contents++; 2295 cursor++;
2292 line = contents; 2296 line = cursor;
2293 } else 2297 } else
2294 contents++; 2298 cursor++;
2295 } 2299 }
2296 g_free(path);
2297 g_free(contents); 2300 g_free(contents);
2298 } 2301 }
2302 g_free(path);
2299 #endif /* !GTK_CHECK_VERSION(2,6,0) */ 2303 #endif /* !GTK_CHECK_VERSION(2,6,0) */
2300 } /* path */ 2304 } /* path */
2301 2305
2302 if (!found) { 2306 if (!found) {
2307 path = NULL;
2303 folder = wpurple_get_special_folder(CSIDL_PROGRAM_FILES); 2308 folder = wpurple_get_special_folder(CSIDL_PROGRAM_FILES);
2304 if (folder) { 2309 if (folder) {
2305 path = g_build_filename(folder, "Trillian", "users", 2310 path = g_build_filename(folder, "Trillian", "users",
2306 "default", "logs", NULL); 2311 "default", "logs", NULL);
2307 g_free(folder); 2312 g_free(folder);
2308 } else 2313 }
2309 path = g_strdup(""); 2314
2315 purple_prefs_add_string(
2316 "/plugins/core/log_reader/trillian/log_directory", path ? path : "");
2317 g_free(path);
2310 } 2318 }
2311 #else /* !defined(_WIN32) */ 2319 #else /* !defined(_WIN32) */
2312 /* TODO: At some point, this could attempt to parse talk.ini 2320 /* TODO: At some point, this could attempt to parse talk.ini
2313 * TODO: from the default Trillian install directory on the 2321 * TODO: from the default Trillian install directory on the
2314 * TODO: Windows mount point. */ 2322 * TODO: Windows mount point. */
2315 2323
2316 /* Calculate default Trillian log directory. */ 2324 /* Calculate default Trillian log directory. */
2317 path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, 2325 path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT,
2318 "Program Files", "Trillian", "users", 2326 "Program Files", "Trillian", "users",
2319 "default", "logs", NULL); 2327 "default", "logs", NULL);
2328 purple_prefs_add_string(
2329 "/plugins/core/log_reader/trillian/log_directory", path);
2330 g_free(path);
2320 #endif 2331 #endif
2321
2322 /*XXX: Why do we even bother allocating it ? */
2323 g_free(path);
2324
2325 2332
2326 /* Add QIP log directory preference. */ 2333 /* Add QIP log directory preference. */
2327 purple_prefs_add_none("/plugins/core/log_reader/qip"); 2334 purple_prefs_add_none("/plugins/core/log_reader/qip");
2328 2335
2329 /* Calculate default QIP log directory. */ 2336 /* Calculate default QIP log directory. */
2330 #ifdef _WIN32 2337 #ifdef _WIN32
2338 path = NULL;
2331 folder = wpurple_get_special_folder(CSIDL_PROGRAM_FILES); 2339 folder = wpurple_get_special_folder(CSIDL_PROGRAM_FILES);
2332 if (folder) { 2340 if (folder) {
2333 path = g_build_filename(folder, "QIP", "Users", NULL); 2341 path = g_build_filename(folder, "QIP", "Users", NULL);
2334 g_free(folder); 2342 g_free(folder);
2335 } else 2343 }
2336 path = g_strdup("");
2337 #else 2344 #else
2338 path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, 2345 path = g_build_filename(PURPLE_LOG_READER_WINDOWS_MOUNT_POINT,
2339 "Program Files", "QIP", "Users", NULL); 2346 "Program Files", "QIP", "Users", NULL);
2340 #endif 2347 #endif
2341 purple_prefs_add_string("/plugins/core/log_reader/qip/log_directory", path); 2348 purple_prefs_add_string("/plugins/core/log_reader/qip/log_directory", path ? path : "");
2342 g_free(path); 2349 g_free(path);
2343 } 2350 }
2344 2351
2345 static gboolean 2352 static gboolean
2346 plugin_load(PurplePlugin *plugin) 2353 plugin_load(PurplePlugin *plugin)