src/lua_irc.c
changeset 142 dc2bb09d412c
parent 141 0b850238c588
child 143 1edab39c88a8
equal deleted inserted replaced
141:0b850238c588 142:dc2bb09d412c
   147     lua_obj_create_type(L, "evirc.net", lua_net_methods);
   147     lua_obj_create_type(L, "evirc.net", lua_net_methods);
   148 }
   148 }
   149 
   149 
   150 static int lua_client_set_defaults (lua_State *L)
   150 static int lua_client_set_defaults (lua_State *L)
   151 {
   151 {
       
   152     int nargs = lua_gettop(L);
   152     struct lua_client *lua_client = lua_obj_get_obj(L, __func__, "evirc.client");
   153     struct lua_client *lua_client = lua_obj_get_obj(L, __func__, "evirc.client");
   153 
   154 
   154     // required args
   155     // required args
   155     lua_client->defaults.register_info.nickname = lua_arg_string(L, 2, "nickname", LUA_ARG_STRING_REQUIRED);
   156     lua_client->defaults.register_info.nickname = lua_arg_string(L, nargs, 2, "nickname", LUA_ARG_STRING_REQUIRED);
   156     lua_client->defaults.register_info.username = lua_arg_string(L, 3, "username", LUA_ARG_STRING_REQUIRED);
   157     lua_client->defaults.register_info.username = lua_arg_string(L, nargs, 3, "username", LUA_ARG_STRING_REQUIRED);
   157     lua_client->defaults.register_info.realname = lua_arg_string(L, 4, "realname", LUA_ARG_STRING_REQUIRED);
   158     lua_client->defaults.register_info.realname = lua_arg_string(L, nargs, 4, "realname", LUA_ARG_STRING_REQUIRED);
   158 
   159 
   159     // optional args
   160     // optional args
   160     lua_client->defaults.service        = lua_arg_string(L, 5, "service", IRC_PORT);
   161     lua_client->defaults.service        = lua_arg_string(L, nargs, 5, "service", IRC_PORT);
   161     lua_client->defaults.service_ssl    = lua_arg_string(L, 6, "service_ssl", IRC_SSL_PORT);
   162     lua_client->defaults.service_ssl    = lua_arg_string(L, nargs, 6, "service_ssl", IRC_SSL_PORT);
   162 
   163 
   163     // invoke
   164     // invoke
   164     irc_client_set_defaults(lua_client->client, &lua_client->defaults);
   165     irc_client_set_defaults(lua_client->client, &lua_client->defaults);
   165 
   166 
   166     // ok
   167     // ok
   167     return 0;
   168     return 0;
   168 }
   169 }
   169 
   170 
   170 static int lua_client_connect (lua_State *L)
   171 static int lua_client_connect (lua_State *L)
   171 {
   172 {
       
   173     int nargs = lua_gettop(L);
   172     struct lua_client *lua_client = lua_obj_get_obj(L, __func__, "evirc.client");
   174     struct lua_client *lua_client = lua_obj_get_obj(L, __func__, "evirc.client");
   173     struct irc_net_info net_info;
   175     struct irc_net_info net_info;
   174     const char *ssl_cafile = NULL, *ssl_cert = NULL, *ssl_pkey = NULL;
   176     const char *ssl_cafile = NULL, *ssl_cert = NULL, *ssl_pkey = NULL;
   175     bool use_ssl = false, ssl_verify = false;
   177     bool use_ssl = false, ssl_verify = false;
   176     struct irc_net *net;
   178     struct irc_net *net;
   178 
   180 
   179     // init net_info
   181     // init net_info
   180     memset(&net_info, 0, sizeof(net_info));
   182     memset(&net_info, 0, sizeof(net_info));
   181 
   183 
   182     // required args
   184     // required args
   183     net_info.network    = lua_arg_string(L, 2, "network",       LUA_ARG_STRING_REQUIRED);
   185     net_info.network    = lua_arg_string(L, nargs, 2, "network",    LUA_ARG_STRING_REQUIRED);
   184     net_info.hostname   = lua_arg_string(L, 3, "hostname",      LUA_ARG_STRING_REQUIRED);
   186     net_info.hostname   = lua_arg_string(L, nargs, 3, "hostname",   LUA_ARG_STRING_REQUIRED);
   185 
   187 
   186     // optional args
   188     // optional args
   187     net_info.service    = lua_arg_string(L, 4, "service",       NULL);
   189     net_info.service    = lua_arg_string(L, nargs, 4, "service",    NULL);
   188 
   190 
   189     // ssl stuff
   191     // ssl stuff
   190     use_ssl             = lua_arg_bool  (L, 5, "use_ssl",       false);
   192     use_ssl             = lua_arg_bool  (L, nargs, 5, "use_ssl",    false);
   191     ssl_cafile          = lua_arg_string(L, 6, "ssl_cafile",    NULL);
   193     ssl_cafile          = lua_arg_string(L, nargs, 6, "ssl_cafile", NULL);
   192     ssl_verify          = lua_arg_bool  (L, 7, "ssl_verify",    false);
   194     ssl_verify          = lua_arg_bool  (L, nargs, 7, "ssl_verify", false);
   193     ssl_cert            = lua_arg_string(L, 8, "ssl_cert",      NULL);
   195     ssl_cert            = lua_arg_string(L, nargs, 8, "ssl_cert",   NULL);
   194     ssl_pkey            = lua_arg_string(L, 9, "ssl_pkey",      NULL);
   196     ssl_pkey            = lua_arg_string(L, nargs, 9, "ssl_pkey",   NULL);
   195 
   197 
   196     // SSL?
   198     // SSL?
   197     if (use_ssl || ssl_cafile || ssl_verify || ssl_cert || ssl_pkey) {
   199     if (use_ssl || ssl_cafile || ssl_verify || ssl_cert || ssl_pkey) {
   198         // verify
   200         // verify
   199         if ((ssl_cert || ssl_pkey) && !(ssl_cert && ssl_pkey))
   201         if ((ssl_cert || ssl_pkey) && !(ssl_cert && ssl_pkey))