예제 #1
0
        public XmppData.Data GetResultForm()
        {
            XmppData.Data data = new XmppData.Data(XmppData.XDataFormType.result);

            data.AddChild(new XmppData.Field(XmppData.FieldType.Hidden)
            {
                Var = "FORM_TYPE", FieldValue = Features.FEAT_MUC_ROOMINFO
            });
            data.AddChild(new XmppData.Field()
            {
                Var = "muc#roominfo_description", Label = RoomTitle, FieldValue = Title
            });
            data.AddChild(new XmppData.Field()
            {
                Var = "muc#roomconfig_publicroom", FieldValue = Visible ? "1" : "0", Label = RoomPublic
            });
            data.AddChild(new XmppData.Field()
            {
                Var = "muc#roomconfig_passwordprotectedroom", FieldValue = PasswordProtected ? "1" : "0", Label = RoomPasswordProtected
            });
            data.AddChild(new XmppData.Field()
            {
                Var = "muc#roomconfig_persistentroom", FieldValue = Persistent ? "1" : "0", Label = MakeRoomPersistent
            });
            //data.AddChild(new Field() { Var = "muc#roominfo_subject", FieldValue = Subject, Label = "Real user names only" });
            //data.AddChild(new Field() { Var = "muc#roomconfig_enablelogging", FieldValue = Logging ? "1" : "0", Label = "Logging enabled" });
            return(data);
        }
예제 #2
0
        public void OwnerCommand(IQ iq, MucRoomMember member)
        {
            Owner owner = iq.Query as Owner;

            // look for destroy
            if (owner != null)
            {
                Destroy destroy = owner.SelectSingleElement(typeof(Destroy)) as Destroy;
                if (destroy != null)
                {
                    DestroyRoom(destroy);
                    return;
                }

                if (!owner.HasChildElements)
                {
                    // Return config
                    owner.AddChild(RoomSettings.GetDataForm(member.Jid));
                }

                XmppData.Data dataSubmit = (XmppData.Data)owner.SelectSingleElement(typeof(XmppData.Data));

                // form config
                if (dataSubmit != null && dataSubmit.Type == XmppData.XDataFormType.submit)
                {
                    RoomSettings.SubmitForm(dataSubmit);
                    SettingsSave();
                    iq.Query.RemoveAllChildNodes();
                }
            }

            iq.Type = IqType.result;
            iq.SwitchDirection();
        }
예제 #3
0
        public void SubmitForm(XmppData.Data submit)
        {
            ElementList fields = submit.SelectElements(typeof(XmppData.Field));

            foreach (var field in fields)
            {
                if (field is XmppData.Field)
                {
                    XmppData.Field fld = (XmppData.Field)field;
                    //Set conf back
                    switch (fld.Var)
                    {
                    case "muc#roomconfig_usernamesonly":
                        UserNamesOnly = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_roomtitle":
                        Title = fld.GetValue();
                        break;

                    case "muc#roomconfig_enablelogging":
                        Logging = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_changesubject":
                        CanChangeSubject = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_allowinvites":
                        CanInvite = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_publicroom":
                        Visible = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_persistentroom":
                        Persistent = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_membersonly":
                        MembersOnly = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_passwordprotectedroom":
                        PasswordProtected = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_moderated":
                        Moderated = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_roomsecret":
                        Password = fld.GetValue();
                        break;
                    }
                }
            }
        }
예제 #4
0
		public static void FillDataTo(object dataForm, string prefix, Data data)
		{
			if (data.Type == XDataFormType.submit)
			{
				//Gen prop map
				PropertyInfo[] props =
					dataForm.GetType().GetProperties(BindingFlags.Instance | BindingFlags.SetProperty |
													 BindingFlags.Public);
				Dictionary<string, PropertyInfo> propsVar = new Dictionary<string, PropertyInfo>();
				foreach (PropertyInfo prop in props)
				{
					if (prop.CanWrite)
					{
						propsVar.Add(string.Format("{0}#{1}", prefix, prop.Name), prop);
					}
				}

				Field[] fields = data.GetFields();
				foreach (var field in fields)
				{
					if (propsVar.ContainsKey(field.Var))
					{
						PropertyInfo prop = propsVar[field.Var];
						if (prop.PropertyType == typeof(bool))
						{
							string val = field.GetValue();
							if (!string.IsNullOrEmpty(val))
							{
								prop.SetValue(dataForm, val == "1", null);
							}
						}
						else if (prop.PropertyType == typeof(string))
						{
							string val = field.GetValue();
							if (!string.IsNullOrEmpty(val))
							{
								prop.SetValue(dataForm, val, null);
							}
						}
						else if (prop.PropertyType == typeof(string[]))
						{
							string[] val = field.GetValues();
							if (val != null)
							{
								prop.SetValue(dataForm, val, null);
							}
						}

					}
				}
			}
		}
예제 #5
0
        public static void FillDataTo(object dataForm, string prefix, XmppData.Data data)
        {
            if (data.Type == XmppData.XDataFormType.submit)
            {
                //Gen prop map
                PropertyInfo[] props =
                    dataForm.GetType().GetProperties(BindingFlags.Instance | BindingFlags.SetProperty |
                                                     BindingFlags.Public);
                Dictionary <string, PropertyInfo> propsVar = new Dictionary <string, PropertyInfo>();
                foreach (PropertyInfo prop in props)
                {
                    if (prop.CanWrite)
                    {
                        propsVar.Add(string.Format("{0}#{1}", prefix, prop.Name), prop);
                    }
                }

                XmppData.Field[] fields = data.GetFields();
                foreach (var field in fields)
                {
                    if (propsVar.ContainsKey(field.Var))
                    {
                        PropertyInfo prop = propsVar[field.Var];
                        if (prop.PropertyType == typeof(bool))
                        {
                            string val = field.GetValue();
                            if (!string.IsNullOrEmpty(val))
                            {
                                prop.SetValue(dataForm, val == "1", null);
                            }
                        }
                        else if (prop.PropertyType == typeof(string))
                        {
                            string val = field.GetValue();
                            if (!string.IsNullOrEmpty(val))
                            {
                                prop.SetValue(dataForm, val, null);
                            }
                        }
                        else if (prop.PropertyType == typeof(string[]))
                        {
                            string[] val = field.GetValues();
                            if (val != null)
                            {
                                prop.SetValue(dataForm, val, null);
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
        public XmppData.Data GetDataForm(Jid creator)
        {
            XmppData.Data data = new XmppData.Data(XmppData.XDataFormType.form);
            data.Title        = string.Format("Configuration of {0} room", Room.Jid);
            data.Instructions = string.Format("Room {0} was created. Please fill configuration", Room.Name);

            data.AddChild(new XmppData.Field(XmppData.FieldType.Hidden)
            {
                Var = "FORM_TYPE", FieldValue = Features.FEAT_MUC_ROOMCONFIG
            });
            data.AddChild(new XmppData.Field(XmppData.FieldType.Text_Single)
            {
                Var = "muc#roomconfig_roomtitle", Label = RoomTitle, FieldValue = Title
            });
            data.AddChild(new XmppData.Field(XmppData.FieldType.Boolean)
            {
                Var = "muc#roomconfig_publicroom", FieldValue = Visible ? "1" : "0", Label = RoomPublic
            });
            data.AddChild(new XmppData.Field(XmppData.FieldType.Boolean)
            {
                Var = "muc#roomconfig_passwordprotectedroom", FieldValue = PasswordProtected ? "1" : "0", Label = RoomPasswordProtected
            });
            data.AddChild(new XmppData.Field(XmppData.FieldType.Text_Private)
            {
                Var = "muc#roomconfig_roomsecret", Label = RoomPassword, FieldValue = Password
            });
            data.AddChild(new XmppData.Field(XmppData.FieldType.Boolean)
            {
                Var = "muc#roomconfig_changesubject", FieldValue = CanChangeSubject ? "1" : "0", Label = AllowChangeSubject
            });
            data.AddChild(new XmppData.Field(XmppData.FieldType.Boolean)
            {
                Var = "muc#roomconfig_enablelogging", FieldValue = Logging ? "1" : "0", Label = "Enable Public Logging?"
            });
            data.AddChild(new XmppData.Field(XmppData.FieldType.Boolean)
            {
                Var = "muc#roomconfig_persistentroom", FieldValue = Persistent ? "1" : "0", Label = MakeRoomPersistent
            });
            //data.AddChild(new Field(FieldType.Boolean) { Var = "muc#roomconfig_usernamesonly", FieldValue = UserNamesOnly ? "1" : "0", Label = "Allow only real User Names?" });
            return(data);
        }
예제 #7
0
		public static Data GetDataForm(object dataForm, string prefix)
		{
			Data data = new Data(XDataFormType.form);

			//Go through public vars
			PropertyInfo[] props = dataForm.GetType().GetProperties(BindingFlags.Instance | BindingFlags.SetProperty |
											 BindingFlags.Public);
			foreach (PropertyInfo prop in props)
			{
				if (prop.CanRead)
				{
					Field field = new Field(FieldType.Unknown);

					field.Var = string.Format("{0}#{1}", prefix, prop.Name);
					object propValue = prop.GetValue(dataForm, null);

					foreach (var attribute in prop.GetCustomAttributes(false))
					{
						if (attribute is XDataDescriptionAttribute)
						{
							field.Label = (attribute as XDataDescriptionAttribute).Description;
						}
						else if (attribute is XDataOneOfAttribute)
						{
							field.Type = FieldType.List_Single;
							field.FieldValue = (string)propValue;
							foreach (var vars in (attribute as XDataOneOfAttribute).Variants)
							{
								field.AddOption(vars, vars);
							}
						}
						else if (attribute is XDataAnyOfAttribute)
						{
							field.Type = FieldType.List_Multi;
							field.AddValues((string[])propValue);
							foreach (var vars in (attribute as XDataAnyOfAttribute).Variants)
							{
								field.AddOption(vars, vars);
							}
						}
						else if (attribute is XDataMultiline)
						{
							field.Type = FieldType.Text_Multi;
							field.FieldValue = (string)propValue;
						}
						else if (attribute is XDataPassword)
						{
							field.Type = FieldType.Text_Private;
							field.FieldValue = (string)propValue;
						}
						else if (attribute is XDataFixed)
						{
							field.Type = FieldType.Fixed;
							field.FieldValue = (string)propValue;
						}
					}
					if (field.Type == FieldType.Unknown)
					{
						if (prop.PropertyType == typeof(bool))
						{
							field.Type = FieldType.Boolean;
							field.FieldValue = (bool)propValue ? "1" : "0";
						}
						else if (prop.PropertyType == typeof(string))
						{
							field.Type = FieldType.Text_Single;
							field.FieldValue = (string)propValue;
						}
					}
					if (field.Label == null)
					{
						field.Label = prop.Name;
					}
					data.AddField(field);
				}
			}

			return data;
		}
예제 #8
0
        public static XmppData.Data GetDataForm(object dataForm, string prefix)
        {
            XmppData.Data data = new XmppData.Data(XmppData.XDataFormType.form);

            //Go through public vars
            PropertyInfo[] props = dataForm.GetType().GetProperties(BindingFlags.Instance | BindingFlags.SetProperty |
                                                                    BindingFlags.Public);
            foreach (PropertyInfo prop in props)
            {
                if (prop.CanRead)
                {
                    XmppData.Field field = new XmppData.Field(XmppData.FieldType.Unknown);

                    field.Var = string.Format("{0}#{1}", prefix, prop.Name);
                    object propValue = prop.GetValue(dataForm, null);

                    foreach (var attribute in prop.GetCustomAttributes(false))
                    {
                        if (attribute is XDataDescriptionAttribute)
                        {
                            field.Label = (attribute as XDataDescriptionAttribute).Description;
                        }
                        else if (attribute is XDataOneOfAttribute)
                        {
                            field.Type       = XmppData.FieldType.List_Single;
                            field.FieldValue = (string)propValue;
                            foreach (var vars in (attribute as XDataOneOfAttribute).Variants)
                            {
                                field.AddOption(vars, vars);
                            }
                        }
                        else if (attribute is XDataAnyOfAttribute)
                        {
                            field.Type = XmppData.FieldType.List_Multi;
                            field.AddValues((string[])propValue);
                            foreach (var vars in (attribute as XDataAnyOfAttribute).Variants)
                            {
                                field.AddOption(vars, vars);
                            }
                        }
                        else if (attribute is XDataMultiline)
                        {
                            field.Type       = XmppData.FieldType.Text_Multi;
                            field.FieldValue = (string)propValue;
                        }
                        else if (attribute is XDataPassword)
                        {
                            field.Type       = XmppData.FieldType.Text_Private;
                            field.FieldValue = (string)propValue;
                        }
                        else if (attribute is XDataFixed)
                        {
                            field.Type       = XmppData.FieldType.Fixed;
                            field.FieldValue = (string)propValue;
                        }
                    }
                    if (field.Type == XmppData.FieldType.Unknown)
                    {
                        if (prop.PropertyType == typeof(bool))
                        {
                            field.Type       = XmppData.FieldType.Boolean;
                            field.FieldValue = (bool)propValue ? "1" : "0";
                        }
                        else if (prop.PropertyType == typeof(string))
                        {
                            field.Type       = XmppData.FieldType.Text_Single;
                            field.FieldValue = (string)propValue;
                        }
                    }
                    if (field.Label == null)
                    {
                        field.Label = prop.Name;
                    }
                    data.AddField(field);
                }
            }

            return(data);
        }
예제 #9
0
 public void SubmitForm(Data submit)
 {
     ElementList fields = submit.SelectElements(typeof(Field));
     foreach (var field in fields)
     {
         if (field is Field)
         {
             Field fld = (Field)field;
             //Set conf back
             switch (fld.Var)
             {
                 case "muc#roomconfig_usernamesonly":
                     UserNamesOnly = fld.GetValueBool();
                     break;
                 case "muc#roomconfig_roomtitle":
                     Title = fld.GetValue();
                     break;
                 case "muc#roomconfig_enablelogging":
                     Logging = fld.GetValueBool();
                     break;
                 case "muc#roomconfig_changesubject":
                     CanChangeSubject = fld.GetValueBool();
                     break;
                 case "muc#roomconfig_allowinvites":
                     CanInvite = fld.GetValueBool();
                     break;
                 case "muc#roomconfig_publicroom":
                     Visible = fld.GetValueBool();
                     break;
                 case "muc#roomconfig_persistentroom":
                     Persistent = fld.GetValueBool();
                     break;
                 case "muc#roomconfig_membersonly":
                     MembersOnly = fld.GetValueBool();
                     break;
                 case "muc#roomconfig_passwordprotectedroom":
                     PasswordProtected = fld.GetValueBool();
                     break;
                 case "muc#roomconfig_moderated":
                     Moderated = fld.GetValueBool();
                     break;
                 case "muc#roomconfig_roomsecret":
                     Password = fld.GetValue();
                     break;
             }
         }
     }
 }
예제 #10
0
        public Data GetResultForm()
        {
            Data data = new Data(XDataFormType.result);

            data.AddChild(new Field(FieldType.Hidden) { Var = "FORM_TYPE", FieldValue = Features.FEAT_MUC_ROOMINFO });
            data.AddChild(new Field() { Var = "muc#roominfo_description", Label = RoomTitle, FieldValue = Title });
            data.AddChild(new Field() { Var = "muc#roomconfig_publicroom", FieldValue = Visible ? "1" : "0", Label = RoomPublic });
            data.AddChild(new Field() { Var = "muc#roomconfig_passwordprotectedroom", FieldValue = PasswordProtected ? "1" : "0", Label = RoomPasswordProtected });
            data.AddChild(new Field() { Var = "muc#roomconfig_persistentroom", FieldValue = Persistent ? "1" : "0", Label = MakeRoomPersistent });
            //data.AddChild(new Field() { Var = "muc#roominfo_subject", FieldValue = Subject, Label = "Real user names only" });
            //data.AddChild(new Field() { Var = "muc#roomconfig_enablelogging", FieldValue = Logging ? "1" : "0", Label = "Logging enabled" });
            return data;
        }
예제 #11
0
        public Data GetDataForm(Jid creator)
        {
            Data data = new Data(XDataFormType.form);
            data.Title = string.Format("Configuration of {0} room", Room.Jid);
            data.Instructions = string.Format("Room {0} was created. Please fill configuration", Room.Name);

            data.AddChild(new Field(FieldType.Hidden) { Var = "FORM_TYPE", FieldValue = Features.FEAT_MUC_ROOMCONFIG });
            data.AddChild(new Field(FieldType.Text_Single) { Var = "muc#roomconfig_roomtitle", Label = RoomTitle, FieldValue = Title });
            data.AddChild(new Field(FieldType.Boolean) { Var = "muc#roomconfig_publicroom", FieldValue = Visible ? "1" : "0", Label = RoomPublic });
            data.AddChild(new Field(FieldType.Boolean) { Var = "muc#roomconfig_passwordprotectedroom", FieldValue = PasswordProtected ? "1" : "0", Label = RoomPasswordProtected });
            data.AddChild(new Field(FieldType.Text_Private) { Var = "muc#roomconfig_roomsecret", Label = RoomPassword, FieldValue = Password });
            data.AddChild(new Field(FieldType.Boolean) { Var = "muc#roomconfig_changesubject", FieldValue = CanChangeSubject ? "1" : "0", Label = AllowChangeSubject });
            data.AddChild(new Field(FieldType.Boolean) { Var = "muc#roomconfig_enablelogging", FieldValue = Logging ? "1" : "0", Label = "Enable Public Logging?" });
            data.AddChild(new Field(FieldType.Boolean) { Var = "muc#roomconfig_persistentroom", FieldValue = Persistent ? "1" : "0", Label = MakeRoomPersistent });
            //data.AddChild(new Field(FieldType.Boolean) { Var = "muc#roomconfig_usernamesonly", FieldValue = UserNamesOnly ? "1" : "0", Label = "Allow only real User Names?" });
            return data;
        }