2012-03-16 18:10:31 +01:00
|
|
|
/*
|
|
|
|
* PROGRAM: Firebird interface.
|
|
|
|
* MODULE: IntlParametersBlock.cpp
|
|
|
|
* DESCRIPTION: Convert strings in parameters block to/from UTF8.
|
|
|
|
*
|
|
|
|
* 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) 2012 Alex Peshkov <peshkoff at mail.ru>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "firebird.h"
|
|
|
|
#include "../common/IntlParametersBlock.h"
|
|
|
|
|
|
|
|
#include "consts_pub.h"
|
|
|
|
#include "../common/isc_f_proto.h"
|
|
|
|
#include "../common/classes/ClumpletWriter.h"
|
2012-03-30 14:27:19 +02:00
|
|
|
#include "../common/UtilSvc.h"
|
2014-12-30 16:18:46 +01:00
|
|
|
#include "../common/StatusHolder.h"
|
2012-03-16 18:10:31 +01:00
|
|
|
|
2012-03-30 14:27:19 +02:00
|
|
|
using namespace Firebird;
|
|
|
|
|
|
|
|
namespace
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
|
|
|
|
2012-03-30 14:27:19 +02:00
|
|
|
void strToUtf8(string& s)
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
2012-03-30 14:27:19 +02:00
|
|
|
ISC_systemToUtf8(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void strFromUtf8(string& s)
|
|
|
|
{
|
|
|
|
ISC_unescape(s);
|
|
|
|
ISC_utf8ToSystem(s);
|
|
|
|
}
|
|
|
|
|
2012-04-04 14:54:27 +02:00
|
|
|
void processCommandLine(IntlParametersBlock::ProcessString* processString, string& par)
|
2012-03-30 14:27:19 +02:00
|
|
|
{
|
|
|
|
bool flagIn = false;
|
|
|
|
string current, result;
|
2012-04-05 20:28:44 +02:00
|
|
|
|
2012-03-30 14:27:19 +02:00
|
|
|
for (const char* s = par.begin(); s < par.end(); ++s)
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
2012-03-30 14:27:19 +02:00
|
|
|
if (s[0] == SVC_TRMNTR)
|
|
|
|
{
|
|
|
|
if (!flagIn)
|
|
|
|
{
|
|
|
|
flagIn = true;
|
|
|
|
}
|
|
|
|
else if (s[1] == SVC_TRMNTR)
|
|
|
|
{
|
|
|
|
current += SVC_TRMNTR;
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flagIn = false;
|
|
|
|
processString(current);
|
|
|
|
if (result.hasData())
|
|
|
|
{
|
|
|
|
result += ' ';
|
|
|
|
}
|
|
|
|
result += current;
|
|
|
|
current = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (s[0] != ' ' || flagIn || current.hasData())
|
|
|
|
{
|
|
|
|
current += s[0];
|
|
|
|
}
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
2012-03-30 14:27:19 +02:00
|
|
|
if (current.hasData())
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
2012-03-30 14:27:19 +02:00
|
|
|
processString(current);
|
|
|
|
if (result.hasData())
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
2012-03-30 14:27:19 +02:00
|
|
|
result += ' ';
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
2012-03-30 14:27:19 +02:00
|
|
|
result += current;
|
|
|
|
}
|
|
|
|
|
|
|
|
par = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Firebird
|
|
|
|
{
|
|
|
|
|
|
|
|
void IntlParametersBlock::toUtf8(ClumpletWriter& pb, UCHAR utf8Tag)
|
|
|
|
{
|
|
|
|
if (utf8Tag)
|
|
|
|
{
|
|
|
|
pb.insertTag(utf8Tag);
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
2012-03-30 14:27:19 +02:00
|
|
|
|
|
|
|
processParametersBlock(strToUtf8, pb);
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntlParametersBlock::fromUtf8(ClumpletWriter& pb, UCHAR utf8Tag)
|
|
|
|
{
|
|
|
|
if (utf8Tag)
|
|
|
|
{
|
|
|
|
pb.deleteWithTag(utf8Tag);
|
|
|
|
}
|
|
|
|
|
2012-03-30 14:27:19 +02:00
|
|
|
processParametersBlock(strFromUtf8, pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IntlParametersBlock::processParametersBlock(ProcessString* processString, ClumpletWriter& pb)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
const char* tagName = NULL;
|
|
|
|
try
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
for (pb.rewind(); !pb.isEof(); )
|
|
|
|
{
|
|
|
|
UCHAR tag = pb.getClumpTag();
|
|
|
|
string s;
|
2012-03-30 14:27:19 +02:00
|
|
|
|
2014-12-30 16:18:46 +01:00
|
|
|
tagName = NULL;
|
|
|
|
switch (checkTag(tag, &tagName))
|
|
|
|
{
|
|
|
|
case TAG_SKIP:
|
|
|
|
pb.moveNext();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAG_STRING:
|
|
|
|
pb.getString(s);
|
|
|
|
processString(s);
|
|
|
|
pb.deleteClumplet();
|
|
|
|
pb.insertString(tag, s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAG_COMMAND_LINE:
|
|
|
|
pb.getString(s);
|
|
|
|
processCommandLine(processString, s);
|
|
|
|
pb.deleteClumplet();
|
|
|
|
pb.insertString(tag, s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-12 01:03:43 +01:00
|
|
|
catch (const Firebird::status_exception& st)
|
2014-12-30 16:18:46 +01:00
|
|
|
{
|
2015-03-27 18:51:19 +01:00
|
|
|
LocalStatus ls;
|
|
|
|
CheckStatusWrapper l(&ls);
|
2014-12-30 16:18:46 +01:00
|
|
|
st.stuffException(&l);
|
2015-02-18 16:01:17 +01:00
|
|
|
if ((l.getState() & IStatus::STATE_ERRORS) && (l.getErrors()[1] == isc_bad_conn_str) && tagName)
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
Arg::Gds newErrors(isc_random);
|
|
|
|
string message("Bad international character in tag ");
|
|
|
|
message += tagName;
|
|
|
|
newErrors << message;
|
2012-03-30 14:27:19 +02:00
|
|
|
|
2014-12-30 16:18:46 +01:00
|
|
|
const ISC_STATUS* errors = l.getErrors();
|
|
|
|
newErrors << Arg::StatusVector(errors + 2); // skip isc_bad_conn_str
|
2012-03-30 14:27:19 +02:00
|
|
|
|
2014-12-30 16:18:46 +01:00
|
|
|
l.setErrors(newErrors.value());
|
|
|
|
status_exception::raise(&l);
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
2014-12-30 16:18:46 +01:00
|
|
|
|
|
|
|
// other case leave exception as is
|
|
|
|
throw;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 03:26:59 +01:00
|
|
|
|
2014-12-30 16:18:46 +01:00
|
|
|
#define FB_IPB_TAG(t) case t: if (!*tagName) *tagName = #t
|
|
|
|
|
|
|
|
|
|
|
|
IntlParametersBlock::TagType IntlDpb::checkTag(UCHAR tag, const char** tagName)
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_dpb_user_name);
|
|
|
|
FB_IPB_TAG(isc_dpb_password);
|
|
|
|
FB_IPB_TAG(isc_dpb_sql_role_name);
|
|
|
|
FB_IPB_TAG(isc_dpb_trusted_auth);
|
|
|
|
FB_IPB_TAG(isc_dpb_trusted_role);
|
|
|
|
FB_IPB_TAG(isc_dpb_working_directory);
|
|
|
|
FB_IPB_TAG(isc_dpb_set_db_charset);
|
|
|
|
FB_IPB_TAG(isc_dpb_process_name);
|
|
|
|
FB_IPB_TAG(isc_dpb_host_name);
|
|
|
|
FB_IPB_TAG(isc_dpb_os_user);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_STRING;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_SKIP;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
2012-03-17 03:26:59 +01:00
|
|
|
|
2014-12-30 16:18:46 +01:00
|
|
|
IntlParametersBlock::TagType IntlSpb::checkTag(UCHAR tag, const char** tagName)
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_spb_user_name);
|
|
|
|
FB_IPB_TAG(isc_spb_password);
|
|
|
|
FB_IPB_TAG(isc_spb_sql_role_name);
|
|
|
|
FB_IPB_TAG(isc_spb_trusted_auth);
|
|
|
|
FB_IPB_TAG(isc_spb_trusted_role);
|
|
|
|
FB_IPB_TAG(isc_spb_process_name);
|
|
|
|
FB_IPB_TAG(isc_spb_expected_db);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_STRING;
|
|
|
|
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_spb_command_line);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_COMMAND_LINE;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_SKIP;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
2012-03-17 03:26:59 +01:00
|
|
|
|
2014-12-30 16:18:46 +01:00
|
|
|
IntlParametersBlock::TagType IntlSpbStart::checkTag(UCHAR tag, const char** tagName)
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
2012-03-17 03:26:59 +01:00
|
|
|
switch (mode)
|
2012-03-16 18:10:31 +01:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_spb_dbname);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_STRING;
|
2012-03-16 18:10:31 +01:00
|
|
|
|
|
|
|
case isc_action_svc_backup:
|
|
|
|
case isc_action_svc_restore:
|
|
|
|
case isc_action_svc_repair:
|
|
|
|
case isc_action_svc_add_user:
|
|
|
|
case isc_action_svc_delete_user:
|
|
|
|
case isc_action_svc_modify_user:
|
|
|
|
case isc_action_svc_display_user:
|
|
|
|
case isc_action_svc_display_user_adm:
|
|
|
|
case isc_action_svc_nbak:
|
|
|
|
case isc_action_svc_nrest:
|
|
|
|
case isc_action_svc_trace_start:
|
|
|
|
case isc_action_svc_db_stats:
|
2015-06-19 14:07:41 +02:00
|
|
|
case isc_action_svc_validate:
|
2012-03-16 18:10:31 +01:00
|
|
|
mode = tag;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case isc_action_svc_backup:
|
|
|
|
case isc_action_svc_restore:
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_spb_bkp_file);
|
|
|
|
FB_IPB_TAG(isc_spb_bkp_skip_data);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_STRING;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case isc_action_svc_repair:
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_spb_tra_db_path);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_STRING;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case isc_action_svc_add_user:
|
|
|
|
case isc_action_svc_delete_user:
|
|
|
|
case isc_action_svc_modify_user:
|
|
|
|
case isc_action_svc_display_user:
|
|
|
|
case isc_action_svc_display_user_adm:
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_spb_sec_username);
|
|
|
|
FB_IPB_TAG(isc_spb_sec_password);
|
|
|
|
FB_IPB_TAG(isc_spb_sec_groupname);
|
|
|
|
FB_IPB_TAG(isc_spb_sec_firstname);
|
|
|
|
FB_IPB_TAG(isc_spb_sec_middlename);
|
|
|
|
FB_IPB_TAG(isc_spb_sec_lastname);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_STRING;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case isc_action_svc_nbak:
|
|
|
|
case isc_action_svc_nrest:
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_spb_nbk_file);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_STRING;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case isc_action_svc_trace_start:
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_spb_trc_name);
|
|
|
|
FB_IPB_TAG(isc_spb_trc_cfg);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_STRING;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case isc_action_svc_db_stats:
|
|
|
|
switch (tag)
|
|
|
|
{
|
2014-12-30 16:18:46 +01:00
|
|
|
FB_IPB_TAG(isc_spb_command_line);
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_COMMAND_LINE;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
break;
|
2015-06-19 14:07:41 +02:00
|
|
|
|
|
|
|
case isc_action_svc_validate:
|
|
|
|
switch (tag)
|
|
|
|
{
|
|
|
|
FB_IPB_TAG(isc_spb_dbname);
|
|
|
|
FB_IPB_TAG(isc_spb_val_tab_incl);
|
|
|
|
FB_IPB_TAG(isc_spb_val_tab_excl);
|
|
|
|
FB_IPB_TAG(isc_spb_val_idx_incl);
|
|
|
|
FB_IPB_TAG(isc_spb_val_idx_excl);
|
|
|
|
return TAG_STRING;
|
|
|
|
}
|
|
|
|
break;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
2012-03-30 14:27:19 +02:00
|
|
|
return TAG_SKIP;
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|
|
|
|
|
2014-12-30 16:18:46 +01:00
|
|
|
|
|
|
|
#undef FB_IPB_TAG
|
|
|
|
|
2012-03-16 18:10:31 +01:00
|
|
|
}
|