aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2012-06-05 18:21:49 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2012-06-05 18:21:49 +0400
commit35cb2b6e2f17a518d0c940985e6e19b41fdedf19 (patch)
tree18b4c1bd7ddea5af8eb580333c6ac1e5f0e00ebb /lib
parent1d8da7cd96a810bc6119a8f604e934235e68f9cf (diff)
downloadrspamd-35cb2b6e2f17a518d0c940985e6e19b41fdedf19.tar.gz
rspamd-35cb2b6e2f17a518d0c940985e6e19b41fdedf19.zip
* Split rspamd build to several independent libraries to reduce overhead.
Diffstat (limited to 'lib')
-rw-r--r--lib/CMakeLists.txt210
-rw-r--r--lib/client/librspamdclient.c34
2 files changed, 147 insertions, 97 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index a0350e012..2ef90dec2 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1,105 +1,170 @@
# Librspamdclient
-SET(LIBRSPAMDSRC client/librspamdclient.c
- ../src/mem_pool.c
- ../src/upstream.c
- ../src/printf.c)
+SET(LIBRSPAMDCLIENTSRC client/librspamdclient.c )
+
+# Librspamd-util
+SET(LIBRSPAMDUTILSRC ../src/aio_event.c
+ ../src/bloom.c
+ ../src/diff.c
+ ../src/fstring.c
+ ../src/fuzzy.c
+ ../src/hash.c
+ ../src/memcached.c
+ ../src/mem_pool.c
+ ../src/printf.c
+ ../src/radix.c
+ ../src/trie.c
+ ../src/upstream.c
+ ../src/util.c)
+
+# kvstorageclient
+
+SET(LIBRKVSTORAGESRC kvstorage/libkvstorageclient.c)
-ADD_LIBRARY(rspamdclient SHARED ${LIBRSPAMDSRC})
-ADD_LIBRARY(rspamdclient_static STATIC ${LIBRSPAMDSRC})
-SET_TARGET_PROPERTIES(rspamdclient PROPERTIES PUBLIC_HEADER "client/librspamdclient.h")
-
-IF(CMAKE_COMPILER_IS_GNUCC)
-SET_TARGET_PROPERTIES(rspamdclient PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
-SET_TARGET_PROPERTIES(rspamdclient_static PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
-ENDIF(CMAKE_COMPILER_IS_GNUCC)
-
-TARGET_LINK_LIBRARIES(rspamdclient ${CMAKE_REQUIRED_LIBRARIES})
-TARGET_LINK_LIBRARIES(rspamdclient pcre)
-TARGET_LINK_LIBRARIES(rspamdclient ${GLIB2_LIBRARIES})
-
-TARGET_LINK_LIBRARIES(rspamdclient_static ${CMAKE_REQUIRED_LIBRARIES})
-TARGET_LINK_LIBRARIES(rspamdclient_static ${GLIB2_LIBRARIES})
-
-SET_TARGET_PROPERTIES(rspamdclient PROPERTIES VERSION ${RSPAMD_VERSION})
-SET_TARGET_PROPERTIES(rspamdclient_static PROPERTIES VERSION ${RSPAMD_VERSION})
-
-IF(GLIB_COMPAT)
- INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/contrib/lgpl")
- TARGET_LINK_LIBRARIES(rspamdclient glibadditions)
-ENDIF(GLIB_COMPAT)
-
-INSTALL(TARGETS rspamdclient rspamdclient_static LIBRARY PUBLIC_HEADER
- LIBRARY DESTINATION lib
- PUBLIC_HEADER DESTINATION include
- ARCHIVE DESTINATION lib)
-
-
# Librspamdserver
-SET(RSPAMDLIBSRC
- ../src/aio_event.c
+SET(LIBRSPAMDSERVERSRC
../src/binlog.c
- ../src/bloom.c
../src/buffer.c
../src/cfg_utils.c
../src/cfg_xml.c
- ../src/diff.c
../src/dkim.c
../src/dns.c
../src/events.c
- ../src/expressions.c
- ../src/filter.c
- ../src/fstring.c
- ../src/fuzzy.c
- ../src/hash.c
../src/html.c
- ../src/images.c
../src/kvstorage.c
../src/kvstorage_config.c
../src/kvstorage_file.c
../src/lmtp_proto.c
../src/logger.c
../src/map.c
- ../src/memcached.c
- ../src/mem_pool.c
- ../src/message.c
- ../src/printf.c
- ../src/protocol.c
../src/proxy.c
- ../src/radix.c
../src/settings.c
../src/spf.c
../src/smtp_proto.c
- ../src/smtp_utils.c
../src/statfile.c
../src/statfile_sync.c
../src/symbols_cache.c
- ../src/trie.c
- ../src/upstream.c
../src/url.c
- ../src/util.c
../src/view.c)
+
+# Librspamd mime
+SET(LIBRSPAMDMIMESRC
+ ../src/expressions.c
+ ../src/filter.c
+ ../src/images.c
+ ../src/message.c
+ ../src/protocol.c
+ ../src/smtp_utils.c)
+# Add targets
+
+# Rspamdutil
+ADD_LIBRARY(rspamd-util SHARED ${LIBRSPAMDUTILSRC})
+IF(CMAKE_COMPILER_IS_GNUCC)
+SET_TARGET_PROPERTIES(rspamd-util PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
+ENDIF(CMAKE_COMPILER_IS_GNUCC)
+
+TARGET_LINK_LIBRARIES(rspamd-util ${CMAKE_REQUIRED_LIBRARIES})
+TARGET_LINK_LIBRARIES(rspamd-util pcre)
+TARGET_LINK_LIBRARIES(rspamd-util ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(rspamd-util event)
+
+SET_TARGET_PROPERTIES(rspamd-util PROPERTIES VERSION ${RSPAMD_VERSION})
+
+IF(GLIB_COMPAT)
+ INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/contrib/lgpl")
+ TARGET_LINK_LIBRARIES(rspamd-util glibadditions)
+ENDIF(GLIB_COMPAT)
+
+INSTALL(TARGETS rspamd-util
+ LIBRARY DESTINATION ${LIBDIR}
+ PUBLIC_HEADER DESTINATION include
+ ARCHIVE DESTINATION ${LIBDIR})
+
+# Rspamd client
+ADD_LIBRARY(rspamdclient SHARED ${LIBRSPAMDCLIENTSRC})
+ADD_LIBRARY(rspamdclient_static STATIC ${LIBRSPAMDCLIENTSRC})
+SET_TARGET_PROPERTIES(rspamdclient PROPERTIES PUBLIC_HEADER "client/librspamdclient.h")
+
+IF(CMAKE_COMPILER_IS_GNUCC)
+SET_TARGET_PROPERTIES(rspamdclient PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
+SET_TARGET_PROPERTIES(rspamdclient_static PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
+ENDIF(CMAKE_COMPILER_IS_GNUCC)
+
+TARGET_LINK_LIBRARIES(rspamdclient rspamd-util)
+
+TARGET_LINK_LIBRARIES(rspamdclient_static ${CMAKE_REQUIRED_LIBRARIES})
+TARGET_LINK_LIBRARIES(rspamdclient_static ${GLIB2_LIBRARIES})
+
+SET_TARGET_PROPERTIES(rspamdclient PROPERTIES VERSION ${RSPAMD_VERSION})
+SET_TARGET_PROPERTIES(rspamdclient_static PROPERTIES VERSION ${RSPAMD_VERSION})
+
+IF(GLIB_COMPAT)
+ INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/contrib/lgpl")
+ TARGET_LINK_LIBRARIES(rspamdclient glibadditions)
+ENDIF(GLIB_COMPAT)
+
+INSTALL(TARGETS rspamdclient rspamdclient_static LIBRARY PUBLIC_HEADER
+ LIBRARY DESTINATION ${LIBDIR}
+ PUBLIC_HEADER DESTINATION ${INCLUDEDIR}
+ ARCHIVE DESTINATION ${LIBDIR})
+
+
+# Librspamd-server
IF(WITH_DB)
- LIST(APPEND RSPAMDLIBSRC ../src/kvstorage_bdb.c)
+ LIST(APPEND LIBRSPAMDSERVERSRC ../src/kvstorage_bdb.c)
ENDIF(WITH_DB)
IF(WITH_SQLITE)
- LIST(APPEND RSPAMDLIBSRC ../src/kvstorage_sqlite.c)
+ LIST(APPEND LIBRSPAMDSERVERSRC ../src/kvstorage_sqlite.c)
ENDIF(WITH_SQLITE)
-ADD_LIBRARY(rspamdserver STATIC ${RSPAMDLIBSRC})
-SET_TARGET_PROPERTIES(rspamdserver PROPERTIES LINKER_LANGUAGE C)
-SET_TARGET_PROPERTIES(rspamdserver PROPERTIES COMPILE_FLAGS "-DRSPAMD_LIB")
-TARGET_LINK_LIBRARIES(rspamdserver rspamd_lua)
-TARGET_LINK_LIBRARIES(rspamdserver rspamd_json)
-TARGET_LINK_LIBRARIES(rspamdserver rspamd_cdb)
+ADD_LIBRARY(rspamd-server SHARED ${LIBRSPAMDSERVERSRC})
+SET_TARGET_PROPERTIES(rspamd-server PROPERTIES LINKER_LANGUAGE C)
+SET_TARGET_PROPERTIES(rspamd-server PROPERTIES COMPILE_FLAGS "-DRSPAMD_LIB")
+TARGET_LINK_LIBRARIES(rspamd-server rspamd-lua)
+TARGET_LINK_LIBRARIES(rspamd-server rspamd-json)
+TARGET_LINK_LIBRARIES(rspamd-server rspamd-cdb)
+TARGET_LINK_LIBRARIES(rspamd-server rspamd-util)
+IF(CMAKE_COMPILER_IS_GNUCC)
+SET_TARGET_PROPERTIES(rspamd-server PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
+ENDIF(CMAKE_COMPILER_IS_GNUCC)
+IF(WITH_DB)
+ TARGET_LINK_LIBRARIES(rspamd-server db)
+ENDIF(WITH_DB)
+IF(SQLITE_LIBRARIES)
+ TARGET_LINK_LIBRARIES(rspamd-server ${SQLITE_LIBRARIES})
+ENDIF(SQLITE_LIBRARIES)
+
+IF(OPENSSL_FOUND)
+ TARGET_LINK_LIBRARIES(rspamd-server ${OPENSSL_LIBRARIES})
+ENDIF(OPENSSL_FOUND)
+INSTALL(TARGETS rspamd-server
+ LIBRARY DESTINATION ${LIBDIR}
+ PUBLIC_HEADER DESTINATION ${INCLUDEDIR}
+ ARCHIVE DESTINATION ${LIBDIR})
+
+# Librspamdmime
+ADD_LIBRARY(rspamd-mime SHARED ${LIBRSPAMDMIMESRC})
+SET_TARGET_PROPERTIES(rspamd-mime PROPERTIES LINKER_LANGUAGE C)
+SET_TARGET_PROPERTIES(rspamd-mime PROPERTIES COMPILE_FLAGS "-DRSPAMD_LIB")
+TARGET_LINK_LIBRARIES(rspamd-mime rspamd-server)
+TARGET_LINK_LIBRARIES(rspamd-mime rspamd-util)
+IF(CMAKE_COMPILER_IS_GNUCC)
+SET_TARGET_PROPERTIES(rspamd-mime PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
+ENDIF(CMAKE_COMPILER_IS_GNUCC)
+
+IF(GMIME24)
+ TARGET_LINK_LIBRARIES(rspamd-mime ${GMIME24_LIBRARIES})
+ELSE(GMIME24)
+ TARGET_LINK_LIBRARIES(rspamd-mime ${GMIME2_LIBRARIES})
+ENDIF(GMIME24)
+
+INSTALL(TARGETS rspamd-mime
+ LIBRARY DESTINATION ${LIBDIR}
+ PUBLIC_HEADER DESTINATION ${INCLUDEDIR}
+ ARCHIVE DESTINATION ${LIBDIR})
# Libkvstorageclient
-SET(LIBRKVSTORAGESRC kvstorage/libkvstorageclient.c
- ../src/mem_pool.c
- ../src/upstream.c
- ../src/printf.c
- ../src/util.c)
ADD_LIBRARY(kvstorageclient SHARED ${LIBRKVSTORAGESRC})
ADD_LIBRARY(kvstorageclient_static STATIC ${LIBRKVSTORAGESRC})
@@ -110,10 +175,7 @@ SET_TARGET_PROPERTIES(kvstorageclient PROPERTIES COMPILE_FLAGS "-fno-strict-alia
SET_TARGET_PROPERTIES(kvstorageclient_static PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
-TARGET_LINK_LIBRARIES(kvstorageclient ${CMAKE_REQUIRED_LIBRARIES})
-TARGET_LINK_LIBRARIES(kvstorageclient pcre)
-TARGET_LINK_LIBRARIES(kvstorageclient ${GLIB2_LIBRARIES})
-TARGET_LINK_LIBRARIES(kvstorageclient event)
+TARGET_LINK_LIBRARIES(kvstorageclient rspamd-util)
TARGET_LINK_LIBRARIES(kvstorageclient_static ${CMAKE_REQUIRED_LIBRARIES})
TARGET_LINK_LIBRARIES(kvstorageclient_static ${GLIB2_LIBRARIES})
@@ -128,6 +190,6 @@ ENDIF(GLIB_COMPAT)
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/src")
INSTALL(TARGETS rspamdclient rspamdclient_static LIBRARY PUBLIC_HEADER
- LIBRARY DESTINATION lib
- PUBLIC_HEADER DESTINATION include
- ARCHIVE DESTINATION lib)
+ LIBRARY DESTINATION ${LIBDIR}
+ PUBLIC_HEADER DESTINATION ${INCLUDEDIR}
+ ARCHIVE DESTINATION ${LIBDIR})
diff --git a/lib/client/librspamdclient.c b/lib/client/librspamdclient.c
index dac49b5ae..2fbc2692d 100644
--- a/lib/client/librspamdclient.c
+++ b/lib/client/librspamdclient.c
@@ -1125,31 +1125,19 @@ rspamd_send_controller_command (struct rspamd_connection *c, const gchar *line,
if ((r = read (c->socket, tmpbuf, sizeof (tmpbuf) - 1)) > 0) {
/* Check the end of the buffer for END marker */
tmpbuf[r] = '\0';
- if (r >= (gint)sizeof (end_marker) - 1 &&
- (p = strstr (tmpbuf, end_marker)) != NULL) {
- *p = '\0';
- /* Copy the rest to the result string */
- if (res == NULL) {
- res = g_string_new (tmpbuf);
- return res;
- }
- else {
- /* Append data to string */
- if (r > 0) {
- res = g_string_append (res, tmpbuf);
- }
- return res;
- }
+ /* Store data inside res */
+ if (res == NULL) {
+ res = g_string_new_len (tmpbuf, r);
}
else {
- /* Store data inside res */
- if (res == NULL) {
- res = g_string_new_len (tmpbuf, r);
- }
- else {
- /* Append data to string */
- res = g_string_append_len (res, tmpbuf, r);
- }
+ /* Append data to string */
+ res = g_string_append_len (res, tmpbuf, r);
+ }
+ /* Check for END marker */
+ if (res->len > sizeof (end_marker) - 1 && (p = strstr (res->str, end_marker)) != NULL) {
+ *p = '\0';
+ res->len = p - res->str;
+ return res;
}
}
} while (r > 0);