public void Accept()
        {
            FeatureNeg fNeg = _si.FeatureNeg;

            bool ok = false;

            if (fNeg != null)
            {
                agsXMPP.protocol.x.data.Data data = fNeg.Data;

                if (data != null)
                {
                    Field[] field = data.GetFields();

                    if (field.Length == 1)
                    {
                        Dictionary<string, string> methods = new Dictionary<string, string>();
                        foreach (Option o in field[0].GetOptions())
                        {
                            string val = o.GetValue();
                            methods.Add(val, val);
                        }

                        if (methods.ContainsKey(Uri.BYTESTREAMS))
                        {
                            // supports bytestream, so choose this option
                            SIIq sIq = new SIIq();
                            sIq.Id = _siIq.Id;
                            sIq.To = _siIq.From;
                            sIq.Type = IqType.result;

                            sIq.SI.Id = _si.Id;
                            sIq.SI.FeatureNeg = new FeatureNeg();

                            agsXMPP.protocol.x.data.Data xdata = new agsXMPP.protocol.x.data.Data();
                            xdata.Type = XDataFormType.submit;
                            Field f = new Field();
                            //f.Type = FieldType.List_Single;
                            f.Var = "stream-method";
                            f.AddValue(Uri.BYTESTREAMS);
                            xdata.AddField(f);
                            sIq.SI.FeatureNeg.Data = xdata;

                            _xmppConnection.OnIq += _xmppConnection_OnIq;
                            _xmppConnection.Send(sIq);

                            ok = true;
                        }
                    }
                }
            }

            if (ok)
            {
                State = FileTransferState.WaitingForResponse;
            }
            else
            {
                State = FileTransferState.Error;
                EventErrorFileTransfer transfer =
                    new EventErrorFileTransfer("Error while negotiating file transfer conditions");
                Events.Instance.OnEvent(this, transfer);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the XData Response Element from the entered Data in the GUI Form
        /// </summary>
        /// <returns></returns>
        public Data CreateResponse()
        {
            Data data = new Data(XDataFormType.submit);
            foreach(XDataFieldControl ctl in panelFields.Controls)
            {
                Type type = ctl.GetType();

                if ( type == typeof(XDataTextBox) )
                {
                    Field f;
                    XDataTextBox txt = ctl as XDataTextBox;
                    if (txt.Multiline == true)
                    {
                        f = new Field(FieldType.Text_Multi);
                    }
                    else
                    {
                        if (txt.IsPrivate)
                            f = new Field(FieldType.Text_Private);
                        else
                            f = new Field(FieldType.Text_Single);

                    }
                    f.AddValues(txt.Values);
                    f.Var = txt.Var;
                    data.AddField(f);

                }
                else if ( type == typeof(XDataHidden) )
                {
                    Field f;
                    XDataHidden hidden = ctl as XDataHidden;

                    f = new Field(FieldType.Hidden);

                    f.AddValue(hidden.Value);
                    f.Var = hidden.Var;

                    data.AddField(f);
                }
                else if ( type == typeof(XDataJidSingle) )
                {
                    XDataJidSingle jids = ctl as XDataJidSingle;
                    Field f = new Field(FieldType.Jid_Single);
                    f.SetValue(jids.Value);
                    f.Var = jids.Var;
                    data.AddField(f);
                }
                else if ( type == typeof(XDataJidMulti) )
                {
                    XDataJidMulti jidm = ctl as XDataJidMulti;
                    Field f = new Field(FieldType.Jid_Multi);
                    f.AddValues(jidm.Values);
                    f.Var = jidm.Var;
                    data.AddField(f);

                }
                else if ( type == typeof(XDataCheckBox) )
                {
                    XDataCheckBox chk = ctl as XDataCheckBox;
                    Field f = new Field(FieldType.Boolean);
                    f.SetValueBool(chk.Value);
                    f.Var = chk.Var;
                    data.AddField(f);
                }
                else if ( type == typeof(XDataListMulti) )
                {
                    XDataListMulti listm = ctl as XDataListMulti;
                    Field f = new Field(FieldType.List_Multi);
                    f.AddValues(listm.Values);
                    f.Var = listm.Var;
                    data.AddField(f);
                }
                else if ( type == typeof(XDataListSingle) )
                {
                    XDataListSingle lists = ctl as XDataListSingle;
                    Field f = new Field(FieldType.List_Single);
                    f.SetValue(lists.Value);
                    f.Var = lists.Var;
                    data.AddField(f);
                }
            }

            return data;
        }
        private void AddField( string tag )
        {
            string value = _register.GetTag( tag ) ;

            if ( value != null )
            {
                XDataControl control ;

                if ( tag == "password" )
                {
                    control = new XDataSecret() ;
                }
                else if ( tag == "key" )
                {
                    control = new XDataHidden() ;
                }
                else
                {
                    control = new XDataTextBox() ;
                }

                Field field = new Field( tag, TextUtil.ToTitleCase( tag ), FieldType.Text_Single ) ;
                field.IsRequired = false ;
                field.AddValue( value ) ;
                field.Description = tag ;

                control.Field = field ;

                _container.Children.Add( control ) ;
            }
        }
Esempio n. 4
0
        private void cmdAccept_Click(object sender, EventArgs e)
        {
            cmdAccept.Enabled = false;
            cmdRefuse.Enabled = false;

            agsXMPP.protocol.extensions.featureneg.FeatureNeg fNeg = si.FeatureNeg;
            if (fNeg != null)
            {
                agsXMPP.protocol.x.data.Data data = fNeg.Data;
                if (data != null)
                {
                    agsXMPP.protocol.x.data.Field[] field = data.GetFields();
                    if (field.Length == 1)
                    {
                        Dictionary<string, string> methods = new Dictionary<string, string>();
                        foreach (agsXMPP.protocol.x.data.Option o in field[0].GetOptions())
                        {
                            string val = o.GetValue();
                            methods.Add(val, val);
                        }
                        if (methods.ContainsKey(agsXMPP.Uri.BYTESTREAMS))
                        {
                            // supports bytestream, so choose this option
                            agsXMPP.protocol.extensions.si.SIIq sIq = new agsXMPP.protocol.extensions.si.SIIq();
                            sIq.Id      = siIq.Id;
                            sIq.To      = siIq.From;
                            sIq.Type    = IqType.result;

                            sIq.SI.Id = si.Id;
                            sIq.SI.FeatureNeg = new agsXMPP.protocol.extensions.featureneg.FeatureNeg();

                            Data xdata = new Data();
                            xdata.Type = XDataFormType.submit;
                            Field f = new Field();
                            //f.Type = FieldType.List_Single;
                            f.Var = "stream-method";
                            f.AddValue(agsXMPP.Uri.BYTESTREAMS);
                            xdata.AddField(f);
                            sIq.SI.FeatureNeg.Data = xdata;

                            m_XmppCon.Send(sIq);
                        }
                    }
                }
            }
        }
        private void SetupSimpleSearch()
        {
            _instructions.Text = _search.Instructions;

            // first name
            if ( _search.Firstname != null )
            {
                _textFirst = new XDataTextBox() ;

                Field fieldUserName = new Field( "firstname", Properties.Resources.Constant_FirstName, FieldType.Text_Single ) ;
                fieldUserName.IsRequired = false ;
                fieldUserName.AddValue( _search.Firstname ) ;
                fieldUserName.Description = Properties.Resources.Constant_EnterFirstNameForSearch ;

                _textFirst.Field = fieldUserName ;

                _container.Children.Add( _textFirst ) ;
            }

            // last name
            if ( _search.Lastname != null )
            {
                _textLast = new XDataTextBox() ;

                Field fieldUserName = new Field( "lastname", Properties.Resources.Constant_LastName, FieldType.Text_Single ) ;
                fieldUserName.IsRequired = false ;
                fieldUserName.AddValue( _search.Lastname ) ;
                fieldUserName.Description = Properties.Resources.Constant_EnterLastNameForSearch ;

                _textLast.Field = fieldUserName ;

                _container.Children.Add( _textLast ) ;
            }

            // nickname
            if ( _search.Nickname != null )
            {
                _textNick = new XDataTextBox() ;

                Field fieldUserName = new Field( "nickname", Properties.Resources.Constant_Nickname, FieldType.Text_Single ) ;
                fieldUserName.IsRequired = false ;
                fieldUserName.AddValue( _search.Nickname ) ;
                fieldUserName.Description = Properties.Resources.Constant_EnterNicknameForSearch ;

                _textNick.Field = fieldUserName ;

                _container.Children.Add( _textNick ) ;
            }

            // email
            if ( _search.Email != null )
            {
                _textEmail = new XDataTextBox() ;

                Field fieldEmail = new Field( "email", Properties.Resources.Constant_Email, FieldType.Text_Single ) ;
                fieldEmail.IsRequired = false ;
                fieldEmail.AddValue( _search.Email ) ;
                fieldEmail.Description = Properties.Resources.Constant_EnterEmailForSearch ;

                _textEmail.Field = fieldEmail ;

                _container.Children.Add( _textEmail ) ;
            }
        }