XRootD
Loading...
Searching...
No Matches
XrdOucERoute.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d O u c E R o u t e . h h */
4/* */
5/* (c) 2012 by the Board of Trustees of the Leland Stanford, Jr., University */
6/* All Rights Reserved */
7/* Produced by Andrew Hanushevsky for Stanford University under contract */
8/* DE-AC02-76-SFO0515 with the Department of Energy */
9/* */
10/* This file is part of the XRootD software suite. */
11/* */
12/* XRootD is free software: you can redistribute it and/or modify it under */
13/* the terms of the GNU Lesser General Public License as published by the */
14/* Free Software Foundation, either version 3 of the License, or (at your */
15/* option) any later version. */
16/* */
17/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20/* License for more details. */
21/* */
22/* You should have received a copy of the GNU Lesser General Public License */
23/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25/* */
26/* The copyright holder's institutional names and contributor's names may not */
27/* be used to endorse or promote products derived from this software without */
28/* specific prior written permission of the institution or contributor. */
29/******************************************************************************/
30
31#include <cctype>
32#include <cstdio>
33#include <cstring>
34
37#include "XrdSys/XrdSysError.hh"
39
40/******************************************************************************/
41/* F o r m a t */
42/******************************************************************************/
43
44int XrdOucERoute::Format(char *buff, int blen, int ecode, const char *etxt1,
45 const char *etxt2)
46{
47 const char *esep = " ", *estr = XrdSysError::ec2text(ecode);
48 char ebuff[256];
49 int n;
50
51// Substitute something of no ecode translation exists
52//
53 if (!estr) estr = "reason unknown";
54 else if (isupper(static_cast<int>(*estr)))
55 {strlcpy(ebuff, estr, sizeof(ebuff));
56 *ebuff = static_cast<char>(tolower(static_cast<int>(*estr)));
57 estr = ebuff;
58 }
59
60// Set format elements
61//
62 if (!etxt2) etxt2 = esep = "";
63
64// Format the message
65//
66 n = snprintf(buff, blen, "Unable to %s%s%s; %s",etxt1,esep,etxt2,estr);
67 return (n < blen ? n : blen-1);
68}
69
70/******************************************************************************/
71/* R o u t e */
72/******************************************************************************/
73
75 const char *esfx, int ecode,
76 const char *etxt1, const char *etxt2)
77{
78 char ebuff[2048];
79 int elen;
80
81// Format the error message
82//
83 elen = Format(ebuff, sizeof(ebuff), ecode, etxt1, etxt2);
84
85// Route appropriately
86//
87 if (elog) elog->Emsg(esfx, ebuff);
88 if (estrm) estrm->Put(ebuff, elen);
89
90// Return the error number
91//
92 if (ecode) return (ecode < 0 ? ecode : -ecode);
93 return -1;
94}
size_t strlcpy(char *dst, const char *src, size_t sz)
static int Format(char *buff, int blen, int ecode, const char *etxt1, const char *etxt2=0)
static int Route(XrdSysError *elog, XrdOucStream *estrm, const char *esfx, int ecode, const char *etxt1, const char *etxt2=0)
int Put(const char *data, const int dlen)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
static const char * ec2text(int ecode)