/* * PROGRAM: Firebird utilities interface * MODULE: UtilSvc.cpp * DESCRIPTION: Interface making it possible to use same code * as both utility or service * * The contents of this file are subject to the Initial * Developer's Public License Version 1.0 (the "License"); * you may not use this file except in compliance with the * License. You may obtain a copy of the License at * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. * * Software distributed under the License is distributed AS IS, * WITHOUT WARRANTY OF ANY KIND, either express or implied. * See the License for the specific language governing rights * and limitations under the License. * * The Original Code was created by Alex Peshkov * for the Firebird Open Source RDBMS project. * * Copyright (c) 2007 Alex Peshkov * and all contributors signed below. * * All Rights Reserved. * Contributor(s): ______________________________________. * * */ #include "firebird.h" #include "../common/UtilSvc.h" #include "../common/classes/alloc.h" #include "iberror.h" #include #include namespace Firebird { class StandaloneUtilityInterface : public UtilSvc { public: StandaloneUtilityInterface(int ac, char** av) { while (ac--) { argv.push(*av++); } } virtual void printf(const SCHAR* format, ...) { va_list arglist; va_start(arglist, format); int rc = ::vprintf(format, arglist); va_end(arglist); if (rc < 0) { Firebird::system_call_failed::raise("StandaloneUtilityInterface::printf()/vprintf()"); } } virtual void hidePasswd(ArgvType& argv, int pos) { const size_t l = strlen(argv[pos]); char* data = FB_NEW(getPool()) char[l + 1]; memcpy(data, argv[pos], l); data[l] = 0; // here const-correctness is violated to make the rest 99.9% // places of code much more clear char* hide = const_cast(argv[pos]); argv[pos] = data; memset(hide, '*', l); } virtual bool isService() { return false; } virtual void checkService() { Firebird::status_exception::raise(isc_utl_trusted_switch, 0); } // do nothing for non-service virtual void finish() { } virtual void started() { } virtual void putLine(char, const char*) { } virtual void putSLong(char, SLONG) { } virtual void putChar(char, char) { } virtual void stuffStatus(const ISC_STATUS*) { } virtual void stuffStatus(const USHORT, const USHORT, const MsgFormat::SafeArg&) { } virtual ISC_STATUS* getStatus() { return 0; } }; UtilSvc* UtilSvc::createStandalone(int ac, char** av) { return new StandaloneUtilityInterface(ac, av); } } // namespace Firebird