summaryrefslogtreecommitdiff
path: root/subversion/libsvn_ra_serf/util_error.c
blob: da66091a354f4bf5f5175b84c409442db50ce49b (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
/*
 * util_error.c : serf utility routines for wrapping serf status codes
 *
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you under the Apache License, Version 2.0 (the
 *    "License"); you may not use this file except in compliance
 *    with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing,
 *    software distributed under the License is distributed on an
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *    KIND, either express or implied.  See the License for the
 *    specific language governing permissions and limitations
 *    under the License.
 * ====================================================================
 */
#include <serf.h>

#include "svn_utf.h"
#include "private/svn_error_private.h"

#include "ra_serf.h"

/*
 * Undefine the helpers for creating errors.
 *
 * *NOTE*: Any use of these functions in any other function may need
 * to call svn_error__locate() because the macro that would otherwise
 * do this is being undefined and the filename and line number will
 * not be properly set in the static error_file and error_line
 * variables.
 */
#undef svn_error_create
#undef svn_error_createf
#undef svn_error_quick_wrap
#undef svn_error_wrap_apr
#undef svn_ra_serf__wrap_err

svn_error_t *
svn_ra_serf__wrap_err(apr_status_t status,
                      const char *fmt,
                      ...)
{
  const char *serf_err_msg = serf_error_string(status);
  svn_error_t *err;
  va_list ap;

  err = svn_error_create(status, NULL, NULL);

  if (serf_err_msg || fmt)
    {
      const char *msg;
      const char *err_msg;
      char errbuf[255]; /* Buffer for APR error message. */

      if (serf_err_msg)
        {
          err_msg = serf_err_msg;
        }
      else
        {
          svn_error_t *utf8_err;

          /* Grab the APR error message. */
          apr_strerror(status, errbuf, sizeof(errbuf));
          utf8_err = svn_utf_cstring_to_utf8(&err_msg, errbuf, err->pool);
          if (utf8_err)
            err_msg = NULL;
          svn_error_clear(utf8_err);
        }

      /* Append it to the formatted message. */
      if (fmt)
        {
          va_start(ap, fmt);
          msg = apr_pvsprintf(err->pool, fmt, ap);
          va_end(ap);
        }
      else
        {
          msg = "ra_serf";
        }
      if (err_msg)
        {
          err->message = apr_pstrcat(err->pool, msg, ": ", err_msg, NULL);
        }
      else
        {
          err->message = msg;
        }
    }

  return err;
}