diff --git a/apps/dsm/DSMCoreModule.cpp b/apps/dsm/DSMCoreModule.cpp index 866cad6d..6f540339 100644 --- a/apps/dsm/DSMCoreModule.cpp +++ b/apps/dsm/DSMCoreModule.cpp @@ -75,6 +75,7 @@ DSMAction* DSMCoreModule::getAction(const string& from_str) { DEF_CMD("set", SCSetAction); DEF_CMD("append", SCAppendAction); + DEF_CMD("substr", SCSubStrAction); DEF_CMD("inc", SCIncAction); DEF_CMD("log", SCLogAction); DEF_CMD("clear", SCClearAction); @@ -351,6 +352,29 @@ EXEC_ACTION_START(SCAppendAction) { var_name.c_str(), sc_sess->var[var_name].c_str()); } EXEC_ACTION_END; +CONST_ACTION_2P(SCSubStrAction,',', false); +EXEC_ACTION_START(SCSubStrAction) { + string var_name = (par1.length() && par1[0] == '$')? + par1.substr(1) : par1; + unsigned int pos = 0; + if (str2i(resolveVars(par2, sess, sc_sess, event_params), pos)) { + ERROR("substr length '%s'\n", + resolveVars(par2, sess, sc_sess, event_params).c_str()); + sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); + return false; + } + try { + sc_sess->var[var_name] = sc_sess->var[var_name].substr(pos); + } catch(...) { + ERROR("in substr\n"); + sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG); + return false; + } + + DBG("$%s now '%s'\n", + var_name.c_str(), sc_sess->var[var_name].c_str()); +} EXEC_ACTION_END; + EXEC_ACTION_START(SCIncAction) { string var_name = (arg.length() && arg[0] == '$')? arg.substr(1) : arg; diff --git a/apps/dsm/DSMCoreModule.h b/apps/dsm/DSMCoreModule.h index fce60437..ecd9ebb0 100644 --- a/apps/dsm/DSMCoreModule.h +++ b/apps/dsm/DSMCoreModule.h @@ -76,6 +76,7 @@ DEF_SCModSEStrArgAction(SCReturnFSMAction); DEF_ACTION_2P(SCSetAction); DEF_ACTION_2P(SCAppendAction); +DEF_ACTION_2P(SCSubStrAction); DEF_ACTION_1P(SCIncAction); DEF_ACTION_1P(SCClearAction); DEF_ACTION_2P(SCSetTimerAction);