src/error.h
author Tero Marttila <terom@fixme.fi>
Mon, 30 Mar 2009 01:31:27 +0300
changeset 87 f0db6ebf18b9
parent 83 c8e2dac08207
child 93 42ade8285570
permissions -rw-r--r--
documentation tweaks
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef ERROR_H
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define ERROR_H
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     4
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     5
 * @file
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
     6
 *
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
 * Error-handling functions
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
 */
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
#include <errno.h>
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    11
/**
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    12
 * The type used for error codes is an explicitly *unsigned* int, meaning that error codes themselves are positive.
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    13
 * Negative error codes (as signed ints) also exist in some places, and they are just a negative err_t.
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
 */
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
typedef unsigned int err_t;
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    17
/**
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    18
 * Ways to interpret error_info.extra
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
    19
 */
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
    20
enum error_extra_types {
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    21
    /** No extra info */
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    22
    ERR_EXTRA_NONE      = 0,
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
    23
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    24
    /** libc errno, using strerror() */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    25
    ERR_EXTRA_ERRNO,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    26
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    27
    /** libc resolver, using gai_strerror() */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    28
    ERR_EXTRA_GAI,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    29
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    30
    /** GnuTLS, using gnutls_strerror() */
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    31
    ERR_EXTRA_GNUTLS,
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    32
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    33
    /** Static error message string */
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    34
    ERR_EXTRA_STR,
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
    35
};
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
    36
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    37
/**
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
 * List of defined error codes, organized mostly by function name
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
 */
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
enum error_code {
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    41
    _ERR_INVALID    = 0x000000,
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
    
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    43
    /** stdlib.h functions */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    44
    _ERR_STDLIB     = 0x000100,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    45
    ERR_CALLOC,
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    46
    ERR_STRDUP,
71
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
    47
    ERR_SIGACTION,
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    48
    
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    49
    /** DNS resolver */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    50
    _ERR_RESOLVER   = 0x000200,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    51
    ERR_GETADDRINFO,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    52
    ERR_GETADDRINFO_EMPTY, 
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    53
    
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    54
    /** @see sock_error_code*/
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    55
    _ERR_SOCK       = 0x000300,
4
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
    56
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    57
    /** @see sock_gnutls_error_code */
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    58
    _ERR_GNUTLS     = 0x000400,
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    59
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    60
    /** Libevent errors */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    61
    _ERR_LIBEVENT   = 0x000500,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    62
    ERR_EVENT_NEW,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    63
    ERR_EVENT_ADD,
17
5001564ac5fc irc_line implementation
Tero Marttila <terom@fixme.fi>
parents: 12
diff changeset
    64
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    65
    /** Evsql errors */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    66
    _ERR_EVSQL      = 0x000600,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    67
    ERR_EVSQL_NEW_PQ,
68
591a574f390e add FindEvsql/FindLibPQ cmake modules and irc_log.sql definition, and implement logging of JOIN, PART, MODE, TOPIC, KICK, PRIVMSG, NOTICE and OPEN messages
Tero Marttila <terom@fixme.fi>
parents: 63
diff changeset
    68
    ERR_EVSQL_QUERY_EXEC,
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 17
diff changeset
    69
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    70
    /** irc_proto errors */
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    71
    _ERR_IRC_LINE   = 0x000700,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    72
    ERR_LINE_TOO_LONG,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    73
    ERR_LINE_INVALID_TOKEN,
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    74
    ERR_INVALID_NM,
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 34
diff changeset
    75
    ERR_INVALID_NICK_LENGTH,
27
e6639132bead add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    76
e6639132bead add irc_conn_callbacks, and delay irc_chan_join until on_registered
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    77
    /** irc_conn errors */
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    78
    _ERR_IRC_CONN   = 0x000800,
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    79
    ERR_IRC_CONN_REGISTER_STATE,
48
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    80
    ERR_IRC_CONN_QUIT_STATE,
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    81
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    82
    /** irc_net errors */
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    83
    _ERR_IRC_NET    = 0x000900,
4841f4398fd2 add irc_net_quit and signal handling
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    84
    ERR_IRC_NET_QUIT_STATE,
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    85
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    86
    /** @see module_error_code */
55
6f7f6ae729d0 'working' modules code, and convert irc_log to use said interface, but we've hit the limits on our Makefile, and the compiled module doesn't really work
Tero Marttila <terom@fixme.fi>
parents: 48
diff changeset
    87
    _ERR_MODULE     = 0x000a00,
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    88
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    89
    /** config errors */
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    90
    _ERR_CONFIG     = 0x000b00,
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    91
    ERR_CONFIG_NAME,
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    92
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    93
    /** General errors */
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    94
    _ERR_GENERAL    = 0xffff00,
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    95
    ERR_CMD_OPT,
83
c8e2dac08207 add config module and modify irc_log/nexus to use it
Tero Marttila <terom@fixme.fi>
parents: 71
diff changeset
    96
30
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    97
};
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    98
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
    99
/**
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   100
 * Table of error descriptions
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   101
 */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   102
struct error_desc {
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   103
    /** The flat error code */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   104
    err_t code;
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   105
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   106
    /** The short name */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   107
    const char *name;
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   108
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   109
    /** How to interpret .extra */
7f8dd120933f rework error to use a struct error_desc, and move ERR_SOCK/ERR_GNUTLS definitions to sock.h/sock_gnutls.h. error_desc definitions are still in error.c, though :(
Tero Marttila <terom@fixme.fi>
parents: 29
diff changeset
   110
    enum error_extra_types extra_type;
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   111
};
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   112
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   113
/**
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   114
 * An error code and associated extra infos
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   115
 */
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   116
struct error_info {
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   117
    /** The base error code */
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   118
    err_t code;
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   119
    
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   120
    union {
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   121
        /** Additional detail info, usually some third-party error code, as defined by the code's ERR_EXTRA_* */
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   122
        int extra;
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   123
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   124
        /** Additional info, stored as a pointer to a static string (note how dangerous this is) */
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   125
        const char *extra_str;
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   126
    };
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   127
};
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   129
/**
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   130
 * Translate an err_t into a function name.
6
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
   131
 */
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
   132
const char *error_name (err_t code);
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents: 5
diff changeset
   133
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   134
/**
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   135
 * Maximum length of error messages returned by error_msg (including NUL byte)
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   136
 */
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   137
#define ERROR_MSG_MAXLEN 1024
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   138
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   139
/**
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   140
 * Translate an error_info into a message.
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   141
 *
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   142
 * This is returned as a pointer into a statically allocated buffer. It is not re-entrant.
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   143
 */
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   144
const char *error_msg (const struct error_info *err);
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   145
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   146
/** No error, evaulates as logical false */
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   147
#define SUCCESS (0)
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   148
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   149
/** Evaulates to error_info.code as lvalue */
4
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   150
#define ERROR_CODE(err_info_ptr) ((err_info_ptr)->code)
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   151
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   152
/** Evaulates to error_info.extra as lvalue */
4
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   153
#define ERROR_EXTRA(err_info_ptr) ((err_info_ptr)->extra)
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   154
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   155
/** Set error_info.code to SUCCESS, evaulates as zero */
4
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   156
#define RESET_ERROR(err_info_ptr) ((err_info_ptr)->code = SUCCESS)
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   157
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   158
/** Compare error_info.code != 0 */
4
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   159
#define IS_ERROR(err_info_ptr) (!!(err_info_ptr)->code)
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   160
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   161
/** Compare the err_code/err_extra for an err_info */
10
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   162
#define MATCH_ERROR(err_info_ptr, err_code, err_extra) ((err_info_ptr)->code == (err_code) && (err_info_ptr)->extra == (err_extra))
9fe218576d13 fix sock_stream read/write return value, move line buffer inside of line_proto, add some initial code for event-based non-blocking operation
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
   163
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   164
/** Set error_info.code, but leave err_extra as-is. Evaluates to err_code */
4
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   165
#define SET_ERROR(err_info_ptr, err_code) ((err_info_ptr)->code = (err_code))
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   166
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   167
/** Set error_info.code/extra. XXX: should evaluate to err_code */
4
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   168
#define _SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra) (err_info_ptr)->code = (err_code); (err_info_ptr)->extra = (err_extra)
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   169
#define SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra) do { _SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra); } while (0)
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   170
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   171
/** Set error_info.code to err_code, and .extra to errno. XXX: should evaulate to err_code */
4
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   172
#define _SET_ERROR_ERRNO(err_info_ptr, err_code) _SET_ERROR_EXTRA(err_info_ptr, err_code, errno);
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   173
#define SET_ERROR_ERRNO(err_info_ptr, err_code) SET_ERROR_EXTRA(err_info_ptr, err_code, errno);
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   174
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   175
/** 
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   176
 * Set error_info.code to err_code, and .extra_str to str. The given string pointer should remain valid while the error
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   177
 * is being handled down-stack.
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   178
 */
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   179
#define _SET_ERROR_STR(err_info_ptr, err_code, err_str) (err_info_ptr)->code = (err_code); (err_info_ptr)->extra_str = (err_str)
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   180
#define SET_ERROR_STR(err_info_ptr, err_code, err_str) do { _SET_ERROR_STR(err_info_ptr, err_code, err_str); } while(0)
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   181
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   182
/** Set error_info from another error_info. Evaluates to the new error_info */
5
a09a0797f6f0 ERROR-ify sock_gnutls
Tero Marttila <terom@fixme.fi>
parents: 4
diff changeset
   183
#define SET_ERROR_INFO(err_info_ptr, from_ptr) (*err_info_ptr = *from_ptr)
a09a0797f6f0 ERROR-ify sock_gnutls
Tero Marttila <terom@fixme.fi>
parents: 4
diff changeset
   184
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   185
/** Same as above, but also return err_code from func. XXX: use 'return SET_ERROR...' instead */
5
a09a0797f6f0 ERROR-ify sock_gnutls
Tero Marttila <terom@fixme.fi>
parents: 4
diff changeset
   186
#define RETURN_SET_ERROR(err_info_ptr, err_code) do { SET_ERROR(err_info_ptr, err_code); return (err_code); } while (0)
4
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   187
#define RETURN_SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra) do { _SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra); return (err_code); } while (0)
a3ca0f97a075 change ERROR_* to use pointers again, and implement error_info for sock_init
Tero Marttila <terom@fixme.fi>
parents: 3
diff changeset
   188
#define RETURN_SET_ERROR_ERRNO(err_info_ptr, err_code) do { _SET_ERROR_ERRNO(err_info_ptr, err_code); return (err_code); } while (0)
8
be88e543c8ff split off line_proto, and make sock_stream_error return a const error_info
Tero Marttila <terom@fixme.fi>
parents: 7
diff changeset
   189
#define RETURN_SET_ERROR_INFO(err_info_ptr, from_ptr) do { SET_ERROR_INFO(err_info_ptr, from_ptr); return (from_ptr->code); } while (0)
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   190
#define RETURN_SET_ERROR_STR(err_info_ptr, err_code, err_str) do { _SET_ERROR_STR(err_info_ptr, err_code, err_str); return (err_code); } while (0)
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   191
34
763f65f9df0c add doxygen.conf, and tweak comments
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
   192
/** Same as above, but also do a 'goto error' */
5
a09a0797f6f0 ERROR-ify sock_gnutls
Tero Marttila <terom@fixme.fi>
parents: 4
diff changeset
   193
#define JUMP_SET_ERROR(err_info_ptr, err_code) do { SET_ERROR(err_info_ptr, err_code); goto error; } while (0)
87
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   194
#define JUMP_SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra) do { _SET_ERROR_EXTRA(err_info_ptr, err_code, err_extra); goto error; } while (0)
f0db6ebf18b9 documentation tweaks
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   195
#define JUMP_SET_ERROR_ERRNO(err_info_ptr, err_code) do { _SET_ERROR_ERRNO(err_info_ptr, err_code); goto error; } while (0)
5
a09a0797f6f0 ERROR-ify sock_gnutls
Tero Marttila <terom@fixme.fi>
parents: 4
diff changeset
   196
#define JUMP_SET_ERROR_INFO(err_info_ptr, from_ptr) do { SET_ERROR_INFO(err_info_ptr, from_ptr); goto error; } while (0)
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
   197
#define JUMP_SET_ERROR_STR(err_info_ptr, err_code, err_str) do { _SET_ERROR_STR(err_info_ptr, err_code, err_str); goto error; } while (0)
5
a09a0797f6f0 ERROR-ify sock_gnutls
Tero Marttila <terom@fixme.fi>
parents: 4
diff changeset
   198
3
cc94ae754e2a error handling magic
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   199
#endif