Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / gdp / gdp_stat.c @ master

History | View | Annotate | Download (6.98 KB)

1 a901db09 Eric Allman
/* vim: set ai sw=4 sts=4 ts=4 : */
2 b041e64c Eric Allman
3
/*
4 a901db09 Eric Allman
**        Status codes to string mappings
5 eaf2fd26 Eric Allman
**
6 055d3009 Eric Allman
**        ----- BEGIN LICENSE BLOCK -----
7
**        GDP: Global Data Plane Support Library
8
**        From the Ubiquitous Swarm Lab, 490 Cory Hall, U.C. Berkeley.
9
**
10 c87dd166 Eric Allman
**        Copyright (c) 2015-2019, Regents of the University of California.
11 6bd5476b Eric Allman
**        All rights reserved.
12 055d3009 Eric Allman
**
13 6bd5476b Eric Allman
**        Permission is hereby granted, without written agreement and without
14
**        license or royalty fees, to use, copy, modify, and distribute this
15
**        software and its documentation for any purpose, provided that the above
16
**        copyright notice and the following two paragraphs appear in all copies
17
**        of this software.
18 055d3009 Eric Allman
**
19 6bd5476b Eric Allman
**        IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
20
**        SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
21
**        PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
22
**        EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 055d3009 Eric Allman
**
24 6bd5476b Eric Allman
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
25 055d3009 Eric Allman
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 6bd5476b Eric Allman
**        FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
27
**        IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
28
**        OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
29
**        OR MODIFICATIONS.
30 055d3009 Eric Allman
**        ----- END LICENSE BLOCK -----
31 eaf2fd26 Eric Allman
*/
32 b041e64c Eric Allman
33 055d3009 Eric Allman
#include "gdp.h"
34 8cc28925 Eric Allman
#include "gdp_priv.h"
35
#include "gdp_pdu.h"
36 055d3009 Eric Allman
#include "gdp_stat.h"
37
38 8cc28925 Eric Allman
#include <ep/ep_dbg.h>
39
40
static EP_DBG        Dbg = EP_DBG_INIT("gdp_stat", "GDP status codes");
41 055d3009 Eric Allman
42 8cc28925 Eric Allman
/* TODO:        Verify that these strings are accurate.  */
43 51775f02 Eric Allman
44 a901db09 Eric Allman
static struct ep_stat_to_string Stats[] =
45 b041e64c Eric Allman
{
46 a901db09 Eric Allman
        // module name
47 ba9021ce Eric Allman
        { GDP_STAT_NEW(OK, 0),                                "Swarm-GDP",                                                },
48 b041e64c Eric Allman
49 a901db09 Eric Allman
        // individual codes
50 ba9021ce Eric Allman
        { GDP_STAT_MSGFMT,                                        "message format error",                                },
51
        { GDP_STAT_SHORTMSG,                                "incomplete message",                                },
52
        { GDP_STAT_READ_OVERFLOW,                        "read overflow",                                        },
53
        { GDP_STAT_NOT_IMPLEMENTED,                        "not implemented",                                        },
54
        { GDP_STAT_PDU_WRITE_FAIL,                        "network pdu write failure",                },
55
        { GDP_STAT_PDU_READ_FAIL,                        "network pdu read failure",                        },
56
        { GDP_STAT_PDU_VERSION_MISMATCH,        "protocol version mismatch",                },
57
        { GDP_STAT_PDU_NO_SEQ,                                "no sequence number",                                },
58
        { GDP_STAT_KEEP_READING,                        "more input needed",                                },
59 eae1d3ec Eric Allman
        { GDP_STAT_LOG_NOT_OPEN,                        "GDP log is not open",                                },
60 ba9021ce Eric Allman
        { GDP_STAT_UNKNOWN_RID,                                "request id unknown",                                },
61
        { GDP_STAT_INTERNAL_ERROR,                        "GDP internal error",                                },
62
        { GDP_STAT_BAD_IOMODE,                                "GDP bad I/O mode",                                        },
63 eae1d3ec Eric Allman
        { GDP_STAT_GDP_NAME_INVALID,                "invalid GDP name",                                        },
64 ba9021ce Eric Allman
        { GDP_STAT_BUFFER_FAILURE,                        "gdp_buf I/O failure",                                },
65 eae1d3ec Eric Allman
        { GDP_STAT_NULL_GIN,                                "GDP Instance required",                        },
66
        { GDP_STAT_NULL_GOB,                                "GDP Object required",                                },
67 ba9021ce Eric Allman
        { GDP_STAT_PROTOCOL_FAIL,                        "GDP protocol failure",                                },
68 92243bf4 Eric Allman
        { GDP_STAT_CORRUPT_LOG,                                "corrupt log data file",                        },
69 ba9021ce Eric Allman
        { GDP_STAT_DEAD_DAEMON,                                "lost connection to GDP",                        },
70 92243bf4 Eric Allman
        { GDP_STAT_LOG_VERSION_MISMATCH,        "log version mismatch",                                },
71 5c6e2b40 Eric Allman
        { GDP_STAT_READONLY,                                "cannot update read-only object",        },
72 02356366 Eric Allman
        { GDP_STAT_NOTFOUND,                                "cannot find requested object",                },
73
        { GDP_STAT_PDU_CORRUPT,                                "corrupt pdu",                                                },
74 49d76189 Eric Allman
        { GDP_STAT_CRYPTO_SKEY_REQUIRED,        "secret key required",                                },
75
        { GDP_STAT_CRYPTO_SKEY_MISSING,                "cannot find secret key",                        },
76 92243bf4 Eric Allman
        { GDP_STAT_LOG_READ_ERROR,                        "log read error",                                        },
77 f7307b63 Eric Allman
        { GDP_STAT_RECNO_SEQ_ERROR,                        "record out of sequence",                        },
78 caef25cd Eric Allman
        { GDP_STAT_CRYPTO_VRFY_FAIL,                "signature verification failure",        },
79 7b2b4d4c Eric Allman
        { GDP_STAT_PHYSIO_ERROR,            "physical I/O error on log",        },
80 c2e8809e Eric Allman
        { GDP_STAT_RECORD_EXPIRED,                        "record expired",                                        },
81 6a78b581 Eric Allman
        { GDP_STAT_USING_FREE_REQ,                        "trying to use free req",                        },
82 e539f4d3 Eric Allman
        { GDP_STAT_BAD_REFCNT,                                "invalid reference count",                        },
83 02356366 Eric Allman
        { GDP_STAT_RECORD_MISSING,                        "record missing (look elsewhere)",        },
84
        { GDP_STAT_RECORD_DUPLICATED,                "record duplicated",                                },
85 8701c522 Eric Allman
        { GDP_STAT_DATUM_REQUIRED,                        "missing required datum",                        },
86 23c926fa Eric Allman
        { GDP_STAT_SQLITE_ERROR,                        "other sqlite3 error",                                },
87 66ba1423 Eric Allman
        { GDP_STAT_INVOKE_TIMEOUT,                        "GDP command timeout",                                },
88 5a73c6ad Eric Allman
        { GDP_STAT_PDU_TOO_LONG,                        "PDU too long",                                                },
89 2af11a08 Eric Allman
        { GDP_STAT_CHAN_NOT_CONNECTED,                "cannot connect to router",                        },
90 9852be60 Eric Allman
        { GDP_STAT_METADATA_REQUIRED,                "logs must have metadata",                        },
91 bd278f2e Eric Allman
        { GDP_STAT_RESPONSE_SENT,                        "response already sent",                        },
92 1c4fea03 Eric Allman
        { GDP_STAT_NO_METADATA,                                "GDP log has no metadata",                        },
93 59c6c7e0 Eric Allman
        { GDP_STAT_NAME_UNKNOWN,                        "cannot resolve GDP name",                        },
94
        { GDP_STAT_MYSQL_ERROR,                                "other mysql error",                                },
95 caef25cd Eric Allman
        { GDP_STAT_CRYPTO_SIG_MISSING,                "signature missing",                                },
96
        { GDP_STAT_CRYPTO_NO_PUB_KEY,                "missing public key",                                },
97
        { GDP_STAT_CRYPTO_NO_SIG,                        "datum missing required signature",        },
98 80da996e Eric Allman
        { GDP_STAT_SVC_NAME_REQ,                        "service name required",                        },
99 f5cccbca Eric Allman
        { GDP_STAT_HONGD_UNAVAILABLE,                "human-to-GDPname directory unavailable",        },
100 1042a70f Eric Allman
        { GDP_STAT_CRYPTO_ERROR,                        "generic crypto error",                                },
101 bd278f2e Eric Allman
102
        // codes corresponding to command responses
103
        { GDP_STAT_ACK_END_OF_RESULTS,                "263 end of results",                                },
104 e77b2836 Eric Allman
105 1da6930e Eric Allman
        { GDP_STAT_NAK_BADREQ,                                "400 bad request",                                        },
106
        { GDP_STAT_NAK_UNAUTH,                                "401 unauthorized",                                        },
107
        { GDP_STAT_NAK_BADOPT,                                "402 bad option",                                        },
108
        { GDP_STAT_NAK_FORBIDDEN,                        "403 forbidden",                                        },
109
        { GDP_STAT_NAK_NOTFOUND,                        "404 not found",                                        },
110
        { GDP_STAT_NAK_METHNOTALLOWED,                "405 method not allowed",                        },
111
        { GDP_STAT_NAK_NOTACCEPTABLE,                "406 not acceptable",                                },
112
        { GDP_STAT_NAK_CONFLICT,                        "409 conflict",                                                },
113 24a0a636 Eric Allman
        { GDP_STAT_NAK_GONE,                                "410 gone",                                                        },
114 1da6930e Eric Allman
        { GDP_STAT_NAK_PRECONFAILED,                "412 precondition failed",                        },
115
        { GDP_STAT_NAK_TOOLARGE,                        "413 request entity too large",                },
116
        { GDP_STAT_NAK_UNSUPMEDIA,                        "415 unsupported media type",                },
117 7fdfaa3c Eric Allman
        { GDP_STAT_NAK_REC_MISSING,                        "430 missing record",                                },
118
        { GDP_STAT_NAK_REC_DUP,                                "431 duplicate record",                                },
119 704c6e35 Eric Allman
120 1da6930e Eric Allman
        { GDP_STAT_NAK_INTERNAL,                        "500 internal server error",                },
121
        { GDP_STAT_NAK_NOTIMPL,                                "501 not implemented",                                },
122
        { GDP_STAT_NAK_BADGATEWAY,                        "502 bad gateway",                                        },
123
        { GDP_STAT_NAK_SVCUNAVAIL,                        "503 service unavailable",                        },
124
        { GDP_STAT_NAK_GWTIMEOUT,                        "504 gateway timeout",                                },
125
        { GDP_STAT_NAK_PROXYNOTSUP,                        "505 proxying not supported",                },
126 6d70b9d9 Eric Allman
        { GDP_STAT_NAK_REPLICATE_FAIL,                "514 couldn't write W replicas",        },
127 ae509350 Eric Allman
128 1da6930e Eric Allman
        { GDP_STAT_NAK_NOROUTE,                                "600 no route available",                        },
129 704c6e35 Eric Allman
130 dec37a7b Eric Allman
        // specialized success/warning codes from gdp_name_parse
131
        { GDP_STAT_NAME_SHA,                                "old (insecure) GDPname",                        },
132
        { GDP_STAT_OK_NAME_HONGD,                        "human-oriented name directory",        },
133
        { GDP_STAT_OK_NAME_PNAME,                        "printable internal name",                        },
134
        { GDP_STAT_OK_NAME_HEX,                                "printable hexidecimal",                        },
135
136 a901db09 Eric Allman
        // end of list sentinel
137
        { EP_STAT_OK,                                                NULL                                                        },
138 eaf2fd26 Eric Allman
};
139 b041e64c Eric Allman
140
void
141 0314a7a7 Eric Allman
_gdp_stat_init(void)
142 b041e64c Eric Allman
{
143 a901db09 Eric Allman
        ep_stat_reg_strings(Stats);
144 b041e64c Eric Allman
}
145 8cc28925 Eric Allman
146
147
/*
148
**   Convert an ACK or NAK command code into an EP_STAT
149
*/
150
151
EP_STAT
152
_gdp_stat_from_acknak(int acknak)
153
{
154
        if (acknak >= GDP_ACK_MIN && acknak <= GDP_ACK_MAX)
155
                return GDP_STAT_FROM_ACK(acknak);
156
        if (acknak >= GDP_NAK_C_MIN && acknak <= GDP_NAK_C_MAX)
157
                return GDP_STAT_FROM_C_NAK(acknak);
158
        if (acknak >= GDP_NAK_S_MIN && acknak <= GDP_NAK_S_MAX)
159
                return GDP_STAT_FROM_S_NAK(acknak);
160
        if (acknak >= GDP_NAK_R_MIN && acknak <= GDP_NAK_R_MAX)
161
                return GDP_STAT_FROM_R_NAK(acknak);
162
163
        ep_dbg_cprintf(Dbg, 1, "_gdp_stat_from_acknak: code %d not an acknak\n",
164
                        acknak);
165
        return GDP_STAT_INTERNAL_ERROR;
166
}