Esempio n. 1
0
    private void HandleConfigMessage(XplMsg x)
    {
      string strMessage = "";
      if (x.XPL_Msg[0].Section.ToLowerInvariant() == "xpl-cmnd")
      {
        this.LogInfo("Processing config message: " + x.XPL_Msg[1].Section.ToLowerInvariant());
        if (this.DoDebug)
        {
          Log.Info("xPL.XplListener.HandleConfigMessage(): received config message: " + x.XPL_Msg[1].Section.ToLowerInvariant(),
                   new object[0]);
        }
        string str4 = x.XPL_Msg[1].Section.ToLowerInvariant();
        if (str4 != null)
        {
          XplConfigItem item;
          if (!(str4 == "config.current"))
          {
            if (!(str4 == "config.list"))
            {
              if ((str4 == "config.response") &&
                  (x.GetParam(0, "target").ToLowerInvariant() == (this.Source.ToLowerInvariant() + "." + this.InstanceName.ToLowerInvariant())))
              {
                if (this.DoDebug)
                {
                  Log.Info("xPL.XplListener.HandleConfigMessage(): parsing config.response message");
                }
                ArrayList list = new ArrayList();
                for (int i = 0; i < x.XPL_Msg[1].Details.Count; i++)
                {
                  try
                  {
                    string key = x.XPL_Msg[1].Details[i].keyName.ToLowerInvariant();
                    string s = x.XPL_Msg[1].Details[i].Value;
                    this.LogInfo("Processing configuration item: " + key);
                    item = this.ConfigItems.ConfigItem(key);
                    if (!list.Contains(key))
                    {
                      item.ResetValues();
                      list.Add(key);
                    }
                    if (key == "interval")
                    {
                      int num5;
                      try
                      {
                        num5 = int.Parse(s);
                      }
                      catch
                      {
                        num5 = 5;
                      }
                      if (num5 < 5)
                      {
                        num5 = 5;
                      }
                      else if (num5 > 9)
                      {
                        num5 = 9;
                      }
                      item.AddValue(num5.ToString());
                      if (this.XplConfigItemDone != null)
                      {
                        this.XplConfigItemDone(key, num5.ToString());
                      }
                    }
                    else
                    {
                      item.AddValue(s);
                      if (this.XplConfigItemDone != null)
                      {
                        this.XplConfigItemDone(key, s);
                      }
                    }
                  }
                  catch (Exception exception)
                  {
                    this.LogError(exception.Message);
                  }
                }
                try
                {
                  if (this.bConfigOnly)
                  {
                    this.bConfigOnly = false;
                    if (this.XplConfigDone != null)
                    {
                      this.XplConfigDone();
                    }
                  }
                  else if (this.XplReConfigDone != null)
                  {
                    this.XplReConfigDone();
                  }
                }
                catch {}
                this.SaveState();
                this.SendHeartbeatMessage(false);
              }
            }
            else
            {
              for (int j = 0; j < this.ConfigItems.Count; j++)
              {
                item = this.ConfigItems.ConfigItem(j);
                switch (item.ConfigType)
                {
                  case xplConfigTypes.xConfig:
                    strMessage = strMessage + "config=";
                    break;

                  case xplConfigTypes.xReconf:
                    strMessage = strMessage + "reconf=";
                    break;

                  case xplConfigTypes.xOption:
                    strMessage = strMessage + "option=";
                    break;
                }
                strMessage = strMessage + item.Name;
                if (item.MaxValues > 1)
                {
                  strMessage = strMessage + "[" + item.MaxValues.ToString() + "]";
                }
                strMessage = strMessage + '\n';
              }
              if (this.DoDebug)
              {
                Log.Info("xPL.XplListener.HandleConfigMessage(): responding to config.list request");
              }
              this.SendMessage("xpl-stat", "*", "config.list", strMessage);
            }
          }
          else
          {
            string str5;
            if (((str5 = x.GetParam(1, "command").ToLowerInvariant()) != null) && (str5 == "request"))
            {
              if (this.DoDebug)
              {
                Log.Info(
                  "xPL.XplListener.HandleConfigMessage(): parsing config for config.current command=request ({0} config items)",
                  new object[] {this.ConfigItems.Count});
              }
              for (int k = 0; k < this.ConfigItems.Count; k++)
              {
                if (this.DoDebug)
                {
                  Log.Info("xPL.XplListener.HandleConfigMessage(): parsing config items {0} ({1})",
                           new object[] {k, this.ConfigItems.ConfigItem(k).Name});
                }
                item = this.ConfigItems.ConfigItem(k);
                for (int m = 0; m < item.ValueCount; m++)
                {
                  object obj2 = strMessage;
                  strMessage = string.Concat(new object[] {obj2, item.Name, "=", item.Values[m], '\n'});
                }
              }
              if (this.DoDebug)
              {
                Log.Info("xPL.XplListener.HandleConfigMessage(): responding to config.current command=request",
                         new object[0]);
              }
              this.SendMessage("xpl-stat", "*", "config.current", strMessage);
            }
          }
        }
      }
    }
Esempio n. 2
0
 private void ReceiveData(IAsyncResult ar)
 {
   if (!this.disposing)
   {
     EndPoint epIncoming = this.epIncoming;
     int count = this.sockIncoming.EndReceiveFrom(ar, ref epIncoming);
     this.epIncoming = (IPEndPoint)epIncoming;
     if (this.DoDebug)
     {
       Log.Info("xPL.XplListener.ReceiveData(): received {0} bytes", new object[] {count});
     }
     bool flag = false;
     for (int i = 0; !flag & (i < this.ListenToIPs.Length); i++)
     {
       if (this.ListenToIPs[i].ToUpperInvariant() == "ANY")
       {
         flag = true;
       }
       else if (this.ListenToIPs[i].ToUpperInvariant() == "ANY_LOCAL")
       {
         flag = this.LocalIP.Contains(this.epIncoming.Address.ToString());
       }
       else if (this.ListenToIPs[i] == this.epIncoming.Address.ToString())
       {
         flag = true;
       }
     }
     if (!flag)
     {
       if (this.DoDebug)
       {
         Log.Info("xPL.XplListener.ReceiveData(): Illegal source - " + this.epIncoming.Address.ToString(),
                  new object[0]);
       }
       this.LogInfo("Illegal source: " + this.epIncoming.Address.ToString());
     }
     else
     {
       if (this.DoDebug)
       {
         Log.Info("xPL.XplListener.ReceiveData(): reading data");
       }
       XplMsg x = new XplMsg(Encoding.ASCII.GetString(this.XPL_Buff, 0, count));
       if (this.DoDebug)
       {
         Log.Info("xPL.XplListener.ReceiveData(): read data\n\n{0}\n",
                  new object[] {Encoding.ASCII.GetString(this.XPL_Buff, 0, count)});
       }
       try
       {
         if (x.IsMessageValid)
         {
           if (this.DoDebug)
           {
             Log.Info("xPL.XplListener.ReceiveData(): received data is a valid xPL message");
           }
           string t = x.GetParam(0, "target").ToLowerInvariant();
           bool flag2 = x.GetParam(0, "target").ToLowerInvariant() == (this.Source + "." + this.InstanceName).ToLowerInvariant();
           bool flag3 = x.GetParam(0, "target") == "*";
           bool flag4 = this.Filters.Count == 0;
           string c = x.Schema.msgClass.ToLowerInvariant();
           string str3 = x.Schema.msgType.ToLowerInvariant();
           if (this.DoDebug)
           {
             Log.Info(
               "xPL.XplListener.ReceiveData(): received Source = {0}, Instance = {1} - Schema - Class = {2}, Type = {3}",
               new object[] {this.Source, this.InstanceName, c, str3});
           }
           if ((!this.mHubFound && (c.Equals("hbeat") || c.Equals("config"))) &&
               (str3.Equals("app") & x.GetParam(0, "source").Equals(this.Source + "." + this.InstanceName)))
           {
             if (this.DoDebug)
             {
               Log.Info("xPL.XplListener.ReceiveData(): received message from Source = {0}",
                        new object[] {x.GetParam(0, "source")});
             }
             if (this.DoDebug)
             {
               Log.Info("xPL.XplListener.ReceiveData(): Found xPL hub");
             }
             this.mHubFound = true;
             this.XPLTimer.Interval = 60000.0;
             this.XplJoinedxPLNetwork();
           }
           if (flag2 & c.Equals("config"))
           {
             this.HandleConfigMessage(x);
           }
           if ((flag2 | flag3) & (c.Equals("hbeat") & str3.Equals("request")))
           {
             this.WaitForRandomPeriod();
             this.SendHeartbeatMessage(false);
           }
           if (!this.bConfigOnly | this.Filters.AlwaysPassMessages)
           {
             if ((flag3 | flag2) | (!this.Filters.MatchTarget | this.CheckGroups(t)))
             {
               string m = x.XPL_Msg[0].Section.ToLowerInvariant();
               for (int j = 0; j < this.Filters.Count; j++)
               {
                 XplFilter filter = this.Filters.Item(j);
                 if ((this.MsgTypeMatchesFilter(m, filter.MessageType) &&
                      this.MsgSourceMatchesFilter(x.Source, filter.Source)) &&
                     this.MsgSchemaMatchesFilter(c, str3, filter.Schema))
                 {
                   flag4 = true;
                   break;
                 }
               }
             }
             if (flag4 && (this.XplMessageReceived != null))
             {
               this.XplMessageReceived(this, new XplEventArgs(x));
             }
           }
         }
       }
       catch (Exception exception)
       {
         this.LogError(exception.ToString());
       }
     }
     this.sockIncoming.BeginReceiveFrom(this.XPL_Buff, 0, 0x5dc, SocketFlags.None, ref epIncoming,
                                        new AsyncCallback(this.ReceiveData), null);
   }
 }
Esempio n. 3
0
 public XplEventArgs(XplMsg x)
 {
   this.XplMsg = x;
 }