lm_proxy.c
author Myhailo Danylenko <isbear@ukrpost.net>
Wed, 16 Mar 2016 01:53:56 +0200
changeset 66 a40beb82130c
parent 63 c17f3295f52c
permissions -rw-r--r--
node: Use new loudmouth feature - public attribute list (v0.9.7)
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>
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
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
/// lm.proxy
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    29
/// Object, containing information about proxy-server for connection.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    30
/// Create object, set it's parameters, and then attach to connection
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    31
/// with 'proxy' method.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    32
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    33
/// proxy type
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    34
/// Stirng, specifying proxy-server type. The only type supported for now is http.
4
5770be2d5f3f Documentation updates
Myhailo Danylenko <isbear@ukrpost.net>
parents: 0
diff changeset
    35
/// G:
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    36
const string2enum_t type_lm_proxy[] = {
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    37
	{ "http", LM_PROXY_TYPE_HTTP },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    38
	{ "none", LM_PROXY_TYPE_NONE },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    39
	{ NULL,   LM_PROXY_TYPE_HTTP },
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    40
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    41
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    42
/// lm.proxy.new
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    43
/// Creates new proxy object.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    44
/// Note, you should specify either none of args or both.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    45
/// A: proxy type, string (optional proxy server name), integer (optional server port)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    46
/// R: lm proxy object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    47
static int new_lm_proxy (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    48
{
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    49
	int type = luaL_checkenum (L, 1, type_lm_proxy);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    50
	LmProxy *proxy;
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    51
	if (lua_gettop (L) > 0)
63
c17f3295f52c lua: Add compatibility with lua 5.3
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
    52
		proxy = lm_proxy_new_with_server (type, luaL_checkstring (L, 2), luaL_checkinteger (L, 3));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    53
	else
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    54
		proxy = lm_proxy_new (type);
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    55
	bless_lm_proxy (L, proxy);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    56
	lm_proxy_unref (proxy); // XXX
38
34a2b880615c Fix debugging pointer format character
Myhailo Danylenko <isbear@ukrpost.net>
parents: 23
diff changeset
    57
	D ("Proxy %p created", proxy);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    58
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    59
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    60
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    61
/// lm.proxy.bless
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    62
/// Blesses given pointer to lm proxy object.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    63
/// A: lightuserdata (C lm proxy object)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
/// R: lm proxy object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    65
static int bless_lua_lm_proxy (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    66
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    67
	luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "lm proxy lightuserdata expected");
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    68
	bless_lm_proxy (L, lua_touserdata (L, 1));
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    69
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    70
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    71
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    72
/// proxy:type
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    73
/// Gets or sets proxy server type.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    74
/// A: proxy type (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    75
/// R: proxy type (when called with no args) or lm proxy object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    76
static int kind_lm_proxy (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    77
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    78
	llm_proxy_t *proxy = luaL_checklm_proxy (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    79
	if (lua_gettop (L) > 1) { // Set
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    80
		lm_proxy_set_type (proxy->proxy, luaL_checkenum (L, 2, type_lm_proxy));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    81
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    82
	} else // Get
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    83
		luaL_pushenum (L, lm_proxy_get_type (proxy->proxy), type_lm_proxy);
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    84
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    85
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    86
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    87
/// proxy:server
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    88
/// Gets or sets proxy server name.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    89
/// A: string (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    90
/// R: string (when called with no args) or lm proxy object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
    91
static int server_lm_proxy (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    92
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    93
	llm_proxy_t *object = luaL_checklm_proxy (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    94
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    95
		lm_proxy_set_server (object->proxy, luaL_checkstring (L, 2));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    96
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    97
	} else // Get
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    98
		lua_pushstring (L, lm_proxy_get_server (object->proxy));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
    99
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   100
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   101
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   102
/// proxy:port
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   103
/// Gets or sets proxy server port.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   104
/// A: integer (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   105
/// R: integer (when called with no args) or lm proxy object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   106
static int port_lm_proxy (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   107
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   108
	llm_proxy_t *object = luaL_checklm_proxy (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   109
	if (lua_gettop (L) > 1) { // Set
63
c17f3295f52c lua: Add compatibility with lua 5.3
Myhailo Danylenko <isbear@ukrpost.net>
parents: 54
diff changeset
   110
		lm_proxy_set_port (object->proxy, luaL_checkinteger (L, 2));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   111
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   112
	} else // Get
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   113
		lua_pushnumber (L, lm_proxy_get_port (object->proxy));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   114
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   115
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   116
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   117
/// proxy:username
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   118
/// Gets or sets username to authenticate to proxy server with.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   119
/// A: string (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   120
/// R: string (when called with no args) or lm proxy object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   121
static int username_lm_proxy (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   122
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   123
	llm_proxy_t *object = luaL_checklm_proxy (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   124
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   125
		lm_proxy_set_username (object->proxy, luaL_checkstring (L, 2));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   126
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   127
	} else // Get
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   128
		lua_pushstring (L, lm_proxy_get_username (object->proxy));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   129
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   130
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   131
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   132
/// proxy:password
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   133
/// Gets or sets password to authenticate to proxy server with.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   134
/// A: string (optional)
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   135
/// R: string (when called with no args) or lm proxy object
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   136
static int password_lm_proxy (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   137
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   138
	llm_proxy_t *object = luaL_checklm_proxy (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   139
	if (lua_gettop (L) > 1) { // Set
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   140
		lm_proxy_set_password (object->proxy, luaL_checkstring (L, 2));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   141
		lua_pop (L, 1);
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   142
	} else // Get
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   143
		lua_pushstring (L, lm_proxy_get_password (object->proxy));
6
90073cbb535d Logging and chained methods
Myhailo Danylenko <isbear@ukrpost.net>
parents: 4
diff changeset
   144
	return 1;
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   145
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   146
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   147
/// proxy:pointer
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   148
/// Returns pointer to underlying C structure.
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   149
/// R: lightuserdata
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   150
static int pointer_lm_proxy (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   151
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   152
	llm_proxy_t *object = luaL_checklm_proxy (L, 1);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   153
	lua_pushlightuserdata (L, object->proxy);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   154
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   155
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   156
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   157
static int gc_lm_proxy (lua_State *L)
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   158
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   159
	llm_proxy_t *object = luaL_checklm_proxy (L, 1);
38
34a2b880615c Fix debugging pointer format character
Myhailo Danylenko <isbear@ukrpost.net>
parents: 23
diff changeset
   160
	D ("Proxy %p gc called", object);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   161
	lm_proxy_unref (object->proxy);
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   162
	return 0;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   163
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   164
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   165
static const luaL_Reg reg_f_lm_proxy[] = {
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   166
	{ "new",   new_lm_proxy       },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   167
	{ "bless", bless_lua_lm_proxy },
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   168
	{ NULL,    NULL               },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   169
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   170
11
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   171
static const luaL_Reg reg_m_lm_proxy[] = {
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   172
	{ "port",     port_lm_proxy     },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   173
	{ "server",   server_lm_proxy   },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   174
	{ "type",     kind_lm_proxy     },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   175
	{ "username", username_lm_proxy },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   176
	{ "password", password_lm_proxy },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   177
	{ "pointer",  pointer_lm_proxy  },
a8c6460d612b Naming scheme change to more ld-friendly
Myhailo Danylenko <isbear@ukrpost.net>
parents: 6
diff changeset
   178
	{ "__gc",     gc_lm_proxy       },
12
63f06a23c235 Empty to field
Myhailo Danylenko <isbear@ukrpost.net>
parents: 11
diff changeset
   179
	{ NULL,       NULL              },
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   180
};
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   181
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   182
int luaopen_lm_proxy (lua_State *L)
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   183
{
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   184
	luaL_newmetatable (L, "loudmouth.proxy");
19
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   185
	lua_pushvalue (L, -1);
d775d7289fe4 Use lua_pushliteral and lua_setfield
Myhailo Danylenko <isbear@ukrpost.net>
parents: 16
diff changeset
   186
	lua_setfield (L, -2, "__index");
54
6bef2082e5f9 v0.9.2 Support for lua 5.2
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   187
	luaL_setfuncs (L, reg_m_lm_proxy, 0);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   188
	lua_pop (L, 1);
16
09b375e9ce32 Switch to new module organization scheme
Myhailo Danylenko <isbear@ukrpost.net>
parents: 12
diff changeset
   189
	lua_newtable (L); // XXX we can specify here exact amount of fields
54
6bef2082e5f9 v0.9.2 Support for lua 5.2
Myhailo Danylenko <isbear@ukrpost.net>
parents: 38
diff changeset
   190
	luaL_setfuncs (L, reg_f_lm_proxy, 0);
0
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   191
	return 1;
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   192
}
84fdfb0344c9 Initial commit
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
   193