summaryrefslogtreecommitdiff
path: root/telepathy-logger/util.c
blob: 1bfdd91d8a80633065569d507db92c8f761a27e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2009 Collabora Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
 */

#include "util.h"

#include "datetime.h"
#include "log-store-index.h"

/* Bug#26838 prevents us to trust Messages' iface message-token
 * header, so I need to create a token which TPL can trust to be unique
 * within itself */
gchar *
create_message_token (const gchar *channel,
    gint64 timestamp,
    guint msgid)
{
  GChecksum *log_id = g_checksum_new (G_CHECKSUM_SHA1);
  gchar *retval;
  gchar *date = tpl_time_to_string_local (timestamp,
      TPL_LOG_STORE_INDEX_TIMESTAMP_FORMAT);

  g_checksum_update (log_id, (guchar *) channel, -1);
  g_checksum_update (log_id, (guchar *) date, -1);
  g_checksum_update (log_id, (guchar *) &msgid, sizeof (unsigned int));

  retval = g_strdup (g_checksum_get_string (log_id));

  g_checksum_free (log_id);
  g_free (date);

  return retval;
}