/** 引数を解析 * * オプション=>値のマップに構築 * * オプションに対する入力ではない引数は、ヌルストリングキーに入る。ArgMap[string("")] * * この中でプログラム本体のパスを読み飛ばすので、main関数の引数をそのまま渡してください。 * * @return パーズエラーの場合false * @author SAM (T&GG, Org.) <*****@*****.**> * @date 2002/12/31 16:48:01 * $Id: argmap.cpp,v 1.3 2005/02/21 02:21:12 takasugi Exp $ * * Copyright (C) 2001,2002 SAM (T&GG, Org.) <*****@*****.**>. All rights reserved. */ bool WArgMap::parse(int argc, wchar_t *argv[]) { argc--; argv++; wstring cur_key; for(int i = 0; i < argc; i++) { if(argv[i][0] == L'-') { if(argv[i][1] == L'-') { if(argv[i][2] == L'-') { add(wstring(L""), wstring(argv[i])); } else { cur_key = argv[i]+2; if(!doseKeyHasVal(cur_key)) { (*this)[cur_key]; cur_key = L""; } } } else { if(!checkOpt(argv[i]+1, cur_key)) return false; } } else { if(cur_key.length()) { add(cur_key, wstring(argv[i])); cur_key = L""; } else { add(wstring(L""), wstring(argv[i])); } } } return cur_key.length()==0; }
int main (int argc, char ** argv) { checkOpt(argc, argv); if (checkLogin() == 1) { startCalculator(); } return 0; }
std::string TlsOptions::getStringOption( tls_option opt ) const { char *value; checkOpt(opt, STRING); ldap_get_option( m_ld, optmap[opt].optval, (void*) &value); std::string strval; if (value) { strval=std::string(value); ldap_memfree(value); } return strval; }
void TlsOptions::setOption( tls_option opt, const std::string& value ) const { checkOpt(opt, STRING); switch(opt) { case TlsOptions::CACERTFILE : case TlsOptions::CERTFILE : case TlsOptions::KEYFILE : { // check if the supplied file is actually readable std::ifstream ifile(value.c_str()); if ( !ifile ) { throw( LDAPException( LDAP_LOCAL_ERROR, "Unable to open the supplied file for reading" ) ); } } break; case TlsOptions::CACERTDIR : { struct stat st; std::ostringstream msg; bool fail=false; int err = stat(value.c_str(),&st); if ( err ) { msg << strerror(errno); fail = true; } else { if ( !S_ISDIR(st.st_mode) ){ msg << "The supplied path is not a directory."; fail = true; } } if ( fail ) { std::ostringstream errstr; errstr << "Error while setting Certificate Directory (" << value << "): " << msg.str(); throw( LDAPException( LDAP_LOCAL_ERROR, errstr.str() ) ); } } break; } this->setOption( opt, value.empty() ? NULL : (void*) value.c_str() ); }
int TlsOptions::getIntOption( tls_option opt ) const { int value; checkOpt(opt, INT); ldap_get_option( m_ld, optmap[opt].optval, (void*) &value); return value; }
void TlsOptions::setOption( tls_option opt, int value ) const { checkOpt(opt, INT); this->setOption( opt, (void*) &value); }
void TlsOptions::setOption( tls_option opt, const std::string& value ) const { checkOpt(opt, STRING); this->setOption( opt, value.empty() ? NULL : (void*) value.c_str() ); }