src/error.c
author Tero Marttila <terom@fixme.fi>
Wed, 08 Apr 2009 01:28:46 +0300
changeset 120 576bab0a1c5a
parent 108 50ff7ac8a725
child 121 4682ebbc5644
permissions -rw-r--r--
modify config to support options with multiple params/values
6
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#include "error.h"
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
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: 10
diff changeset
     4
// for the error_desc tables
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: 10
diff changeset
     5
#include "sock.h"
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: 10
diff changeset
     6
#include "sock_gnutls.h"
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: 41
diff changeset
     7
#include "module.h"
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: 10
diff changeset
     8
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
     9
#include <string.h>
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
    10
#include <stdio.h>
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
    11
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: 10
diff changeset
    12
struct error_desc _core_error_desc[] = {
31
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    13
    {   ERR_CALLOC,                         "calloc",                                   ERR_EXTRA_NONE      },
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: 31
diff changeset
    14
    {   ERR_STRDUP,                         "strdup",                                   ERR_EXTRA_NONE      },
71
0a13030f795d implement signal_ignore using sigaction directly, without any libevent in between
Tero Marttila <terom@fixme.fi>
parents: 68
diff changeset
    15
    {   ERR_SIGACTION,                      "sigaction",                                ERR_EXTRA_ERRNO     },
108
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
    16
    {   ERR_ACCESS_READ,                    "access(R_OK)",                             ERR_EXTRA_ERRNO     },
31
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    17
    {   ERR_GETADDRINFO,                    "getaddrinfo",                              ERR_EXTRA_GAI       },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    18
    {   ERR_GETADDRINFO_EMPTY,              "getaddrinfo: no results",                  ERR_EXTRA_NONE      },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    19
    {   ERR_EVENT_NEW,                      "event_new",                                ERR_EXTRA_NONE      },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    20
    {   ERR_EVENT_ADD,                      "event_add",                                ERR_EXTRA_NONE      },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    21
    {   ERR_EVSQL_NEW_PQ,                   "evsql_new_pq",                             ERR_EXTRA_NONE      },
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
    22
    {   ERR_EVSQL_QUERY_EXEC,               "evsql_query_exec",                         ERR_EXTRA_NONE      },
63
d399a1d915a3 start reworking option-parsing, but --module/--config is still unimplemented
Tero Marttila <terom@fixme.fi>
parents: 57
diff changeset
    23
    {   ERR_CMD_OPT,                        "argv",                                     ERR_EXTRA_STR       },
31
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    24
    {   _ERR_INVALID,                       NULL,                                       0                   }
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
    25
31
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    26
}, _sock_error_desc[] = {
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    27
    {   ERR_SOCKET,                         "socket",                                   ERR_EXTRA_ERRNO     },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    28
    {   ERR_CONNECT,                        "connect",                                  ERR_EXTRA_ERRNO     },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    29
    {   ERR_READ,                           "read",                                     ERR_EXTRA_ERRNO     },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    30
    {   ERR_READ_EOF,                       "read: EOF",                                ERR_EXTRA_NONE      },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    31
    {   ERR_WRITE,                          "write",                                    ERR_EXTRA_ERRNO     },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    32
    {   ERR_WRITE_EOF,                      "write: EOF",                               ERR_EXTRA_NONE      },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    33
    {   ERR_FCNTL,                          "fcntl",                                    ERR_EXTRA_ERRNO     },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    34
    {   ERR_CLOSE,                          "close",                                    ERR_EXTRA_ERRNO     },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    35
    {   _ERR_INVALID,                       NULL,                                       0                   }
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: 10
diff changeset
    36
31
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    37
}, _sock_gnutls_error_desc[] = {
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    38
    {   ERR_GNUTLS_CERT_ALLOC_CRED,         "gnutls_certificate_allocate_credentials",  ERR_EXTRA_GNUTLS    },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    39
    {   ERR_GNUTLS_GLOBAL_INIT,             "gnutls_global_init",                       ERR_EXTRA_GNUTLS    },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    40
    {   ERR_GNUTLS_SET_DEFAULT_PRIORITY,    "gnutls_set_default_priority",              ERR_EXTRA_GNUTLS    },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    41
    {   ERR_GNUTLS_CRED_SET,                "gnutls_credentials_set",                   ERR_EXTRA_GNUTLS    },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    42
    {   ERR_GNUTLS_HANDSHAKE,               "gnutls_handshake",                         ERR_EXTRA_GNUTLS    },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    43
    {   ERR_GNUTLS_RECORD_SEND,             "gnutls_record_send",                       ERR_EXTRA_GNUTLS    },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    44
    {   ERR_GNUTLS_RECORD_RECV,             "gnutls_record_recv",                       ERR_EXTRA_GNUTLS    },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    45
    {   ERR_GNUTLS_RECORD_GET_DIRECTION,    "gnutls_record_get_direction",              ERR_EXTRA_GNUTLS    },
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    46
    {   _ERR_INVALID,                       NULL,                                       0                   }
98ea2bd59195 error.c formatting
Tero Marttila <terom@fixme.fi>
parents: 30
diff changeset
    47
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    48
}, _irc_error_desc[] = {
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: 31
diff changeset
    49
    {   ERR_LINE_TOO_LONG,                  "IRC line is too long",                     ERR_EXTRA_NONE      },
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: 31
diff changeset
    50
    {   ERR_LINE_INVALID_TOKEN,             "Illegal token value for IRC line",         ERR_EXTRA_NONE      },
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: 31
diff changeset
    51
    {   ERR_INVALID_NM,                     "Invalid nickmask",                         ERR_EXTRA_NONE      },
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: 31
diff changeset
    52
    {   ERR_INVALID_NICK_LENGTH,            "Nickname is too long",                     ERR_EXTRA_NONE      },
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    53
    
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    54
    // extra: the name of the invalid field
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    55
    {   ERR_IRC_NET_INFO,                   "invalid irc_net_info",                     ERR_EXTRA_STR       },
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    56
    {   ERR_IRC_NET_STATE,                  "invalid irc_net state for operation",      ERR_EXTRA_NONE      },
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    57
    {   ERR_IRC_CHAN_STATE,                 "invalid irc_chan state for operation",     ERR_EXTRA_NONE      },
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    58
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: 31
diff changeset
    59
    {   _ERR_INVALID,                       NULL,                                       0                   }
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    60
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    61
}, _config_error_desc[] = {
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    62
    // extra: the (unknown) config field name
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    63
    {   ERR_CONFIG_NAME,                    "no matching config name",                  ERR_EXTRA_STR       },
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    64
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    65
    // XXX: extra: the mismatching types
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    66
    {   ERR_CONFIG_TYPE,                    "wrong config type",                        ERR_EXTRA_NONE      },
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    67
    
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    68
    // extra: the name of the field with missing value
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    69
    {   ERR_CONFIG_REQUIRED,                "missing required value",                   ERR_EXTRA_STR       },
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    70
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    71
    {   _ERR_INVALID,                       NULL,                                       0                   }
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    72
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: 41
diff changeset
    73
}, _module_error_desc[] = {
108
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
    74
    {   ERR_MODULE_NAME,                    "invalid module name",                      ERR_EXTRA_NONE      },
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
    75
    {   ERR_MODULE_DUP,                     "module already loaded",                    ERR_EXTRA_NONE      },
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
    76
    {   ERR_MODULE_PATH,                    "invalid module path",                      ERR_EXTRA_STR       },
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    77
    {   ERR_MODULE_OPEN,                    "module dlopen() failed",                   ERR_EXTRA_STR       },
108
50ff7ac8a725 implement modules_path + module_load with NULL path
Tero Marttila <terom@fixme.fi>
parents: 106
diff changeset
    78
    {   ERR_MODULE_SYM,                     "module dlsym() failed",                    ERR_EXTRA_STR       },
57
ce1accba5fc7 slight cleanup to move module funcs to a 'struct module_funcs'
Tero Marttila <terom@fixme.fi>
parents: 56
diff changeset
    79
    {   ERR_MODULE_INIT_FUNC,               "invalid module init func",                 ERR_EXTRA_STR       },
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
    80
    {   ERR_MODULE_CONF,                    "module_conf",                              ERR_EXTRA_STR       },
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: 41
diff changeset
    81
    {   _ERR_INVALID,                       NULL,                                       0                   }
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    82
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    83
}, _lua_error_desc[] = {
106
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    84
    {   ERR_LUA_MEM,                        "lua: out of memory",                       ERR_EXTRA_STR       },
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    85
    {   ERR_LUA_SYNTAX,                     "lua: syntax error",                        ERR_EXTRA_STR       },
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    86
    {   ERR_LUA_RUN,                        "lua: runtime error",                       ERR_EXTRA_STR       },
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    87
    {   ERR_LUA_ERR,                        "lua: error handling error",                ERR_EXTRA_STR       },
f00661136ac2 add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents: 100
diff changeset
    88
    {   ERR_LUA_FILE,                       "lua: error loading file",                  ERR_EXTRA_STR       },
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    89
    {   _ERR_INVALID,                       NULL,                                       0                   }
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: 10
diff changeset
    90
};
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: 10
diff changeset
    91
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: 10
diff changeset
    92
/**
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: 10
diff changeset
    93
 * Array of error_desc tables
6
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
 */
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: 10
diff changeset
    95
static struct error_desc* _desc_tables[] = {
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: 10
diff changeset
    96
    _core_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: 10
diff changeset
    97
    _sock_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: 10
diff changeset
    98
    _sock_gnutls_error_desc,
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
    99
    _irc_error_desc,
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: 41
diff changeset
   100
    _module_error_desc,
100
cfb7776bd6f0 improve the config module futher, now the module_desc interface uses structured config_value's
Tero Marttila <terom@fixme.fi>
parents: 83
diff changeset
   101
    _lua_error_desc,
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: 10
diff changeset
   102
    NULL
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: 10
diff changeset
   103
};
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: 10
diff changeset
   104
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: 10
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: 10
diff changeset
   106
 * Look up the error_desc for the given 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: 10
diff changeset
   107
 */
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: 10
diff changeset
   108
static const struct error_desc* error_lookup_desc (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: 10
diff changeset
   109
{
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: 10
diff changeset
   110
    struct error_desc **desc_table, *desc = NULL;
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: 10
diff changeset
   111
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: 10
diff changeset
   112
    // iterate over each defined error_desc array
41
40f7aa051acb add line_proto test, enhance others
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   113
    for (desc_table = _desc_tables; *desc_table; desc_table++) {
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: 10
diff changeset
   114
        for (desc = *desc_table; desc->code && desc->name; 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: 10
diff changeset
   115
            // compare 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: 10
diff changeset
   116
            if (desc->code == 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: 10
diff changeset
   117
                // found
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: 10
diff changeset
   118
                return 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: 10
diff changeset
   119
        }
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: 10
diff changeset
   120
    }
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: 10
diff changeset
   121
    
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: 10
diff changeset
   122
    // not found
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: 10
diff changeset
   123
    return NULL;    
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: 10
diff changeset
   124
}
6
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   126
const char *error_name (err_t code)
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   127
{
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: 10
diff changeset
   128
    const struct error_desc *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: 10
diff changeset
   129
    
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: 10
diff changeset
   130
    // do we have an error_desc for it?
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: 10
diff changeset
   131
    if ((desc = error_lookup_desc(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: 10
diff changeset
   132
        return desc->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: 10
diff changeset
   133
    else
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: 10
diff changeset
   134
        // unknown
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: 10
diff changeset
   135
        return "[unknown]";
6
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   136
}
240ae8482d64 add error_name function
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   137
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
   138
const char *error_msg (const struct error_info *err)
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   139
{
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   140
    static char msg[ERROR_MSG_MAXLEN];
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: 10
diff changeset
   141
    const struct error_desc *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: 10
diff changeset
   142
    
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: 10
diff changeset
   143
    // do we have an error_desc for it?
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: 10
diff changeset
   144
    if ((desc = error_lookup_desc(err->code)) == NULL)
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: 10
diff changeset
   145
        // ???
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: 10
diff changeset
   146
        snprintf(msg, ERROR_MSG_MAXLEN, "[%#.8x]: %#.8x", err->code, err->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: 10
diff changeset
   147
    
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: 10
diff changeset
   148
    else
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: 10
diff changeset
   149
        // intrepret .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: 10
diff changeset
   150
        switch (desc->extra_type) {
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: 10
diff changeset
   151
            case ERR_EXTRA_NONE:
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: 10
diff changeset
   152
                // no additional info
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: 10
diff changeset
   153
                snprintf(msg, ERROR_MSG_MAXLEN, "%s", desc->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: 10
diff changeset
   154
                break;
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: 10
diff changeset
   155
            
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: 10
diff changeset
   156
            case 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: 10
diff changeset
   157
                // 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: 10
diff changeset
   158
                snprintf(msg, ERROR_MSG_MAXLEN, "%s: %s", desc->name, strerror(err->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: 10
diff changeset
   159
                break;
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: 10
diff changeset
   160
            
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: 10
diff changeset
   161
            case 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: 10
diff changeset
   162
                // 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: 10
diff changeset
   163
                snprintf(msg, ERROR_MSG_MAXLEN, "%s: %s", desc->name, gai_strerror(err->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: 10
diff changeset
   164
                break;
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: 10
diff changeset
   165
            
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: 10
diff changeset
   166
            case ERR_EXTRA_GNUTLS:
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: 10
diff changeset
   167
                // gnutls_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: 10
diff changeset
   168
                snprintf(msg, ERROR_MSG_MAXLEN, "%s: %s", desc->name, gnutls_strerror(err->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: 10
diff changeset
   169
                break;
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: 10
diff changeset
   170
            
56
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   171
            case ERR_EXTRA_STR:
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   172
                // static error message string
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   173
                snprintf(msg, ERROR_MSG_MAXLEN, "%s: %s", desc->name, err->extra_str);
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   174
                break;
942370000450 compiling, working, but still ugly module code
Tero Marttila <terom@fixme.fi>
parents: 55
diff changeset
   175
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: 10
diff changeset
   176
            default:
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: 10
diff changeset
   177
                // ???
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: 10
diff changeset
   178
                snprintf(msg, ERROR_MSG_MAXLEN, "%s: %#.8x", desc->name, err->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: 10
diff changeset
   179
                break;
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: 10
diff changeset
   180
        }   
7
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   181
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   182
    // return static pointer
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   183
    return msg;
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   184
}
844f014409ff and then error_msg
Tero Marttila <terom@fixme.fi>
parents: 6
diff changeset
   185