File: gconf-error.c

package info (click to toggle)
gconf 3.2.6-6
  • links: PTS
  • area: main
  • in suites: bullseye, sid
  • size: 15,120 kB
  • sloc: ansic: 39,709; sh: 11,189; python: 1,107; makefile: 445; xml: 332
file content (145 lines) | stat: -rw-r--r-- 3,432 bytes parent folder | download | duplicates (6)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* GConf
 * Copyright (C) 1999, 2000 Red Hat Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include <config.h>
#include "gconf-error.h"
#include "gconf-internals.h"
#include <stdarg.h>

static const gchar* err_msgs[] = {
  N_("Success"),
  N_("Failed"),
  N_("Configuration server couldn't be contacted"),
  N_("Permission denied"),
  N_("Couldn't resolve address for configuration source"),
  N_("Bad key or directory name"),
  N_("Parse error"),
  N_("Corrupt data in configuration source database"),
  N_("Type mismatch"),
  N_("Key operation on directory"),
  N_("Directory operation on key"),
  N_("Can't overwrite existing read-only value"),
  N_("Object Activation Framework error"),
  N_("Operation not allowed without configuration server"),
  N_("Failed to get a lock"),
  N_("No database available to save your configuration")
};

static const int n_err_msgs = sizeof(err_msgs)/sizeof(err_msgs[0]);

static const gchar* 
gconf_strerror       (GConfError en)
{
  g_return_val_if_fail (en < n_err_msgs, NULL);

  return _(err_msgs[en]);    
}

GQuark
gconf_error_quark (void)
{
  static GQuark err_q = 0;

  if (err_q == 0)
    err_q = g_quark_from_static_string ("gconf-error-quark");

  return err_q;
}

static GError* 
gconf_error_new_valist(GConfError en, const gchar* fmt, va_list args)
{
  GError *err;
  gchar* orig;
  
  orig = g_strdup_vprintf(fmt, args);

  err = g_error_new (GCONF_ERROR, en, "%s: %s",
                     gconf_strerror (en),
                     orig);  

  g_free(orig);
  
  return err;
}

GError*
gconf_error_new(GConfError en, const gchar* fmt, ...)
{
  GError* err;
  va_list args;
  
  va_start (args, fmt);
  err = gconf_error_new_valist(en, fmt, args);
  va_end (args);

  return err;
}

void
gconf_set_error      (GError** err, GConfError en, const gchar* fmt, ...)
{
  GError* obj;
  va_list args;

  if (err == NULL)
    return;

  /* Warn if we stack up errors on top
   * of each other. Keep the "deepest"
   * error
   */
  g_return_if_fail(*err == NULL);
  
  va_start (args, fmt);
  obj = gconf_error_new_valist(en, fmt, args);
  va_end (args);

  *err = obj;
}

/* This function should die. */
GError*
gconf_compose_errors (GError* err1, GError* err2)
{
  if (err1 == NULL && err2 == NULL)
    return NULL;
  else if (err1 == NULL)
    return g_error_copy(err2);
  else if (err2 == NULL)
    return g_error_copy(err1);
  else
    {
      GError *n;

      n = g_error_new (GCONF_ERROR, GCONF_ERROR_FAILED, " ");

      if (err1->code == err2->code)
        n->code = err1->code;
      else
        n->code = GCONF_ERROR_FAILED;

      g_free (n->message);
      
      n->message = g_strconcat(err1->message, "\n", err2->message, NULL);

      return n;
    }
}