Commit c027acc9ea0b3678892c5d557d3a153368fa6095

Authored by Elena.Budnik
1 parent 726ff386

added username to DD Server request; logging

CMakeLists.txt
... ... @@ -27,6 +27,10 @@ endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
27 27  
28 28 find_package( Threads REQUIRED )
29 29  
  30 +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
  31 +
  32 +find_package( Log4Cxx REQUIRED)
  33 +
30 34 MESSAGE( STATUS "Build DDClient Project" )
31 35 add_subdirectory(src/DDClientLibC)
32 36 add_subdirectory(src/DDClientLibCpp)
... ...
cmake/FindLog4Cxx.cmake 0 → 100644
... ... @@ -0,0 +1,44 @@
  1 +# Strigi
  2 +# This notice was added by Olivier Coupelon based on the project information from http://sourceforge.net/projects/strigi
  3 +# In case of error please contact me at olivier.coupelon@teardrop.fr
  4 +# Copyright (C) 2006 Strigi
  5 +
  6 +# This library is free software; you can redistribute it and/or modify
  7 +# it under the terms of the GNU Lesser General Public License as
  8 +# published by the Free Software Foundation; either version 2.1 of the
  9 +# License, or (at your option) any later version.
  10 +
  11 +# This library is distributed in the hope that it will be useful,
  12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14 +# GNU Lesser General Public License for more details.
  15 +
  16 +# You should have received a copy of the GNU Lesser General Public
  17 +# License along with this library; if not, write to the Free Software
  18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19 +
  20 +
  21 +# - Try to find the liblog4cxx libraries
  22 +# Once done this will define
  23 +#
  24 +# Log4cxx_FOUND - system has liblog4cxx
  25 +# LOG4CXX_INCLUDE_DIR - the liblog4cxx include directory
  26 +# LOG4CXX_LIBRARIES - liblog4cxx library
  27 +
  28 +FIND_PATH(LOG4CXX_INCLUDE_DIR logger.h PATHS /include/log4cxx /usr/include/log4cxx /usr/local/include/log4cxx ${USERLOCAL_ROOT}/include/log4cxx)
  29 +FIND_LIBRARY(LOG4CXX_LIBRARIES NAMES log4cxx log4cxxd PATHS /lib /usr/lib /usr/local/lib ${USERLOCAL_ROOT}/lib )
  30 +
  31 +IF(LOG4CXX_INCLUDE_DIR AND LOG4CXX_LIBRARIES)
  32 +SET(Log4cxx_FOUND 1)
  33 +#remove last /log4cxx string
  34 +STRING(REGEX REPLACE "/log4cxx" "" LOG4CXX_INCLUDE_DIR_SUP_LEVEL ${LOG4CXX_INCLUDE_DIR})
  35 +SET (LOG4CXX_INCLUDE_DIR ${LOG4CXX_INCLUDE_DIR_SUP_LEVEL} ${LOG4CXX_INCLUDE_DIR} )
  36 +if(NOT Log4cxx_FIND_QUIETLY)
  37 +message(STATUS "Found log4cxx: ${LOG4CXX_LIBRARIES}")
  38 +endif(NOT Log4cxx_FIND_QUIETLY)
  39 +ELSE(LOG4CXX_INCLUDE_DIR AND LOG4CXX_LIBRARIES)
  40 +SET(Log4cxx_FOUND 0 CACHE BOOL "Not found log4cxx library")
  41 +message(STATUS "NOT Found log4cxx, disabling it")
  42 +ENDIF(LOG4CXX_INCLUDE_DIR AND LOG4CXX_LIBRARIES)
  43 +
  44 +MARK_AS_ADVANCED(LOG4CXX_INCLUDE_DIR LOG4CXX_LIBRARIES)
... ...
src/DDClientLibCpp/DD_client.cc
... ... @@ -101,7 +101,7 @@ int DD_Client::GetUserHost() {
101 101 snprintf(UserHost, MAXHOSTLENGTH, "%03u.%03u.%03u.%03u", b1, b2, b3, b4);
102 102  
103 103 #ifdef LOG4CXX
104   - //LOG4CXX_DEBUG(_logger, "DD_Client::GetUserHost - UserHost : " << UserHost);
  104 + // LOG4CXX_DEBUG(_logger, "DD_Client::GetUserHost - UserHost : " << UserHost);
105 105 #endif
106 106 }
107 107 return userid;
... ... @@ -110,7 +110,14 @@ int DD_Client::GetUserHost() {
110 110 void DD_Client::setUserHost(const char* host) {
111 111 snprintf(UserHost, MAXHOSTLENGTH, "%s", host);
112 112 #ifdef LOG4CXX
113   - //LOG4CXX_DEBUG(_logger, "DD_Client::setUserHost - UserHost : " << UserHost);
  113 + // LOG4CXX_DEBUG(_logger, "DD_Client::setUserHost - UserHost : " << UserHost);
  114 +#endif
  115 +}
  116 +
  117 +void DD_Client::setUserName(const char* name) {
  118 + snprintf(UserName, USRLENGTH, "%s", name);
  119 +#ifdef LOG4CXX
  120 + // LOG4CXX_DEBUG(_logger, "DD_Client::setUserName - UserName : " << UserName);
114 121 #endif
115 122 }
116 123  
... ... @@ -286,7 +293,9 @@ int DD_Client::DD_SetVariable(char *InstrName)
286 293 int hostlen,userlen;
287 294 char *PUserHost = UserHost, *PUserName = UserName;
288 295 /* We need this because XDR works with adresses of pointers */
289   -
  296 +#ifdef LOG4CXX
  297 + LOG4CXX_DEBUG(_logger, "DD_Client::DD_SetVariable - UserName is undefined");
  298 +#endif
290 299 /* If there is no connection, try to get it */
291 300 if(SocketID < 0)
292 301 if((SocketID = GetSocket()) < 0)
... ... @@ -321,7 +330,12 @@ int DD_Client::DD_SetVariable(char *InstrName)
321 330 xdrmem_create(&xdrs, buffSetVarialbe, REQUESTLENGTH, XDR_FREE);
322 331  
323 332 /*-------- preparation an authorization request ----------------*/
324   - if(UserName[0] == '\0') strcpy(UserName,NONAME);
  333 + if(UserName[0] == '\0') {
  334 + strcpy(UserName,NONAME);
  335 +#ifdef LOG4CXX
  336 + LOG4CXX_ERROR(_logger, "DD_Client::DD_SetVariable - UserName is undefined");
  337 +#endif
  338 + }
325 339 hostlen = strlen(UserHost);
326 340 userlen = strlen(UserName);
327 341  
... ... @@ -330,7 +344,7 @@ int DD_Client::DD_SetVariable(char *InstrName)
330 344 xdr_int(&xdrs,&UserID);
331 345 xdr_string(&xdrs, &PUserHost, hostlen);
332 346 xdr_string(&xdrs, &PUserName, userlen);
333   -/* fprintf(stderr,"userid %d host %s DD_name %s\n",UserID,UserHost,UserName); */
  347 + //fprintf(stderr,"userid %d host %s DD_name %s\n",UserID,UserHost,UserName);
334 348  
335 349 /* Send request */
336 350 if( send(SocketID,buffSetVarialbe,REQUESTLENGTH,0) < 0)
... ...
src/DDClientLibCpp/INCLUDE/DD.hh
... ... @@ -19,6 +19,7 @@
19 19 #ifndef DD_H_
20 20 #define DD_H_
21 21  
  22 +#define LOG4CXX
22 23  
23 24 #include "DD_comm.hh"
24 25 #include "DD_Access.hh"
... ... @@ -98,7 +99,8 @@ public:
98 99  
99 100 int GetUserHost();
100 101  
101   - void setUserHost(const char* host);
  102 + void setUserHost(const char* host);
  103 + void setUserName(const char* name);
102 104  
103 105 int getInfoFromHostName(const char *hostName, struct sockaddr_in &addr);
104 106  
... ... @@ -178,8 +180,8 @@ public:
178 180 */
179 181  
180 182 private:
181   -#ifdef LO4CXX
182   - static log4cxx::LoggerPtr _logger;
  183 +#ifdef LOG4CXX
  184 + static log4cxx::LoggerPtr _logger;
183 185 #endif
184 186 };
185 187 /*--------------------- CONSTANTS -----------------------------------------*/
... ...