lm_connection.c
author Myhailo Danylenko <isbear@ukrpost.net>
Tue, 19 May 2009 02:12:02 +0300
changeset 23 13f03e604c8a
parent 19 d775d7289fe4
child 30 21547232c875
permissions -rw-r--r--
License notes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     1
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     2
/* Copyright 2009 Myhailo Danylenko
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     3
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     4
This file is part of lua-lm.
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     5
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     6
lua-lm is free software: you can redistribute it and/or modify
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     7
it under the terms of the GNU General Public License as published by
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     8
the Free Software Foundation, either version 2 of the License, or
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
     9
(at your option) any later version.
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    10
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    11
This program is distributed in the hope that it will be useful,
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    14
GNU General Public License for more details.
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    15
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    16
You should have received a copy of the GNU General Public License
13f03e604c8a License notes
Myhailo Danylenko <isbear@ukrpost.net>
parents: 19
diff changeset
    17
along with this program.  If not, see <http://www.gnu.org/licenses/>. */
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    18
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    19
#include <lua.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    20
#include <lauxlib.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    21
#include <glib.h>			// GDestroyNotify, GMainContext
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
#include <loudmouth/loudmouth.h>
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    23
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    24
#include "config.h"
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
#include "util.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    26
#include "lm_types.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    27
#include "lm_message.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
#include "lm_message_handler.h"
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    29
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    30
/// lm.connection
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    31
/// Central module, representing connection to the server.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    32
/// You should create a new connection object, then open it (establish
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    33
/// connection), then authenticate to the server.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    34
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    35
/// connection state
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    36
/// Stirng, representing current connection state.
4
5770be2d5f3f Documentation updates
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    37
/// G:
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    38
const string2enum_t state_lm_connection[] = {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    39
	{ "closed",         LM_CONNECTION_STATE_CLOSED         },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    40
	{ "opening",        LM_CONNECTION_STATE_OPENING        },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    41
	{ "open",           LM_CONNECTION_STATE_OPEN           },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    42
	{ "authenticating", LM_CONNECTION_STATE_AUTHENTICATING },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    43
	{ "authenticated",  LM_CONNECTION_STATE_AUTHENTICATED  },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    44
	{ NULL,             0                                  }, // XXX
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    45
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    46
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    47
/// handler priority
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48
/// String, according to which handler will be placed into one
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    49
/// of three handler groups.
4
5770be2d5f3f Documentation updates
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    50
/// G:
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    51
const string2enum_t priority_lm_handler[] = {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    52
	{ "last",   LM_HANDLER_PRIORITY_LAST   },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    53
	{ "normal", LM_HANDLER_PRIORITY_NORMAL },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    54
	{ "first",  LM_HANDLER_PRIORITY_FIRST  },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    55
	{ NULL,     0                          }, // XXX
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    56
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    57
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    58
/// disconnect reason
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    59
/// String, indicating the reason of disconnection occured.
4
5770be2d5f3f Documentation updates
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    60
/// G:
5770be2d5f3f Documentation updates
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1
diff changeset
    61
static const string2enum_t llm_disconnect_reason[] = {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    62
	{ "ok",                LM_DISCONNECT_REASON_OK                },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    63
	{ "ping time out",     LM_DISCONNECT_REASON_PING_TIME_OUT     },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
	{ "hup",               LM_DISCONNECT_REASON_HUP               },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    65
	{ "error",             LM_DISCONNECT_REASON_ERROR             },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    66
	{ "resource conflict", LM_DISCONNECT_REASON_RESOURCE_CONFLICT },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    67
	{ "invalid xml",       LM_DISCONNECT_REASON_INVALID_XML       },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    68
	{ "unknown",           LM_DISCONNECT_REASON_UNKNOWN           },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    69
	{ "ping_time_out",     LM_DISCONNECT_REASON_PING_TIME_OUT     },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    70
	{ "resource_conflict", LM_DISCONNECT_REASON_RESOURCE_CONFLICT },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    71
	{ "invalid_xml",       LM_DISCONNECT_REASON_INVALID_XML       },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    72
	{ NULL,                0                                      }, // XXX
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    73
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    74
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    75
/// lm.connection.new
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    76
/// Creates a new connection (closed).
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    77
/// A: string (server name), lightuserdata (C glib main context object, optional)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    78
/// R: lm connection object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    79
static int new_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    80
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    81
	const char *server = luaL_checkstring (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    82
	LmConnection *connection;
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    83
	if (lua_gettop (L) < 2)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    84
		connection = lm_connection_new (server);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    85
	else {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    86
		luaL_argcheck (L, lua_islightuserdata (L, 2), 2, "glib main context lightuserdata expected");
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    87
		connection = lm_connection_new_with_context (server, (GMainContext *) lua_touserdata (L, 2));
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    88
	}
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
    89
	bless_lm_connection (L, connection);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    90
	lm_connection_unref (connection);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    91
	D ("Connection %X created", (int) connection);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    92
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    93
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    94
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    95
/// lm.connection.bless
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    96
/// Blesses given pointer to lm connection object.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    97
/// Note: it adds a reference to connection.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    98
/// A: lightuserdata (C lm connection object)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    99
/// R: lm connection object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   100
static int bless_lua_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   101
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   102
	luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "loudmouth connection lightuserdata expected");
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   103
	bless_lm_connection (L, (LmConnection *) lua_touserdata (L, 1));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   104
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   105
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   106
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   107
/// connection callback function
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   108
/// User function, that will be called on connection establishment operation end,
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   109
/// eg. successful/unsuccessful opening or authentication.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   110
/// A: lm connection object, boolean (success)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   111
static void callback_lm_connection (LmConnection *connection, int success, llm_callback_t *cb)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   112
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   113
	lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   114
	bless_lm_connection (cb->L, connection);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   115
	// XXX lm_connection_unref (connection);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   116
	lua_pushboolean (cb->L, success);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   117
	if (lua_pcall (cb->L, 2, 0, 0)) {
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   118
		W ("Connection callback error: %s", lua_tostring (cb->L, -1));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   119
		lua_pop (cb->L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   120
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   121
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   122
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   123
/// connection:open
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   124
/// Opens connection to the server and then calls callback function.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   125
/// A: connection callback function
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   126
/// R: lm connection object or nil, string (error message)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   127
static int open_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   128
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   129
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   130
	llm_callback_t *cb;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   131
	luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   132
	GError *err;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   133
	
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   134
	cb = luaL_malloc (L, sizeof (llm_callback_t));
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   135
	cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   136
	cb->L         = L;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   137
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   138
	if (lm_connection_open (object->connection, (LmResultFunction) callback_lm_connection,
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   139
				 cb, (GDestroyNotify) llm_callback_destroy, &err))
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   140
		return 1;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   141
	else {
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   142
		lua_pushnil (L);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   143
		lua_pushstring (L, err->message);
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   144
		I ("Connection opening failed");
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   145
		return 2;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   146
	}
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   147
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   148
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   149
/// connection:authenticate
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   150
/// Tries to authenticate against opened connection, then calls callback function.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   151
/// A: string (username), string (password), string (resource), connection callback function
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   152
/// R: lm connection object or nil, string (error message)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   153
static int authenticate_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   154
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   155
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   156
	const char *username = luaL_checkstring (L, 2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   157
	const char *password = luaL_checkstring (L, 3);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   158
	const char *resource = luaL_checkstring (L, 4);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   159
	llm_callback_t *cb;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   160
	int status;
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   161
	GError *err = NULL;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   162
	luaL_argcheck (L, lua_isfunction (L, 5), 5, "function expected");
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   163
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   164
	cb = luaL_malloc (L, sizeof (llm_callback_t));
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   165
	cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   166
	cb->L         = L;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   167
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   168
	if (lm_connection_authenticate (object->connection, username, password, resource,
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   169
						(LmResultFunction) callback_lm_connection, cb,
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   170
						(GDestroyNotify) llm_callback_destroy, &err)) {
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   171
		lua_pop (L, 3);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   172
		return 1;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   173
	} else {
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   174
		lua_pushnil (L);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   175
		lua_pushstring (L, err->message);
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   176
		I ("Connection authentication failed: %s", err->message);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   177
		return 2;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   178
	}
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   179
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   180
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   181
/// connection:port
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   182
/// Gets or sets server port to connect.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   183
/// A: integer (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   184
/// R: integer (when called with no args) or lm connection object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   185
static int port_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   186
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   187
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   188
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   189
		lm_connection_set_port (object->connection, luaL_checkint (L, 2));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   190
		lua_pop (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   191
	} else { // Get
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   192
		lua_pushnumber (L, lm_connection_get_port (object->connection));
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   193
	}
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   194
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   195
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   196
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   197
/// connection:server
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   198
/// Gets or sets server to connect to.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   199
/// A: string (optional, server name)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   200
/// R: string (when called with no args) or lm connection object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   201
static int server_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   202
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   203
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   204
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   205
		lm_connection_set_server (object->connection, luaL_checkstring (L, 2));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   206
		lua_pop (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   207
	} else { // Get
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   208
		lua_pushstring (L, lm_connection_get_server (object->connection));
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   209
	}
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   210
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   211
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   212
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   213
/// connection:jid
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   214
/// Gets or sets jid for connection.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   215
/// A: string (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   216
/// R: string (when called with no args) or lm connection object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   217
static int jid_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   218
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   219
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   220
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   221
		lm_connection_set_jid (object->connection, luaL_checkstring (L, 2));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   222
		lua_pop (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   223
	} else { // Get
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   224
		lua_pushstring (L, lm_connection_get_jid (object->connection));
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   225
	}
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   226
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   227
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   228
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   229
/// connection:keep_alive_rate
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   230
/// Gets or sets keep alive packets rate for connection.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   231
/// Note, that on some platforms there is no get function even in
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   232
/// loudmouth versions, that should have it according to documentation.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   233
/// integer (optional, seconds)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   234
/// integer (when called with no args) or lm connection object or nil, string (error message, when get function is not available in loudmouth)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   235
static int keep_alive_rate_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   236
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   237
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   238
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   239
		lm_connection_set_keep_alive_rate (object->connection, luaL_checkint (L, 2));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   240
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   241
		return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   242
	} else { // Get
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   243
#ifdef HAVE_LM_CONNECTION_GET_KEEP_ALIVE_RATE
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   244
		lua_pushnumber (L, lm_connection_get_keep_alive_rate (object->connection));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   245
		return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   246
#else
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   247
		W ("Sorry, your loudmouth have no get_keep_alive_rate ()");
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   248
		lua_pushnil (L);
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   249
		lua_pushliteral (L, "Sorry, your loudmouth have no get_keep_alive_rate ()");
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   250
		return 2;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   251
#endif
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   252
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   253
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   254
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   255
/// connection:proxy
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   256
/// Gets or sets proxy server for connection.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   257
/// A: lm proxy object (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   258
/// R: lm proxy object or nil (when called with no args) or lm connection object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   259
static int proxy_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   260
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   261
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   262
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   263
		llm_proxy_t *proxy = luaL_checklm_proxy (L, 2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   264
		lm_connection_set_proxy (object->connection, proxy->proxy);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   265
		lua_pop (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   266
	} else { // Get
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   267
		LmProxy *proxy = lm_connection_get_proxy (object->connection);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   268
		lua_pop (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   269
		if (proxy) {
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   270
			bless_lm_proxy (L, proxy);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   271
			// XXX lm_proxy_unref (proxy);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   272
		} else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   273
			lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   274
	}
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   275
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   276
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   277
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   278
/// connection:ssl
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   279
/// Gets or sets ssl object for connection.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   280
/// A: lm ssl object (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   281
/// R: lm ssl object or nil (when called with no args) or lm connection object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   282
static int ssl_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   283
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   284
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   285
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   286
		llm_ssl_t *ssl = luaL_checklm_ssl (L, 2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   287
		lm_connection_set_ssl (object->connection, ssl->ssl);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   288
		lua_pop (L, 1);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   289
	} else { // Get
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   290
		LmSSL *ssl = lm_connection_get_ssl (object->connection);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   291
		lua_pop (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   292
		if (ssl) {
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   293
			bless_lm_ssl (L, ssl);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   294
			// XXX lm_ssl_unref (ssl);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   295
		} else
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   296
			lua_pushnil (L);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   297
	}
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   298
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   299
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   300
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   301
/// connection:close
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   302
/// Close connection.
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   303
/// R: lm connection object or nil, string (error message)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   304
static int close_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   305
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   306
	llm_connection_t *object = luaL_checklm_connection (L, 1);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   307
	GError *err = NULL;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   308
	if (lm_connection_close (object->connection, &err))
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   309
		return 1;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   310
	else {
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   311
		I ("Connection close failed: %s", err->message);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   312
		lua_pushnil (L);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   313
		lua_pushstring (L, err->message);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   314
		return 2;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   315
	}
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   316
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   317
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   318
/// connection:status
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   319
/// Returns string, describing connection state.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   320
/// R: connection state
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   321
static int status_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   322
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   323
	llm_connection_t *connection = luaL_checklm_connection (L, 1);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   324
	luaL_pushenum (L, lm_connection_get_state (connection->connection), state_lm_connection);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   325
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   326
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   327
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   328
/// connection:send
10
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   329
/// Sends message. If specified, handler function will be called upon receiving of response to this message.
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   330
/// Handler function can be either a message handler object or just a message handler function.
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   331
/// Message can be raw xml string. However, you cannot use it with handler function.
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   332
/// In short:
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   333
/// * connection, errmsg = connection:send ( "raw xml" )
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   334
/// * connection, errmsg = connection:send ( message )
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   335
/// * connection, errmsg = connection:send ( message, function ( connection, message ) end )
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   336
/// * connection, errmsg = connection:send ( message, handler )
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   337
/// If connection is nil, errmsg contains error message.
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   338
/// A: lm message object/string, message handler callback function/lm message handler object (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   339
/// R: lm connection object or nil, string (error message)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   340
static int send_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   341
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   342
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   343
	int status;
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   344
	GError *err = NULL;
10
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   345
	if (lua_gettop (L) < 3) { // Send
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   346
		if (lua_type (L, 2) == LUA_TSTRING)
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   347
			status = lm_connection_send_raw (object->connection, lua_tostring (L, 2), &err);
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   348
		else {
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   349
			llm_message_t *message = luaL_checklm_message (L, 2);
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   350
			status = lm_connection_send (object->connection, message->message, &err);
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   351
		}
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   352
	} else if (lua_isfunction (L, 3)) { // Send w/reply, func
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   353
		llm_message_t    *message = luaL_checklm_message (L, 2);
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   354
		llm_callback_t   *cb      = luaL_malloc (L, sizeof (llm_callback_t));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   355
		LmMessageHandler *handler;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   356
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   357
		cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
10
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   358
		cb->L         = L;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   359
		handler = lm_message_handler_new (
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   360
					(LmHandleMessageFunction)callback_lm_handler,
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   361
					cb, (GDestroyNotify)llm_callback_destroy);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   362
		status = lm_connection_send_with_reply (object->connection,
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   363
							message->message, handler, &err);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   364
		lm_message_handler_unref (handler);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   365
	} else { // Send w/reply, handler
10
aed141accdd9 Merge send_raw and send methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 9
diff changeset
   366
		llm_message_t *message = luaL_checklm_message (L, 2);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   367
		llm_handler_t *handler = luaL_checklm_handler (L, 3);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   368
		status = lm_connection_send_with_reply (object->connection, message->message,
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   369
							handler->handler, &err);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   370
		lua_pop (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   371
	};
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   372
	lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   373
	if (status)
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   374
		return 1;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   375
	else {
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   376
		I ("Message sending failed: %s", err->message);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   377
		lua_pushnil (L);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   378
		lua_pushstring (L, err->message);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   379
		return 2;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   380
	}
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   381
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   382
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   383
/// connection:handler
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   384
/// Registers or unregisters handler function for a given type of messages.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   385
/// To unregister handler, omit the priority argument.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   386
/// Handler function can be specified as plain function or message handler object.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   387
/// Though, you can unregister only a message handler object.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   388
/// A: message handler callback function or lm message handler object, message type, handler priority (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   389
/// R: lm connection object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   390
static int handler_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   391
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   392
	llm_connection_t *object = luaL_checklm_connection (L, 1);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   393
	int type = luaL_checkenum (L, 3, type_lm_message);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   394
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   395
	if (lua_gettop (L) > 3) { // Register
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   396
		int priority = luaL_checkenum (L, 4, priority_lm_handler);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   397
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   398
		if (lua_isfunction (L, 2)) { // Function
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   399
			LmMessageHandler *handler;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   400
			llm_callback_t *cb = luaL_malloc (L, sizeof (llm_callback_t));
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   401
			lua_pushvalue (L, 2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   402
			cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   403
			cb->L         = L;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   404
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   405
			handler = lm_message_handler_new (
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   406
					(LmHandleMessageFunction)callback_lm_handler,
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   407
					cb, (GDestroyNotify)llm_callback_destroy);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   408
			lm_connection_register_message_handler (object->connection,
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   409
								handler, type, priority);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   410
			lm_message_handler_unref (handler);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   411
		} else { // Object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   412
			llm_handler_t *handler = luaL_checklm_handler (L, 2);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   413
			lm_connection_register_message_handler (object->connection,
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   414
								handler->handler,
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   415
								type, priority);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   416
		}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   417
		lua_pop (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   418
	} else { // Unregister
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   419
		llm_handler_t *handler = luaL_checklm_handler (L, 2);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   420
		lm_connection_unregister_message_handler (object->connection,
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   421
							  handler->handler,
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   422
							  type);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   423
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   424
	lua_pop (L, 2);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   425
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   426
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   427
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   428
/// disconnect callback function
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   429
/// Function, that will be called when disconnection occurs.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   430
/// A: lm connection object, disconnect reason
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   431
void llm_disconnect_callback (LmConnection *connection, LmDisconnectReason reason, llm_callback_t *cb)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   432
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   433
	lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   434
	bless_lm_connection (cb->L, connection);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   435
	// XXX lm_connection_unref (connection);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   436
	luaL_pushenum (cb->L, reason, llm_disconnect_reason);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   437
	if (lua_pcall (cb->L, 2, 0, 0)) {
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   438
		W ("Disconnect callback error: %s", lua_tostring (cb->L, -1));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   439
		lua_pop (cb->L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   440
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   441
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   442
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   443
/// connection:ondisconnect
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   444
/// Sets callback, that will be called on connection disconnect.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   445
/// A: disconnect callback function
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   446
/// R: lm connection object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   447
static int ondisconnect_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   448
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   449
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   450
	llm_callback_t *cb;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   451
	luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected");
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   452
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   453
	cb = luaL_malloc (L, sizeof (llm_callback_t));
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   454
	cb->reference  = luaL_ref (L, LUA_REGISTRYINDEX);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   455
	cb->L          = L;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   456
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   457
	lm_connection_set_disconnect_function (object->connection,
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   458
					       (LmDisconnectFunction)llm_disconnect_callback,
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   459
					       cb, (GDestroyNotify)llm_callback_destroy);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   460
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   461
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   462
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   463
/// connection:open_wait
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   464
/// Synchronous open call, that will block until connection will be opened.
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   465
/// R: lm connection object or nil, string (error message)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   466
static int open_wait_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   467
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   468
	llm_connection_t *object = luaL_checklm_connection (L, 1);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   469
	GError *err = NULL;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   470
	if (lm_connection_open_and_block (object->connection, &err))
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   471
		return 1;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   472
	else {
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   473
		I ("Synchronous connection opening failed: %s", err->message);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   474
		lua_pushnil (L);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   475
		lua_pushstring (L, err->message);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   476
		return 2;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   477
	}
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   478
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   479
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   480
/// connection:authenticate_wait
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   481
/// Synchronous authentication call, that will wait until the end of authentication.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   482
/// A: string (username), string (password), string (resource)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   483
/// R: lm connection object or nil, string (error message)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   484
static int authenticate_wait_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   485
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   486
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   487
	const char *username = luaL_checkstring (L, 2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   488
	const char *password = luaL_checkstring (L, 3);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   489
	const char *resource = luaL_checkstring (L, 4);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   490
	GError *err = NULL;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   491
	if (lm_connection_authenticate_and_block (object->connection, username,
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   492
								password, resource, &err))
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   493
		return 1;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   494
	else {
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   495
		I ("Synchronous authentication failed: %s", err->message);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   496
		lua_pushnil (L);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   497
		lua_pushstring (L, err->message);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   498
		return 2;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   499
	}
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   500
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   501
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   502
/// connection:send_wait
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   503
/// Synchronous call, that will send message and wait for reply to it.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   504
/// A: lm message object
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   505
/// R: lm message object or nil, string (error message)
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   506
static int send_wait_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   507
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   508
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   509
	llm_message_t *message = luaL_checklm_message (L, 2);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   510
	GError *err = NULL;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   511
	LmMessage *new = lm_connection_send_with_reply_and_block (object->connection,
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   512
									message->message, &err);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   513
	if (!new) {
9
50f55d494efb Not use error log level, it is fatal
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   514
		I ("Synchronous message sending failed: %s", err->message);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   515
		lua_pushnil (L);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   516
		lua_pushstring (L, err->message);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   517
		return 2;
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   518
	} else {
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   519
		bless_lm_message (L, new);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   520
		lm_message_unref (new); // XXX
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   521
		return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   522
	}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   523
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   524
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   525
/// connection:pointer
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   526
/// Returns pointer to underlying C loudmouth structure.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   527
/// R: lightuserdata
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   528
static int pointer_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   529
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   530
	llm_connection_t *object = luaL_checklm_connection (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   531
	lua_pushlightuserdata (L, object->connection);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   532
	lua_remove (L, -2);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   533
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   534
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   535
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   536
static int gc_lm_connection (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   537
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   538
	llm_connection_t *object = luaL_checklm_connection (L, 1);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   539
	D ("Connection %X gc called", (int) object);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   540
	lm_connection_unref (object->connection);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   541
	return 0;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   542
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   543
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   544
static const luaL_Reg reg_f_lm_connection[] = {
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   545
	{ "new",   new_lm_connection       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   546
	{ "bless", bless_lua_lm_connection },
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   547
	{ NULL,    NULL                    },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   548
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   549
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   550
static const luaL_Reg reg_m_lm_connection[] = {
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   551
	{ "open",              open_lm_connection              },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   552
	{ "close",             close_lm_connection             },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   553
	{ "authenticate",      authenticate_lm_connection      },
13
8f502c1477ac Forgot to register connection:status
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   554
	{ "status",            status_lm_connection            },
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   555
	{ "port",              port_lm_connection              },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   556
	{ "server",            server_lm_connection            },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   557
	{ "jid",               jid_lm_connection               },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   558
	{ "keep_alive_rate",   keep_alive_rate_lm_connection   },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   559
	{ "state",             status_lm_connection            },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   560
	{ "proxy",             proxy_lm_connection             },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   561
	{ "ssl",               ssl_lm_connection               },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   562
	{ "send",              send_lm_connection              },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   563
	{ "handler",           handler_lm_connection           },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   564
	{ "ondisconnect",      ondisconnect_lm_connection      },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   565
	{ "open_wait",         open_wait_lm_connection         },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   566
	{ "authenticate_wait", authenticate_wait_lm_connection },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   567
	{ "send_wait",         send_wait_lm_connection         },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   568
	{ "pointer",           pointer_lm_connection           },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   569
	{ "__gc",              gc_lm_connection                },
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   570
	{ NULL,                NULL                            },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   571
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   572
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   573
int luaopen_lm_connection (lua_State *L)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   574
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   575
	luaL_newmetatable (L, "loudmouth.connection");
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   576
	lua_pushvalue (L, -1);
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   577
	lua_setfield (L, -2, "__index");
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 10
diff changeset
   578
	luaL_register (L, NULL, reg_m_lm_connection);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   579
	lua_pop (L, 1);
16
09b375e9ce32 Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 13
diff changeset
   580
	lua_newtable (L); // XXX we can specify here exact amount of fields
09b375e9ce32 Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 13
diff changeset
   581
	luaL_register (L, NULL, reg_f_lm_connection);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   582
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   583
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   584