Back to index

im-sdk  12.3.91
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
IMSvrArg Class Reference

#include <IMSvrArg.hh>

Inheritance diagram for IMSvrArg:
Inheritance graph
[legend]
Collaboration diagram for IMSvrArg:
Collaboration graph
[legend]

List of all members.

Classes

struct  ArgVal
struct  ArgVal.arg

Public Types

enum  IMSvrCfgOpt {
  IMDIR = 0, BASICLOCALE, IFPATHNAME, IFNAME,
  PORT, HOSTNAME, NSMAP_CFG_FILE, CONFIGFILE,
  LECONFFILE, CONVERSIONKEYS, LABEL, SETTRIGGEROFFKEYS,
  IMCONFIG, DIRECT_XSUNIM, LOG_FACILITY, LOG_LEVEL,
  MESSAGE_LOCALE, LOOKUPROW, LOOKUPCOL, NODAEMON,
  DEBUGFLAG, USER, VARDIR, DESKTOP,
  PREFERRED_LOADING, CFGOPT_LAST
}

Public Member Functions

virtual bool configure (IMSvr *pimsvr)
 IMSvrArg (int argc, char **argv)
virtual ~IMSvrArg ()
bool get_boolval (enum IMSvrCfgOpt opt) const
int get_numval (enum IMSvrCfgOpt opt) const
const char * get_strval (enum IMSvrCfgOpt opt) const
void showall () const
const char * get_command_name ()

Protected Types

enum  CfgType {
  ARG_UNINIT = 0, ARG_INVALID, ARG_BOOL, ARG_NUMBER,
  ARG_STRING
}

Protected Member Functions

enum CfgType get_type (enum IMSvrCfgOpt opt)
const string & get_description (enum IMSvrCfgOpt opt)
void setbool (enum IMSvrCfgOpt opt, bool boolval)
void setnum (enum IMSvrCfgOpt opt, int numval)
void setstr (enum IMSvrCfgOpt opt, const char *strval)
bool get_process_user (string &user)
bool get_home_dir (string &dir)
IMUserMgrget_usermgr (IMSvr *pimsvr)
bool config_lepath (IMSvr *pimsvr, const char *lepath)
bool config_listenaddress (IMSvr *pimsvr, IMSocketAddressVec &addrvec)
bool config_le (IMSvr *pimsvr, const char *lepath, IIIMLEXMLConf &xml, bool preferred_loading)
bool set_nsmap_config (IMSvr *pimsvr, IMNsMapStruct *nsm, int num_entries)

Private Types

typedef map< const char
*, ArgVal, Functor_strcmp
IMSvrArgMap

Private Member Functions

void show_usage ()
void addopt (enum IMSvrCfgOpt opt, const char *option)
void initialize ()
bool parse_arguments (int argc, char **argv)
bool set_argopt ()

Private Attributes

bool valid_flag
IMSvrXMLConfpxmlsvrcfg
IIIMLEXMLConf * pxmllecfg
IMNSMapConfpnsmapcfg
IMSvrArgMap optmap

Detailed Description

Definition at line 10 of file IMSvrArg.hh.


Class Documentation

struct IMSvrArg::ArgVal.arg

Definition at line 20 of file IMSvrArg.hh.

Class Members
bool b
int n
string s

Member Typedef Documentation

typedef map<const char*, ArgVal, Functor_strcmp> IMSvrArg::IMSvrArgMap [private]

Definition at line 33 of file IMSvrArg.hh.


Member Enumeration Documentation

enum IMSvrCfg::CfgType [protected, inherited]
Enumerator:
ARG_UNINIT 
ARG_INVALID 
ARG_BOOL 
ARG_NUMBER 
ARG_STRING 

Definition at line 46 of file IMSvrCfg.hh.

enum IMSvrCfg::IMSvrCfgOpt [inherited]
Enumerator:
IMDIR 
BASICLOCALE 
IFPATHNAME 
IFNAME 
PORT 
HOSTNAME 
NSMAP_CFG_FILE 
CONFIGFILE 
LECONFFILE 
CONVERSIONKEYS 
LABEL 
SETTRIGGEROFFKEYS 
IMCONFIG 
DIRECT_XSUNIM 
LOG_FACILITY 
LOG_LEVEL 
MESSAGE_LOCALE 
LOOKUPROW 
LOOKUPCOL 
NODAEMON 
DEBUGFLAG 
USER 
VARDIR 
DESKTOP 
PREFERRED_LOADING 
CFGOPT_LAST 

Definition at line 13 of file IMSvrCfg.hh.


Constructor & Destructor Documentation

IMSvrArg::IMSvrArg ( int  argc,
char **  argv 
)

Definition at line 329 of file IMSvrArg.cpp.

Here is the call graph for this function:

IMSvrArg::~IMSvrArg ( ) [virtual]

Definition at line 342 of file IMSvrArg.cpp.

Here is the call graph for this function:


Member Function Documentation

void IMSvrArg::addopt ( enum IMSvrCfgOpt  opt,
const char *  option 
) [private]

Definition at line 321 of file IMSvrArg.cpp.

{
    optmap.insert(IMSvrArgMap::value_type(option, ArgVal(opt)));
}

Here is the caller graph for this function:

bool IMSvrCfg::config_le ( IMSvr pimsvr,
const char *  lepath,
IIIMLEXMLConf &  xml,
bool  preferred_loading 
) [inline, protected, inherited]

Definition at line 120 of file IMSvrCfg.hh.

       { return pimsvr->config_le(lepath, xml, preferred_loading); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool IMSvrCfg::config_lepath ( IMSvr pimsvr,
const char *  lepath 
) [inline, protected, inherited]

Definition at line 116 of file IMSvrCfg.hh.

    { return pimsvr->config_lepath(lepath); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool IMSvrCfg::config_listenaddress ( IMSvr pimsvr,
IMSocketAddressVec addrvec 
) [inline, protected, inherited]

Definition at line 118 of file IMSvrCfg.hh.

    { return pimsvr->config_listenaddress(addrvec); }

Here is the call graph for this function:

Here is the caller graph for this function:

bool IMSvrArg::configure ( IMSvr pimsvr) [virtual]

Implements IMSvrCfg.

Definition at line 137 of file IMSvrArg.cpp.

{
    if (!valid_flag) return false;

    if (!set_argopt()) return false;

    if (!pxmlsvrcfg) {
        if (get_boolval(USER)) {
           struct stat st;
            string home_dir, conffile;

            // iiimd run as per-user daemon.
            // use ~/.iiim/iiimd.conf as a default configuration file.
            if (!get_home_dir(home_dir)) return false;

           conffile = home_dir + string("/.iiim/iiimd.xml.conf");
           if (stat(conffile.c_str(), &st) == -1) {
              /* it was failed to stat. use the system-wide config */
              conffile = string(get_strval(IMSvrCfg::CONFIGFILE));
           }
           pxmlsvrcfg = new IMSvrXMLConf(this, conffile.c_str());
        } else {
           pxmlsvrcfg = new IMSvrXMLConf(this, get_strval(IMSvrCfg::CONFIGFILE));
        }
    }
    if (!pxmllecfg) {
       if (get_boolval(USER)) {
           /*
            * iiimd run as per-user daemon.
            * use ~/.iiim/le.xml.conf as a default configuration file.
            */
           string home_dir;
           if (!get_home_dir(home_dir))
              return false;
           pxmllecfg = iiim_le_xmlconf_new((home_dir + string("/.iiim/le.xml.conf")).c_str());
       } else {
           pxmllecfg = iiim_le_xmlconf_new(get_strval(IMSvrCfg::LECONFFILE));
       }
    }

    /* turn on debug mode. */
    if (get_boolval(DEBUGFLAG)) {
       // output full debug info to stderr.
       IMLog::get_instance()->set_log_level(IMLog::DEBUGLOG);
       IMLog::get_instance()->set_default_destination(IMLog::IMLOG_STDERR);
       LOG_DEBUG("Turn on debug mode.");
    } else if (!get_boolval(NODAEMON)) {
       // make the program daemon.
       IMDaemon::get_instance()->setup(get_strval(IMSvrCfg::IMDIR));
    }
    /* ... actual configuration ... */
    // file base configuration.
    if (pxmlsvrcfg) {
       if (!pxmlsvrcfg->configure(pimsvr))
           return false;
    }
    if (pxmllecfg) {
       /* don't bother the return value to allow to run without xml conf */
       iiim_le_xmlconf_load_file(pxmllecfg);
    }
    if (!set_argopt()) return false;

    get_usermgr(pimsvr)->set_command_name(get_command_name());

#if 0
    /* LE path */
    config_lepath(pimsvr, get_strval(IMSvrCfg::IFPATHNAME));
#else
    config_le(pimsvr,
             get_strval(IMSvrCfg::IFPATHNAME),
             *pxmllecfg,
             get_boolval(IMSvrCfg::PREFERRED_LOADING));
#endif

    /* IMLog */
    if (!get_boolval(DEBUGFLAG)) {
       enum IMLog::LOG_LEVEL lv;
       lv = convert_log_level_string(get_strval(IMSvrCfg::LOG_LEVEL));
       if (lv == IMLog::INVALID) {
           LOG_ERROR("Invalid log level %s.", get_strval(IMSvrCfg::LOG_LEVEL));
           return false;
       }

       enum IMLog::LOG_DESTINATION dest;
       dest = convert_log_facility_string(get_strval(IMSvrCfg::LOG_FACILITY));
       if (lv == IMLog::INVALID) {
           LOG_ERROR("Invalid log facility %s.", get_strval(IMSvrCfg::LOG_FACILITY));
           return false;
       }

       IMLog::get_instance()->set_log_level(lv);
       IMLog::get_instance()->set_default_destination(dest);
       LOG_INFO("Set log facility to %s, log level to %s.",
               get_strval(IMSvrCfg::LOG_FACILITY),              
               get_strval(IMSvrCfg::LOG_LEVEL));
    }


    /* By default, allow the connection from localhost. */
    get_usermgr(pimsvr)->set_entry("localhost", IMAuth::PERMIT);
    get_usermgr(pimsvr)->set_entry("localhost.localdomain", IMAuth::PERMIT);

    if (!pnsmapcfg) {
      pnsmapcfg = new IMNSMapConf(get_strval(IMSvrCfg::NSMAP_CFG_FILE));
    }

    if (pnsmapcfg) {
       pnsmapcfg->load();
    }

    int count;
    IMNsMapStruct *nsmp = pnsmapcfg->get_nsmap_info(&count);
    set_nsmap_config(pimsvr, nsmp, count);

    LOG_NORMAL("started.");

    return true;
}

Here is the call graph for this function:

bool IMSvrCfg::get_boolval ( enum IMSvrCfgOpt  opt) const [inherited]

Definition at line 221 of file IMSvrCfg.cpp.

{
    if ((opt >= CFGOPT_LAST)
       || (popts[opt].type != ARG_BOOL)) {
       ERROR_INTERNAL("Invalid argument access.");
    }

    return popts[opt].v.b;
}

Here is the caller graph for this function:

const char* IMSvrCfg::get_command_name ( ) [inline, inherited]

Definition at line 138 of file IMSvrCfg.hh.

    { return command_name.c_str(); }

Here is the caller graph for this function:

const string& IMSvrCfg::get_description ( enum IMSvrCfgOpt  opt) [inline, protected, inherited]

Definition at line 71 of file IMSvrCfg.hh.

    { return popts[opt].description; }
bool IMSvrCfg::get_home_dir ( string &  dir) [protected, inherited]

Definition at line 18 of file IMSvrCfg.cpp.

{

#ifdef HAVE_PWENT
    struct passwd *pass;
#  if defined (HAVE_POSIX_GETPWUID_R) || defined (HAVE_NONPOSIX_GETPWUID_R)
#ifndef NSS_BUFLEN_PASSWD
#define NSS_BUFLEN_PASSWD 1024
#endif
    struct passwd pass_buf;
    char buf[NSS_BUFLEN_PASSWD];

#    ifdef HAVE_POSIX_GETPWUID_R
    if (getpwuid_r(geteuid(), &pass_buf, buf, NSS_BUFLEN_PASSWD, &pass) != 0) {
        return false;
    }
#else
    if ((pass = getpwuid_r(geteuid(), &pass_buf, buf, NSS_BUFLEN_PASSWD))
       != NULL) {
        return false;
    }
#endif
#else /* !HAVE_GETPWUID_R || !HAVE_NONPOSIX_GETPWUID_R */
    if ((pass = getpwuid(geteuid())) == NULL) {
        return false;
    } 
#endif
    dir = string(pass->pw_dir);
    return true;
#else
    return false;
#endif
}

Here is the caller graph for this function:

int IMSvrCfg::get_numval ( enum IMSvrCfgOpt  opt) const [inherited]

Definition at line 235 of file IMSvrCfg.cpp.

{
    if ((opt >= CFGOPT_LAST)
       || (popts[opt].type != ARG_NUMBER)) {
       ERROR_INTERNAL("Invalid argument access.");
    }

    return popts[opt].v.n;
}
bool IMSvrCfg::get_process_user ( string &  user) [protected, inherited]

Definition at line 54 of file IMSvrCfg.cpp.

{

#ifdef HAVE_PWENT
    struct passwd *pass;
#  if defined (HAVE_POSIX_GETPWUID_R) || defined (HAVE_NONPOSIX_GETPWUID_R)
#ifndef NSS_BUFLEN_PASSWD
#define NSS_BUFLEN_PASSWD 1024
#endif
    struct passwd pass_buf;
    char buf[NSS_BUFLEN_PASSWD];

#    ifdef HAVE_POSIX_GETPWUID_R
    if (getpwuid_r(geteuid(), &pass_buf, buf, NSS_BUFLEN_PASSWD, &pass) != 0) {
        return false;
    }
#else
    if ((pass = getpwuid_r(geteuid(), &pass_buf, buf, NSS_BUFLEN_PASSWD))
       != NULL) {
        return false;
    }
#endif
#else /* !HAVE_GETPWUID_R || !HAVE_NONPOSIX_GETPWUID_R */
    if ((pass = getpwuid(geteuid())) == NULL) {
        return false;
    } 
#endif
    username = string(pass->pw_name);
    return true;
#else
    return false;
#endif
}

Here is the caller graph for this function:

const char * IMSvrCfg::get_strval ( enum IMSvrCfgOpt  opt) const [inherited]

Definition at line 249 of file IMSvrCfg.cpp.

{
    if ((opt >= CFGOPT_LAST)
       || (popts[opt].type != ARG_STRING)) {
       ERROR_INTERNAL("Invalid argument access.");
    }

    return popts[opt].v.s.c_str();
}

Here is the caller graph for this function:

enum CfgType IMSvrCfg::get_type ( enum IMSvrCfgOpt  opt) [inline, protected, inherited]

Definition at line 69 of file IMSvrCfg.hh.

    { return popts[opt].type; }

Here is the caller graph for this function:

IMUserMgr* IMSvrCfg::get_usermgr ( IMSvr pimsvr) [inline, protected, inherited]

Definition at line 114 of file IMSvrCfg.hh.

    { return &pimsvr->usermgr; }

Here is the caller graph for this function:

void IMSvrArg::initialize ( ) [private]

Reimplemented from IMSvrCfg.

Definition at line 21 of file IMSvrArg.cpp.

{
    addopt(IMDIR, "imdir");
    addopt(BASICLOCALE, "lc_basiclocale");
    addopt(IFPATHNAME, "ifpath_name");
    addopt(IFNAME, "if");
    addopt(PORT, "port");
    addopt(HOSTNAME, "hostname");
    addopt(NSMAP_CFG_FILE, "ns_map");
    addopt(CONFIGFILE, "cf");
    addopt(CONVERSIONKEYS, "conversionkeys");
    addopt(LABEL, "label");
    addopt(SETTRIGGEROFFKEYS, "setTriggerOffKeys");
    // addopt(IMCONFIG, "imconfig");
    // addopt(DIRECT_XSUNIM, "direct_xsunim");
    // addopt(SYSLOG, "syslog");
    addopt(MESSAGE_LOCALE, "message_locale");
    addopt(LOOKUPROW, "lookupRow");
    addopt(LOOKUPCOL, "lookupRow");
    addopt(NODAEMON, "nodaemon");
    addopt(DEBUGFLAG, "d");
    addopt(USER, "user");
    addopt(VARDIR, "vardir");
#if defined(HAVE_UNIX_SOCKET)
    addopt(UDSFILE, "udsfile");
#endif /* HAVE_UNIX_SOCKET */
    addopt(DESKTOP, "desktop");
    addopt(PREFERRED_LOADING, "preferredload");
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IMSvrArg::parse_arguments ( int  argc,
char **  argv 
) [private]

Definition at line 259 of file IMSvrArg.cpp.

{
    int i;
    char *key;
    IMSvrArgMap::iterator it;
    enum IMSvrCfgOpt opt;

    for (i = 1; i < argc;) {
       key = argv[i];
       if (*key != '-') {
           show_usage();
           return false;
       }
       key++;
       it = optmap.find(key);
       if (optmap.end() == it) {
           show_usage();
           return false;
       }
       ArgVal &val = it->second;
       opt = val.opt;
       if (val.specified) {
           fprintf(stderr, "Duplicated option:%s\n", key);
           show_usage();
           return false;
       }

       if (get_type(opt) == IMSvrCfg::ARG_BOOL) {
           val.arg.b = true;
           val.specified = true;
       } else {
           i++;
           if (i >= argc) {
              show_usage();
              return false;
           }
           if (get_type(opt) == IMSvrCfg::ARG_NUMBER) {
              char *ptr;
              long num;
              num = strtol(argv[i], &ptr, 10);
              if (*ptr != '\0') {
                  show_usage();
                  return false;
              }
              val.arg.n = num;
              val.specified = true;
           } else if (get_type(opt) == IMSvrCfg::ARG_STRING) {
              val.arg.s = argv[i];
              val.specified = true;
           } else {
              ERROR_INTERNAL("Argument type is invalid.");
           }
       }
       i++;
    }
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IMSvrArg::set_argopt ( ) [private]

Definition at line 108 of file IMSvrArg.cpp.

{
    IMSvrArgMap::iterator it;
    enum IMSvrCfgOpt opt;

    for (it = optmap.begin(); it != optmap.end(); it++) {
       ArgVal &val = it->second;
       if (val.specified) {
           opt = val.opt;
           switch (get_type(opt)) {
             case IMSvrCfg::ARG_BOOL:
              setbool(opt, val.arg.b);
              break;
             case IMSvrCfg::ARG_NUMBER:
              setnum(opt, val.arg.n);
              break;
             case IMSvrCfg::ARG_STRING:
              setstr(opt, val.arg.s.c_str());
              break;
             default:
              ERROR_INTERNAL("Argument type is invalid.  That must not happen...");
           }
       }
    }

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IMSvrCfg::set_nsmap_config ( IMSvr pimsvr,
IMNsMapStruct nsm,
int  num_entries 
) [inline, protected, inherited]

Definition at line 122 of file IMSvrCfg.hh.

    { return pimsvr->set_nsmap_config(nsm, num_entries); }

Here is the call graph for this function:

Here is the caller graph for this function:

void IMSvrCfg::setbool ( enum IMSvrCfgOpt  opt,
bool  boolval 
) [protected, inherited]

Definition at line 181 of file IMSvrCfg.cpp.

{
    if (popts[opt].type != ARG_BOOL) {
       ERROR_INTERNAL("Invalid argument access.");
    }
    popts[opt].v.b = boolval;
}

Here is the caller graph for this function:

void IMSvrCfg::setnum ( enum IMSvrCfgOpt  opt,
int  numval 
) [protected, inherited]

Definition at line 194 of file IMSvrCfg.cpp.

{
    if (popts[opt].type != ARG_NUMBER) {
       ERROR_INTERNAL("Invalid argument access.");
    }
    popts[opt].v.n = numval;
}

Here is the caller graph for this function:

void IMSvrCfg::setstr ( enum IMSvrCfgOpt  opt,
const char *  strval 
) [protected, inherited]

Definition at line 207 of file IMSvrCfg.cpp.

{
    if (popts[opt].type != ARG_STRING) {
       ERROR_INTERNAL("Invalid argument access.");
    }
    popts[opt].v.s = strval;
}

Here is the caller graph for this function:

void IMSvrArg::show_usage ( ) [private]

Definition at line 9 of file IMSvrArg.cpp.

{
    fprintf(stderr,
           "iiimd [-d] [-lc_basiclocale localename] \n"
           "      [-ifpath_name ifpath] [-if ifname] \n"
           "      [-port portnumber] [-hostname hostname] \n"
           "      [-conversionkeys keys] \n"
           "      [-ns_map filename ] \n"
           "      [-preferredload] \n" );
}

Here is the caller graph for this function:

void IMSvrCfg::showall ( ) const [inherited]

Definition at line 262 of file IMSvrCfg.cpp.

{
    int i;
    for (i = 0; i < CFGOPT_LAST; i++) {
       switch(popts[i].type) {
         case ARG_BOOL:
          if (popts[i].v.b) {
              LOG_DEBUG("%s[%d]:true", popts[i].description.c_str(), (int)popts[i].opt);
          } else {
              LOG_DEBUG("%s[%d]:false", popts[i].description.c_str(), (int)popts[i].opt);
          }
          break;
         case ARG_NUMBER:
          LOG_DEBUG("%s[%d]:%d", popts[i].description.c_str(), (int)popts[i].opt, popts[i].v.n);
          break;
         case ARG_STRING:
          LOG_DEBUG("%s[%d]:%s", popts[i].description.c_str(), (int)popts[i].opt, popts[i].v.s.c_str());
          break;
         default:
          ERROR_INTERNAL("Invalid arg type.");
          break;
       }
    }

    return;
}

Member Data Documentation

Definition at line 34 of file IMSvrArg.hh.

Definition at line 15 of file IMSvrArg.hh.

IIIMLEXMLConf* IMSvrArg::pxmllecfg [private]

Definition at line 14 of file IMSvrArg.hh.

Definition at line 13 of file IMSvrArg.hh.

bool IMSvrArg::valid_flag [private]

Definition at line 12 of file IMSvrArg.hh.


The documentation for this class was generated from the following files: