libpurple/log.c

changeset 37205
72893d196f1a
parent 37148
50f361d39a1e
child 37554
506e67bca293
equal deleted inserted replaced
37204:e284917fa740 37205:72893d196f1a
1281 txt = purple_markup_linkify(tmp); 1281 txt = purple_markup_linkify(tmp);
1282 g_free(tmp); 1282 g_free(tmp);
1283 1283
1284 return txt; 1284 return txt;
1285 } 1285 }
1286
1287 #if 0 /* Maybe some other time. */
1288 /****************
1289 ** XML LOGGER **
1290 ****************/
1291
1292 static const char *str_from_msg_type (PurpleMessageFlags type)
1293 {
1294
1295 return "";
1296
1297 }
1298
1299 static void xml_logger_write(PurpleLog *log,
1300 PurpleMessageFlags type,
1301 const char *from, time_t time, const char *message)
1302 {
1303 char *xhtml = NULL;
1304
1305 if (!log->logger_data) {
1306 /* This log is new. We could use the loggers 'new' function, but
1307 * creating a new file there would result in empty files in the case
1308 * that you open a convo with someone, but don't say anything.
1309 */
1310 struct tm *tm;
1311 const char *tz;
1312 const char *date;
1313 char *dir = purple_log_get_log_dir(log->type, log->name, log->account);
1314 char *name;
1315 char *filename;
1316
1317 if (dir == NULL)
1318 return;
1319
1320 tm = localtime(&log->time);
1321 tz = purple_escape_filename(purple_utf8_strftime("%Z", tm);
1322 date = purple_utf8_strftime("%Y-%m-%d.%H%M%S%z", tm);
1323
1324 name = g_strdup_printf("%s%s%s", date, tz, ext ? ext : "");
1325
1326 purple_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
1327
1328 filename = g_build_filename(dir, name, NULL);
1329 g_free(dir);
1330 g_free(name);
1331
1332 log->logger_data = g_fopen(filename, "a");
1333 if (!log->logger_data) {
1334 purple_debug(PURPLE_DEBUG_ERROR, "log", "Could not create log file %s\n", filename);
1335 g_free(filename);
1336 return;
1337 }
1338 g_free(filename);
1339 fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n"
1340 "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n");
1341
1342 date = purple_utf8_strftime("%Y-%m-%d %H:%M:%S", localtime(&log->time));
1343 fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n",
1344 date, log->name, protocol);
1345 }
1346
1347 /* if we can't write to the file, give up before we hurt ourselves */
1348 if(!data->file)
1349 return;
1350
1351 date = log_get_timestamp(log, time);
1352
1353 purple_markup_html_to_xhtml(message, &xhtml, NULL);
1354 if (from)
1355 fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n",
1356 str_from_msg_type(type),
1357 type & PURPLE_MESSAGE_SEND ? "direction='sent'" :
1358 type & PURPLE_MESSAGE_RECV ? "direction='received'" : "",
1359 from, date, xhtml);
1360 else
1361 fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n",
1362 str_from_msg_type(type),
1363 type & PURPLE_MESSAGE_SEND ? "direction='sent'" :
1364 type & PURPLE_MESSAGE_RECV ? "direction='received'" : "",
1365 date, xhtml):
1366 fflush(log->logger_data);
1367 g_free(date);
1368 g_free(xhtml);
1369 }
1370
1371 static void xml_logger_finalize(PurpleLog *log)
1372 {
1373 if (log->logger_data) {
1374 fprintf(log->logger_data, "</conversation>\n");
1375 fclose(log->logger_data);
1376 log->logger_data = NULL;
1377 }
1378 }
1379
1380 static GList *xml_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account)
1381 {
1382 return purple_log_common_lister(type, sn, account, ".xml", &xml_logger);
1383 }
1384
1385 static PurpleLogLogger xml_logger = {
1386 N_("XML"), "xml",
1387 NULL,
1388 xml_logger_write,
1389 xml_logger_finalize,
1390 xml_logger_list,
1391 NULL,
1392 NULL,
1393 NULL
1394 };
1395 #endif
1396 1286
1397 /**************************** 1287 /****************************
1398 ** HTML LOGGER ************* 1288 ** HTML LOGGER *************
1399 ****************************/ 1289 ****************************/
1400 1290

mercurial