lm_connection.c
changeset 11 a8c6460d612b
parent 10 aed141accdd9
child 12 63f06a23c235
--- a/lm_connection.c	Mon Feb 23 19:19:13 2009 +0200
+++ b/lm_connection.c	Sun Mar 08 00:48:19 2009 +0200
@@ -18,7 +18,7 @@
 /// connection state
 /// Stirng, representing current connection state.
 /// G:
-const string2enum_t llm_connection_state[] = {
+const string2enum_t state_lm_connection[] = {
 	{ "closed",         LM_CONNECTION_STATE_CLOSED         },
 	{ "opening",        LM_CONNECTION_STATE_OPENING        },
 	{ "open",           LM_CONNECTION_STATE_OPEN           },
@@ -31,7 +31,7 @@
 /// String, according to which handler will be placed into one
 /// of three handler groups.
 /// G:
-const string2enum_t llm_handler_priority[] = {
+const string2enum_t priority_lm_handler[] = {
 	{ "last",   LM_HANDLER_PRIORITY_LAST   },
 	{ "normal", LM_HANDLER_PRIORITY_NORMAL },
 	{ "first",  LM_HANDLER_PRIORITY_FIRST  },
@@ -59,7 +59,7 @@
 /// Creates a new connection (closed).
 /// A: string (server name), lightuserdata (C glib main context object, optional)
 /// R: lm connection object
-static int llm_connection_new (lua_State *L)
+static int new_lm_connection (lua_State *L)
 {
 	const char *server = luaL_checkstring (L, 1);
 	LmConnection *connection;
@@ -69,7 +69,7 @@
 		luaL_argcheck (L, lua_islightuserdata (L, 2), 2, "glib main context lightuserdata expected");
 		connection = lm_connection_new_with_context (server, (GMainContext *) lua_touserdata (L, 2));
 	}
-	llm_connection_bless (L, connection);
+	bless_lm_connection (L, connection);
 	lm_connection_unref (connection);
 	D ("Connection %X created", (int) connection);
 	return 1;
@@ -80,10 +80,10 @@
 /// Note: it adds a reference to connection.
 /// A: lightuserdata (C lm connection object)
 /// R: lm connection object
-static int llm_connection_bless_lua (lua_State *L)
+static int bless_lua_lm_connection (lua_State *L)
 {
 	luaL_argcheck (L, lua_islightuserdata (L, 1), 1, "loudmouth connection lightuserdata expected");
-	llm_connection_bless (L, (LmConnection *) lua_touserdata (L, 1));
+	bless_lm_connection (L, (LmConnection *) lua_touserdata (L, 1));
 	return 1;
 }
 
@@ -91,10 +91,10 @@
 /// User function, that will be called on connection establishment operation end,
 /// eg. successful/unsuccessful opening or authentication.
 /// A: lm connection object, boolean (success)
-static void llm_connection_callback (LmConnection *connection, int success, llm_callback_t *cb)
+static void callback_lm_connection (LmConnection *connection, int success, llm_callback_t *cb)
 {
 	lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference);
-	llm_connection_bless (cb->L, connection);
+	bless_lm_connection (cb->L, connection);
 	// XXX lm_connection_unref (connection);
 	lua_pushboolean (cb->L, success);
 	if (lua_pcall (cb->L, 2, 0, 0)) {
@@ -107,7 +107,7 @@
 /// Opens connection to the server and then calls callback function.
 /// A: connection callback function
 /// R: lm connection object or nil, string (error message)
-static int llm_connection_open (lua_State *L)
+static int open_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	llm_callback_t *cb;
@@ -118,7 +118,7 @@
 	cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
 	cb->L         = L;
 
-	if (lm_connection_open (object->connection, (LmResultFunction) llm_connection_callback,
+	if (lm_connection_open (object->connection, (LmResultFunction) callback_lm_connection,
 				 cb, (GDestroyNotify) llm_callback_destroy, &err))
 		return 1;
 	else {
@@ -133,7 +133,7 @@
 /// Tries to authenticate against opened connection, then calls callback function.
 /// A: string (username), string (password), string (resource), connection callback function
 /// R: lm connection object or nil, string (error message)
-static int llm_connection_authenticate (lua_State *L)
+static int authenticate_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	const char *username = luaL_checkstring (L, 2);
@@ -149,7 +149,7 @@
 	cb->L         = L;
 
 	if (lm_connection_authenticate (object->connection, username, password, resource,
-						(LmResultFunction) llm_connection_callback, cb,
+						(LmResultFunction) callback_lm_connection, cb,
 						(GDestroyNotify) llm_callback_destroy, &err)) {
 		lua_pop (L, 3);
 		return 1;
@@ -165,7 +165,7 @@
 /// Gets or sets server port to connect.
 /// A: integer (optional)
 /// R: integer (when called with no args) or lm connection object
-static int llm_connection_port (lua_State *L)
+static int port_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	if (lua_gettop (L) > 1) { // Set
@@ -181,7 +181,7 @@
 /// Gets or sets server to connect to.
 /// A: string (optional, server name)
 /// R: string (when called with no args) or lm connection object
-static int llm_connection_server (lua_State *L)
+static int server_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	if (lua_gettop (L) > 1) { // Set
@@ -197,7 +197,7 @@
 /// Gets or sets jid for connection.
 /// A: string (optional)
 /// R: string (when called with no args) or lm connection object
-static int llm_connection_jid (lua_State *L)
+static int jid_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	if (lua_gettop (L) > 1) { // Set
@@ -215,7 +215,7 @@
 /// loudmouth versions, that should have it according to documentation.
 /// integer (optional, seconds)
 /// integer (when called with no args) or lm connection object or nil, string (error message, when get function is not available in loudmouth)
-static int llm_connection_keep_alive_rate (lua_State *L)
+static int keep_alive_rate_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	if (lua_gettop (L) > 1) { // Set
@@ -239,7 +239,7 @@
 /// Gets or sets proxy server for connection.
 /// A: lm proxy object (optional)
 /// R: lm proxy object or nil (when called with no args) or lm connection object
-static int llm_connection_proxy (lua_State *L)
+static int proxy_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	if (lua_gettop (L) > 1) { // Set
@@ -250,7 +250,7 @@
 		LmProxy *proxy = lm_connection_get_proxy (object->connection);
 		lua_pop (L, 1);
 		if (proxy) {
-			llm_proxy_bless (L, proxy);
+			bless_lm_proxy (L, proxy);
 			// XXX lm_proxy_unref (proxy);
 		} else
 			lua_pushnil (L);
@@ -262,7 +262,7 @@
 /// Gets or sets ssl object for connection.
 /// A: lm ssl object (optional)
 /// R: lm ssl object or nil (when called with no args) or lm connection object
-static int llm_connection_ssl (lua_State *L)
+static int ssl_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	if (lua_gettop (L) > 1) { // Set
@@ -273,7 +273,7 @@
 		LmSSL *ssl = lm_connection_get_ssl (object->connection);
 		lua_pop (L, 1);
 		if (ssl) {
-			llm_ssl_bless (L, ssl);
+			bless_lm_ssl (L, ssl);
 			// XXX lm_ssl_unref (ssl);
 		} else
 			lua_pushnil (L);
@@ -284,7 +284,7 @@
 /// connection:close
 /// Close connection.
 /// R: lm connection object or nil, string (error message)
-static int llm_connection_close (lua_State *L)
+static int close_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	GError *err = NULL;
@@ -301,10 +301,10 @@
 /// connection:status
 /// Returns string, describing connection state.
 /// R: connection state
-static int llm_connection_status (lua_State *L)
+static int status_lm_connection (lua_State *L)
 {
 	llm_connection_t *connection = luaL_checklm_connection (L, 1);
-	luaL_pushenum (L, lm_connection_get_state (connection->connection), llm_connection_state);
+	luaL_pushenum (L, lm_connection_get_state (connection->connection), state_lm_connection);
 	return 1;
 }
 
@@ -320,7 +320,7 @@
 /// If connection is nil, errmsg contains error message.
 /// A: lm message object/string, message handler callback function/lm message handler object (optional)
 /// R: lm connection object or nil, string (error message)
-static int llm_connection_send (lua_State *L)
+static int send_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	int status;
@@ -340,16 +340,16 @@
 		cb->reference = luaL_ref (L, LUA_REGISTRYINDEX);
 		cb->L         = L;
 		handler = lm_message_handler_new (
-					(LmHandleMessageFunction)llm_message_handler_callback,
+					(LmHandleMessageFunction)callback_lm_handler,
 					cb, (GDestroyNotify)llm_callback_destroy);
 		status = lm_connection_send_with_reply (object->connection,
 							message->message, handler, &err);
 		lm_message_handler_unref (handler);
 	} else { // Send w/reply, handler
 		llm_message_t *message = luaL_checklm_message (L, 2);
-		llm_message_handler_t *handler = luaL_checklm_message_handler (L, 3);
+		llm_handler_t *handler = luaL_checklm_handler (L, 3);
 		status = lm_connection_send_with_reply (object->connection, message->message,
-							handler->message_handler, &err);
+							handler->handler, &err);
 		lua_pop (L, 1);
 	};
 	lua_pop (L, 1);
@@ -370,13 +370,13 @@
 /// Though, you can unregister only a message handler object.
 /// A: message handler callback function or lm message handler object, message type, handler priority (optional)
 /// R: lm connection object
-static int llm_connection_handler (lua_State *L)
+static int handler_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
-	int type = luaL_checkenum (L, 3, llm_message_type);
+	int type = luaL_checkenum (L, 3, type_lm_message);
 
 	if (lua_gettop (L) > 3) { // Register
-		int priority = luaL_checkenum (L, 4, llm_handler_priority);
+		int priority = luaL_checkenum (L, 4, priority_lm_handler);
 
 		if (lua_isfunction (L, 2)) { // Function
 			LmMessageHandler *handler;
@@ -386,22 +386,22 @@
 			cb->L         = L;
 
 			handler = lm_message_handler_new (
-					(LmHandleMessageFunction)llm_message_handler_callback,
+					(LmHandleMessageFunction)callback_lm_handler,
 					cb, (GDestroyNotify)llm_callback_destroy);
 			lm_connection_register_message_handler (object->connection,
 								handler, type, priority);
 			lm_message_handler_unref (handler);
 		} else { // Object
-			llm_message_handler_t *handler = luaL_checklm_message_handler (L, 2);
+			llm_handler_t *handler = luaL_checklm_handler (L, 2);
 			lm_connection_register_message_handler (object->connection,
-								handler->message_handler,
+								handler->handler,
 								type, priority);
 		}
 		lua_pop (L, 1);
 	} else { // Unregister
-		llm_message_handler_t *handler = luaL_checklm_message_handler (L, 2);
+		llm_handler_t *handler = luaL_checklm_handler (L, 2);
 		lm_connection_unregister_message_handler (object->connection,
-							  handler->message_handler,
+							  handler->handler,
 							  type);
 	}
 	lua_pop (L, 2);
@@ -414,7 +414,7 @@
 void llm_disconnect_callback (LmConnection *connection, LmDisconnectReason reason, llm_callback_t *cb)
 {
 	lua_rawgeti (cb->L, LUA_REGISTRYINDEX, cb->reference);
-	llm_connection_bless (cb->L, connection);
+	bless_lm_connection (cb->L, connection);
 	// XXX lm_connection_unref (connection);
 	luaL_pushenum (cb->L, reason, llm_disconnect_reason);
 	if (lua_pcall (cb->L, 2, 0, 0)) {
@@ -427,7 +427,7 @@
 /// Sets callback, that will be called on connection disconnect.
 /// A: disconnect callback function
 /// R: lm connection object
-static int llm_connection_ondisconnect (lua_State *L)
+static int ondisconnect_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	llm_callback_t *cb;
@@ -446,7 +446,7 @@
 /// connection:open_wait
 /// Synchronous open call, that will block until connection will be opened.
 /// R: lm connection object or nil, string (error message)
-static int llm_connection_open_wait (lua_State *L)
+static int open_wait_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	GError *err = NULL;
@@ -464,7 +464,7 @@
 /// Synchronous authentication call, that will wait until the end of authentication.
 /// A: string (username), string (password), string (resource)
 /// R: lm connection object or nil, string (error message)
-static int llm_connection_authenticate_wait (lua_State *L)
+static int authenticate_wait_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	const char *username = luaL_checkstring (L, 2);
@@ -486,7 +486,7 @@
 /// Synchronous call, that will send message and wait for reply to it.
 /// A: lm message object
 /// R: lm message object or nil, string (error message)
-static int llm_connection_send_wait (lua_State *L)
+static int send_wait_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	llm_message_t *message = luaL_checklm_message (L, 2);
@@ -499,7 +499,7 @@
 		lua_pushstring (L, err->message);
 		return 2;
 	} else {
-		llm_message_bless (L, new);
+		bless_lm_message (L, new);
 		lm_message_unref (new); // XXX
 		return 1;
 	}
@@ -508,7 +508,7 @@
 /// connection:pointer
 /// Returns pointer to underlying C loudmouth structure.
 /// R: lightuserdata
-static int llm_connection_pointer (lua_State *L)
+static int pointer_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	lua_pushlightuserdata (L, object->connection);
@@ -516,7 +516,7 @@
 	return 1;
 }
 
-static int llm_connection_gc (lua_State *L)
+static int gc_lm_connection (lua_State *L)
 {
 	llm_connection_t *object = luaL_checklm_connection (L, 1);
 	D ("Connection %X gc called", (int) object);
@@ -524,31 +524,31 @@
 	return 0;
 }
 
-static const luaL_Reg llm_connection_reg_f[] = {
-	{ "new",   llm_connection_new       },
-	{ "bless", llm_connection_bless_lua },
+static const luaL_Reg reg_f_lm_connection[] = {
+	{ "new",   new_lm_connection       },
+	{ "bless", bless_lua_lm_connection },
 	{ NULL,    NULL                     },
 };
 
-static const luaL_Reg llm_connection_reg_m[] = {
-	{ "open",                llm_connection_open                },
-	{ "close",               llm_connection_close               },
-	{ "authenticate",        llm_connection_authenticate        },
-	{ "port",                llm_connection_port                },
-	{ "server",              llm_connection_server              },
-	{ "jid",                 llm_connection_jid                 },
-	{ "keep_alive_rate",     llm_connection_keep_alive_rate     },
-	{ "state",               llm_connection_status              },
-	{ "proxy",               llm_connection_proxy               },
-	{ "ssl",                 llm_connection_ssl                 },
-	{ "send",                llm_connection_send                },
-	{ "handler",             llm_connection_handler             },
-	{ "ondisconnect",        llm_connection_ondisconnect        },
-	{ "open_wait",           llm_connection_open_wait           },
-	{ "authenticate_wait",   llm_connection_authenticate_wait   },
-	{ "send_wait",           llm_connection_send_wait           },
-	{ "pointer",             llm_connection_pointer             },
-	{ "__gc",                llm_connection_gc                  },
+static const luaL_Reg reg_m_lm_connection[] = {
+	{ "open",                open_lm_connection                },
+	{ "close",               close_lm_connection               },
+	{ "authenticate",        authenticate_lm_connection        },
+	{ "port",                port_lm_connection                },
+	{ "server",              server_lm_connection              },
+	{ "jid",                 jid_lm_connection                 },
+	{ "keep_alive_rate",     keep_alive_rate_lm_connection     },
+	{ "state",               status_lm_connection              },
+	{ "proxy",               proxy_lm_connection               },
+	{ "ssl",                 ssl_lm_connection                 },
+	{ "send",                send_lm_connection                },
+	{ "handler",             handler_lm_connection             },
+	{ "ondisconnect",        ondisconnect_lm_connection        },
+	{ "open_wait",           open_wait_lm_connection           },
+	{ "authenticate_wait",   authenticate_wait_lm_connection   },
+	{ "send_wait",           send_wait_lm_connection           },
+	{ "pointer",             pointer_lm_connection             },
+	{ "__gc",                gc_lm_connection                  },
 	{ NULL,                  NULL                               },
 };
 
@@ -558,9 +558,9 @@
 	lua_pushstring (L, "__index");
 	lua_pushvalue (L, -2);
 	lua_settable (L, -3);
-	luaL_register (L, NULL, llm_connection_reg_m);
+	luaL_register (L, NULL, reg_m_lm_connection);
 	lua_pop (L, 1);
-	luaL_register (L, "lm.connection", llm_connection_reg_f);
+	luaL_register (L, "lm.connection", reg_f_lm_connection);
 	return 1;
 }