summaryrefslogtreecommitdiff
path: root/salut/utils.c
blob: 255f400d846ea0462f75ef24d49f327c3ea2312f (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * util.c - Source for ytstenut utilities
 * Copyright (C) 2011 Intel, Corp.
 *   @author: Stef Walter <stefw@collabora.co.uk>
 *
 * 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
 */

#include "config.h"

#include "utils.h"

#include <telepathy-ytstenut-glib/telepathy-ytstenut-glib.h>

GQuark
ytst_message_error_quark (void)
{
  static GQuark quark = 0;

  if (quark == 0)
    quark = g_quark_from_static_string (YTST_MESSAGE_NS);

  return quark;
}

WockyXmppErrorDomain *
ytst_message_error_get_domain (void)
{
  static WockyXmppErrorSpecialization codes[] = {
      { "The recipient does not have sufficient privileges to carry out the "
        "command..",
        YTST_MESSAGE_ERROR_FORBIDDEN,
        TRUE,
        WOCKY_XMPP_ERROR_TYPE_MODIFY
      },
      { "The resource could not be located.",
        YTST_MESSAGE_ERROR_ITEM_NOT_FOUND,
        TRUE,
        WOCKY_XMPP_ERROR_TYPE_MODIFY
      }
  };
  static WockyXmppErrorDomain ytstenut_errors = { 0, };

  if (G_UNLIKELY (ytstenut_errors.domain == 0))
    {
      ytstenut_errors.domain = YTST_MESSAGE_ERROR;
      ytstenut_errors.enum_type = YTST_TYPE_MESSAGE_ERROR;
      ytstenut_errors.codes = codes;
    }

  return &ytstenut_errors;
}

GType
ytst_message_error_get_type (void)
{
  static GType etype = 0;

  if (g_once_init_enter (&etype))
    {
      static const GEnumValue values[] = {
        { YTST_MESSAGE_ERROR_FORBIDDEN,
            "YTST_MESSAGE_ERROR_FORBIDDEN", "forbidden" },
        { YTST_MESSAGE_ERROR_ITEM_NOT_FOUND,
            "YTST_MESSAGE_ERROR_ITEM_NOT_FOUND", "item-not-found" },
        { 0 }
      };

      g_once_init_leave (&etype, g_enum_register_static ("YtstMessageError",
          values));
    }

  return etype;
}

gint
ytst_message_error_type_to_wocky (guint ytstenut_type)
{
  switch (ytstenut_type)
    {
      case TP_YTS_ERROR_TYPE_CANCEL:
        return WOCKY_XMPP_ERROR_TYPE_CANCEL;
      case TP_YTS_ERROR_TYPE_CONTINUE:
        return WOCKY_XMPP_ERROR_TYPE_CONTINUE;
      case TP_YTS_ERROR_TYPE_MODIFY:
        return WOCKY_XMPP_ERROR_TYPE_MODIFY;
      case TP_YTS_ERROR_TYPE_AUTH:
        return WOCKY_XMPP_ERROR_TYPE_AUTH;
      case TP_YTS_ERROR_TYPE_WAIT:
        return WOCKY_XMPP_ERROR_TYPE_WAIT;
      default:
        return -1;
    }
}

guint
ytst_message_error_type_from_wocky (gint wocky_type)
{
  switch (wocky_type)
    {
      case WOCKY_XMPP_ERROR_TYPE_CANCEL:
        return TP_YTS_ERROR_TYPE_CANCEL;
      case WOCKY_XMPP_ERROR_TYPE_CONTINUE:
        return TP_YTS_ERROR_TYPE_CONTINUE;
      case WOCKY_XMPP_ERROR_TYPE_MODIFY:
        return TP_YTS_ERROR_TYPE_MODIFY;
      case WOCKY_XMPP_ERROR_TYPE_AUTH:
        return TP_YTS_ERROR_TYPE_AUTH;
      case WOCKY_XMPP_ERROR_TYPE_WAIT:
        return TP_YTS_ERROR_TYPE_WAIT;
      default:
        g_return_val_if_reached (0);
    }
}