]> source.dussan.org Git - rspamd.git/commitdiff
Move internet address pushing to common routines
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 25 Jan 2016 11:23:35 +0000 (11:23 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 25 Jan 2016 11:23:35 +0000 (11:23 +0000)
src/lua/lua_common.c
src/lua/lua_common.h
src/lua/lua_task.c

index e475ace8327ba60d2cad7be31e629a8c5dcad18e..2c4e913f6914c1f04d8fe72fe90e2c5b746c0837 100644 (file)
@@ -963,3 +963,99 @@ rspamd_lua_table_size (lua_State *L, gint tbl_pos)
 
        return tbl_size;
 }
+
+gboolean
+lua_push_internet_address (lua_State *L, InternetAddress *ia)
+{
+       const char *addr, *at;
+
+#ifndef GMIME24
+       if (internet_address_get_type (ia) == INTERNET_ADDRESS_NAME) {
+               lua_newtable (L);
+               addr = internet_address_get_addr (ia);
+               rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
+               rspamd_lua_table_set (L, "addr", addr);
+
+               if (addr) {
+                       at = strchr (addr, '@');
+                       if (at != NULL) {
+                               lua_pushstring(L, "user");
+                               lua_pushlstring(L, addr, at - addr);
+                               lua_settable (L, -3);
+                               lua_pushstring (L, "domain");
+                               lua_pushstring (L, at + 1);
+                               lua_settable (L, -3);
+                       }
+               }
+
+               return TRUE;
+       }
+       return FALSE;
+#else
+       InternetAddressMailbox *iamb;
+
+       if (ia && INTERNET_ADDRESS_IS_MAILBOX (ia)) {
+               lua_newtable (L);
+               iamb = INTERNET_ADDRESS_MAILBOX (ia);
+               addr = internet_address_mailbox_get_addr (iamb);
+
+               if (addr) {
+                       rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
+                       rspamd_lua_table_set (L, "addr", addr);
+                       /* Set optional fields */
+
+                       at = strchr (addr, '@');
+                       if (at != NULL) {
+                               lua_pushstring(L, "user");
+                               lua_pushlstring(L, addr, at - addr);
+                               lua_settable (L, -3);
+                               lua_pushstring (L, "domain");
+                               lua_pushstring (L, at + 1);
+                               lua_settable (L, -3);
+                       }
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+#endif
+}
+
+/*
+ * Push internet addresses to lua as a table
+ */
+void
+lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs)
+{
+       InternetAddress *ia;
+       gint idx = 1;
+
+#ifndef GMIME24
+       /* Gmime 2.2 version */
+       InternetAddressList *cur;
+
+       lua_newtable (L);
+       cur = addrs;
+       while (cur) {
+               ia = internet_address_list_get_address (cur);
+               if (lua_push_internet_address (L, ia)) {
+                       lua_rawseti (L, -2, idx++);
+               }
+               cur = internet_address_list_next (cur);
+       }
+#else
+       /* Gmime 2.4 version */
+       gsize len, i;
+
+       lua_newtable (L);
+       if (addrs != NULL) {
+               len = internet_address_list_length (addrs);
+               for (i = 0; i < len; i++) {
+                       ia = internet_address_list_get_address (addrs, i);
+                       if (lua_push_internet_address (L, ia)) {
+                               lua_rawseti (L, -2, idx++);
+                       }
+               }
+       }
+#endif
+}
index fd207134a2511824d2c8e739a018d3f5917f4e49..62ac54f3d0996c02ce256f5f11a37095b32e33cc 100644 (file)
@@ -296,5 +296,20 @@ gint rspamd_lua_traceback (lua_State *L);
  * Returns size of table at position `tbl_pos`
  */
 guint rspamd_lua_table_size (lua_State *L, gint tbl_pos);
+
+/**
+ * Pushes a single InternetAddress as lua table
+ * @param L
+ * @param addrs
+ */
+void lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs);
+
+/**
+ * Pushes internet address list to Lua as table of tables
+ * @param L
+ * @param ia
+ * @return
+ */
+gboolean lua_push_internet_address (lua_State *L, InternetAddress *ia);
 #endif /* WITH_LUA */
 #endif /* RSPAMD_LUA_H */
index 2980aba9b1aab0a03c8238d756a443dd6bb305b2..0dbf8dc0dbf2acccdb60af806f91bba0308939ff 100644 (file)
@@ -1250,85 +1250,6 @@ lua_task_inc_dns_req (lua_State *L)
        return 0;
 }
 
-static gboolean
-lua_push_internet_address (lua_State *L, InternetAddress *ia)
-{
-#ifndef GMIME24
-       if (internet_address_get_type (ia) == INTERNET_ADDRESS_NAME) {
-               lua_newtable (L);
-               rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
-               rspamd_lua_table_set (L, "addr", internet_address_get_addr (ia));
-               return TRUE;
-       }
-       return FALSE;
-#else
-       InternetAddressMailbox *iamb;
-       const char *addr, *at;
-       if (ia && INTERNET_ADDRESS_IS_MAILBOX (ia)) {
-               lua_newtable (L);
-               iamb = INTERNET_ADDRESS_MAILBOX (ia);
-               addr = internet_address_mailbox_get_addr (iamb);
-               if (addr) {
-                       rspamd_lua_table_set (L, "name", internet_address_get_name (ia));
-                       rspamd_lua_table_set (L, "addr", addr);
-                       /* Set optional fields */
-
-                       at = strchr (addr, '@');
-                       if (at != NULL) {
-                               lua_pushstring(L, "user");
-                               lua_pushlstring(L, addr, at - addr);
-                               lua_settable (L, -3);
-                               lua_pushstring(L, "domain");
-                               lua_pushstring(L, at + 1);
-                               lua_settable (L, -3);
-                       }
-                       return TRUE;
-               }
-       }
-
-       return FALSE;
-#endif
-}
-
-/*
- * Push internet addresses to lua as a table
- */
-static void
-lua_push_internet_address_list (lua_State *L, InternetAddressList *addrs)
-{
-       InternetAddress *ia;
-       gint idx = 1;
-
-#ifndef GMIME24
-       /* Gmime 2.2 version */
-       InternetAddressList *cur;
-
-       lua_newtable (L);
-       cur = addrs;
-       while (cur) {
-               ia = internet_address_list_get_address (cur);
-               if (lua_push_internet_address (L, ia)) {
-                       lua_rawseti (L, -2, idx++);
-               }
-               cur = internet_address_list_next (cur);
-       }
-#else
-       /* Gmime 2.4 version */
-       gsize len, i;
-
-       lua_newtable (L);
-       if (addrs != NULL) {
-               len = internet_address_list_length (addrs);
-               for (i = 0; i < len; i++) {
-                       ia = internet_address_list_get_address (addrs, i);
-                       if (lua_push_internet_address (L, ia)) {
-                               lua_rawseti (L, -2, idx++);
-                       }
-               }
-       }
-#endif
-}
-
 /*
  * Convert element at the specified position to the type
  * for get_from/get_recipients