Esempio n. 1
0
long CMUSHclientDoc::GetAlphaOptionIndex (LPCTSTR OptionName) 
  {

int iItem;
int iResult = FindBaseAlphaOption (OptionName, AlphaOptionsTable, iItem);

  if (iResult != eOK)
    return -1;
  
  return iItem;

  }   // end of CMUSHclientDoc::GetAlphaOptionIndex 
Esempio n. 2
0
long CMUSHclientDoc::SetAlphaOption(LPCTSTR OptionName, LPCTSTR Value) 
  {

int iItem;
int iResult = FindBaseAlphaOption (OptionName, AlphaOptionsTable, iItem);

  if (iResult != eOK)
    return iResult;

  if (m_CurrentPlugin &&
      (AlphaOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_WRITE))
    return ePluginCannotSetOption;

  return SetAlphaOptionItem (iItem, Value, true, false);

} // end of CMUSHclientDoc::SetAlphaOption
Esempio n. 3
0
long CMUSHclientDoc::SetTriggerOption(LPCTSTR TriggerName, LPCTSTR OptionName, LPCTSTR Value) 
{
CString strTriggerName = TriggerName;
CString strValue = Value;
CTrigger * trigger_item;

  // trim spaces from name, make lower-case
  CheckObjectName (strTriggerName, false);

  if (!GetTriggerMap ().Lookup (strTriggerName, trigger_item))
    return eTriggerNotFound;

CString strOptionName = OptionName;

  strOptionName.MakeLower();
  strOptionName.TrimLeft ();
  strOptionName.TrimRight ();

int iItem;
int iResult = FindBaseOption (strOptionName, TriggerOptionsTable, iItem);

bool bChanged;

  if (iResult == eOK)
    {
    // this is a numeric option
    
    // for boolean options, accept "y" or "n"
    if (TriggerOptionsTable [iItem].iMinimum == 0 &&
      TriggerOptionsTable [iItem].iMaximum == 0)
      {
      if (strValue == "Y" || strValue == "y")
        Value = "1";
      else if (strValue == "N" || strValue == "n")
        Value = "0";
      }

    if (!IsNumber (Value, true))
       return eOptionOutOfRange;

    long iValue = atol (Value);

    if (m_CurrentPlugin &&
        (TriggerOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_WRITE))
    	return ePluginCannotSetOption;  // not available to plugin

    if (TriggerOptionsTable [iItem].iFlags & OPT_CANNOT_WRITE)
    	return ePluginCannotSetOption;  // not available for writing at all    

    iResult = SetBaseOptionItem (iItem,
                        TriggerOptionsTable,
                        NUMITEMS (TriggerOptionsTable),
                        (char *) trigger_item, 
                        iValue,
                        bChanged);

    if (bChanged)
      {
      if (!m_CurrentPlugin) // plugin mods don't really count
        SetModifiedFlag (TRUE);   // document has changed
      trigger_item->nUpdateNumber    = App.GetUniqueNumber ();   // for concurrency checks
      }

    if (strOptionName == "sequence")
      SortTriggers ();

    return iResult;

    }  // end of found
  else
    { // not numeric option, try alpha
    int iResult = FindBaseAlphaOption (strOptionName, TriggerAlphaOptionsTable, iItem);
    if (iResult == eOK)
      {

      // alpha option

      if (m_CurrentPlugin &&
          (TriggerAlphaOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_WRITE))
    	  return ePluginCannotSetOption;  // not available to plugin

      if (TriggerAlphaOptionsTable [iItem].iFlags & OPT_CANNOT_WRITE)
    	  return ePluginCannotSetOption;  // not available for writing at all    

      // ------ preliminary validation before setting the option

      // cannot have null match text
      if (strOptionName == "match" || 
          strOptionName == "ignore_case" ||
          strOptionName == "multi_line")
        {
        if (strValue.IsEmpty ())
          return eTriggerCannotBeEmpty;

        t_regexp * regexp = NULL;

        CString strRegexp; 

        if (trigger_item->bRegexp)
          strRegexp = strValue;
        else
          strRegexp = ConvertToRegularExpression (strValue);

        // compile regular expression
        try 
          {
          regexp = regcomp (strRegexp, (trigger_item->ignore_case ? PCRE_CASELESS : 0) |
                                       (trigger_item->bMultiLine  ? PCRE_MULTILINE : 0) |
                                       (m_bUTF_8 ? PCRE_UTF8 : 0)
                                       );
          }   // end of try
        catch(CException* e)
          {
          e->Delete ();
          return eBadRegularExpression;
          } // end of catch
      
        delete trigger_item->regexp;    // get rid of old one
        trigger_item->regexp = regexp;

        } // end of option "match"  
      else if (strOptionName == "script")
        {
  
        // get trigger dispatch ID

        if (GetScriptEngine () && !strValue.IsEmpty ())
          {
          DISPID dispid = DISPID_UNKNOWN;
          CString strMessage;
          dispid = GetProcedureDispid (strValue, "trigger", TriggerName, strMessage);
          if (dispid == DISPID_UNKNOWN)
            return eScriptNameNotLocated;
          trigger_item->dispid  = dispid;   // update dispatch ID
          }
        } // end of option "script"


      // set the option now

      iResult = SetBaseAlphaOptionItem (iItem,
                        TriggerAlphaOptionsTable,
                        NUMITEMS (TriggerAlphaOptionsTable),
                        (char *) trigger_item,  
                        strValue,
                        bChanged);

      if (bChanged)
        {
        if (!m_CurrentPlugin) // plugin mods don't really count
          SetModifiedFlag (TRUE);   // document has changed
        trigger_item->nUpdateNumber    = App.GetUniqueNumber ();   // for concurrency checks
        }

      return iResult;
      }  // end of found alpha option
    }  // end of not numeric option

 return eUnknownOption;
}   // end of SetTriggerOption
Esempio n. 4
0
VARIANT CMUSHclientDoc::GetTriggerOption(LPCTSTR TriggerName, LPCTSTR OptionName) 
{
CString strTriggerName = TriggerName;
CTrigger * trigger_item;

	VARIANT vaResult;
	VariantInit(&vaResult);

  vaResult.vt = VT_NULL;

  // trim spaces from name, make lower-case
  CheckObjectName (strTriggerName, false);

  vaResult.vt = VT_EMPTY;

  // see if trigger exists, if not return EMPTY
  if (!GetTriggerMap ().Lookup (strTriggerName, trigger_item))
	  return vaResult;

int iItem;
int iResult = FindBaseOption (OptionName, TriggerOptionsTable, iItem);

  
  if (iResult == eOK)
    {

    // numeric option

    if (m_CurrentPlugin &&
        (TriggerOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_READ))
    	return vaResult;  // not available to plugin

    long Value =  GetBaseOptionItem (iItem, 
                              TriggerOptionsTable, 
                              NUMITEMS (TriggerOptionsTable),
                              (char *) trigger_item);  

    SetUpVariantLong (vaResult, Value);
    }  // end of found numeric option
  else
    { // not numeric option, try alpha
    int iResult = FindBaseAlphaOption (OptionName, TriggerAlphaOptionsTable, iItem);
    if (iResult == eOK)
      {

      // alpha option

      if (m_CurrentPlugin &&
          (TriggerAlphaOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_READ))
    	  return vaResult;  // not available to plugin

      CString strValue =  GetBaseAlphaOptionItem (iItem, 
                                                 TriggerAlphaOptionsTable,
                                                 NUMITEMS (TriggerAlphaOptionsTable),
                                                 (char *) trigger_item);

      SetUpVariantString (vaResult, strValue);
      }  // end of found
    }

	return vaResult;
} // end of GetTriggerOption
Esempio n. 5
0
long CMUSHclientDoc::SetTimerOption(LPCTSTR TimerName, LPCTSTR OptionName, LPCTSTR Value)
{
    CString strTimerName = TimerName;
    CString strValue = Value;
    CTimer * Timer_item;

    // trim spaces from name, make lower-case
    CheckObjectName (strTimerName, false);

    if (!GetTimerMap ().Lookup (strTimerName, Timer_item))
        return eTimerNotFound;

    CString strOptionName = OptionName;

    strOptionName.MakeLower();
    strOptionName.TrimLeft ();
    strOptionName.TrimRight ();

    int iItem;
    int iResult = FindBaseOption (strOptionName, TimerOptionsTable, iItem);

    bool bChanged;

    if (iResult == eOK)
    {
        // this is a numeric option

        // for boolean options, accept "y" or "n"
        if (TimerOptionsTable [iItem].iMinimum == 0 &&
                TimerOptionsTable [iItem].iMaximum == 0)
        {
            if (strValue == "Y" || strValue == "y")
                Value = "1";
            else if (strValue == "N" || strValue == "n")
                Value = "0";
        }

        long iValue = 0;
        double fValue = 0;

        if (strOptionName == "second")
            fValue = atof (Value);
        else
        {
            if (!IsNumber (Value, true))
                return eOptionOutOfRange;

            iValue = atol (Value);
        }

        if (m_CurrentPlugin &&
                (TimerOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_WRITE))
            return ePluginCannotSetOption;  // not available to plugin

        if (TimerOptionsTable [iItem].iFlags & OPT_CANNOT_WRITE)
            return ePluginCannotSetOption;  // not available for writing at all

        iResult = SetBaseOptionItem (iItem,
                                     TimerOptionsTable,
                                     NUMITEMS (TimerOptionsTable),
                                     (char *) Timer_item,
                                     iValue,
                                     bChanged);

        if (bChanged)
        {
            if (!m_CurrentPlugin) // plugin mods don't really count
                SetModifiedFlag (TRUE);   // document has changed
            Timer_item->nUpdateNumber    = App.GetUniqueNumber ();   // for concurrency checks
        }

        if (iResult == eOK && Timer_item->iType == CTimer::eInterval)
        {   // need to set "every" time, not "at" time
            if (strOptionName == "hour")
            {
                Timer_item->iEveryHour = iValue;
                ResetOneTimer (Timer_item);
            } // end of option "hour"
            else if (strOptionName == "minute")
            {
                Timer_item->iEveryMinute = iValue;
                ResetOneTimer (Timer_item);
            } // end of option "minute"
            else if (strOptionName == "second")
            {
                Timer_item->fEverySecond = fValue;
                ResetOneTimer (Timer_item);
            } // end of option "second"

        } // end of need to fiddle with hour/minute/second

        // need to reset if we are changing this
        if (strOptionName == "at_time" && bChanged)
        {
            // copy from at to every or vice-versa
            if (Timer_item->iType == CTimer::eInterval)
            {
                Timer_item->iEveryHour    = Timer_item->iAtHour;
                Timer_item->iEveryMinute  = Timer_item->iAtHour;
                Timer_item->fEverySecond  = Timer_item->fAtSecond;
            }
            else
            {
                Timer_item->iAtHour    = Timer_item->iEveryHour;
                Timer_item->iAtMinute  = Timer_item->iEveryHour;
                Timer_item->fAtSecond  = Timer_item->fEverySecond;
            }
            ResetOneTimer (Timer_item);
        }

        return iResult;

    }  // end of found
    else
    {   // not numeric option, try alpha
        int iResult = FindBaseAlphaOption (strOptionName, TimerAlphaOptionsTable, iItem);
        if (iResult == eOK)
        {

            // alpha option

            if (m_CurrentPlugin &&
                    (TimerAlphaOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_WRITE))
                return ePluginCannotSetOption;  // not available to plugin

            if (TimerAlphaOptionsTable [iItem].iFlags & OPT_CANNOT_WRITE)
                return ePluginCannotSetOption;  // not available for writing at all

            // ------ preliminary validation before setting the option

            if (strOptionName == "script")
            {

                // get Timer dispatch ID

                if (GetScriptEngine () && !strValue.IsEmpty ())
                {
                    DISPID dispid = DISPID_UNKNOWN;
                    CString strMessage;
                    dispid = GetProcedureDispid (strValue, "Timer", TimerName, strMessage);
                    if (dispid == DISPID_UNKNOWN)
                        return eScriptNameNotLocated;
                    Timer_item->dispid  = dispid;   // update dispatch ID
                }
            } // end of option "script"


            // set the option now

            iResult = SetBaseAlphaOptionItem (iItem,
                                              TimerAlphaOptionsTable,
                                              NUMITEMS (TimerAlphaOptionsTable),
                                              (char *) Timer_item,
                                              strValue,
                                              bChanged);

            if (bChanged)
            {
                if (!m_CurrentPlugin) // plugin mods don't really count
                    SetModifiedFlag (TRUE);   // document has changed
                Timer_item->nUpdateNumber    = App.GetUniqueNumber ();   // for concurrency checks
            }

            return iResult;
        }  // end of found alpha option
    }  // end of not numeric option

    return eUnknownOption;
} // end of SetTimerOption
Esempio n. 6
0
VARIANT CMUSHclientDoc::GetTimerOption(LPCTSTR TimerName, LPCTSTR OptionName)
{
    CString strTimerName = TimerName;
    CTimer * Timer_item;

    VARIANT vaResult;
    VariantInit(&vaResult);

    vaResult.vt = VT_NULL;

    // trim spaces from name, make lower-case
    CheckObjectName (strTimerName, false);

    vaResult.vt = VT_EMPTY;

    // see if Timer exists, if not return EMPTY
    if (!GetTimerMap ().Lookup (strTimerName, Timer_item))
        return vaResult;


    CString strOptionName = OptionName;

    strOptionName.MakeLower();
    strOptionName.TrimLeft ();
    strOptionName.TrimRight ();

    int iItem;
    int iResult = FindBaseOption (strOptionName, TimerOptionsTable, iItem);


    if (iResult == eOK)
    {

        // numeric option

        if (m_CurrentPlugin &&
                (TimerOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_READ))
            return vaResult;  // not available to plugin

        double Value;

        // this is a pest!
        if (strOptionName == "hour")
        {
            if (Timer_item->iType == CTimer::eInterval)
                Value = Timer_item->iEveryHour;
            else
                Value = Timer_item->iAtHour;
        } // end of option "hour"
        else if (strOptionName == "minute")
        {
            if (Timer_item->iType == CTimer::eInterval)
                Value = Timer_item->iEveryMinute;
            else
                Value = Timer_item->iAtMinute;
        } // end of option "minute"
        else if (strOptionName == "second")
        {
            if (Timer_item->iType == CTimer::eInterval)
                Value = Timer_item->fEverySecond;
            else
                Value = Timer_item->fAtSecond;
        } // end of option "second"
        else
            Value =  GetBaseOptionItem (iItem,
                                        TimerOptionsTable,
                                        NUMITEMS (TimerOptionsTable),
                                        (char *) Timer_item);

        SetUpVariantDouble (vaResult, Value);
    }  // end of found numeric option
    else
    {   // not numeric option, try alpha
        int iResult = FindBaseAlphaOption (OptionName, TimerAlphaOptionsTable, iItem);
        if (iResult == eOK)
        {

            // alpha option

            if (m_CurrentPlugin &&
                    (TimerAlphaOptionsTable [iItem].iFlags & OPT_PLUGIN_CANNOT_READ))
                return vaResult;  // not available to plugin

            CString strValue =  GetBaseAlphaOptionItem (iItem,
                                TimerAlphaOptionsTable,
                                NUMITEMS (TimerAlphaOptionsTable),
                                (char *) Timer_item);

            SetUpVariantString (vaResult, strValue);
        }  // end of found
    }

    return vaResult;
} // end of GetTimerOption