public FileTransfer(XmppClientConnection XmppCon, IQ iq) { Console.WriteLine("Accepting a file from " + iq.From.ToString()); siIq = iq; si = iq.SelectSingleElement(typeof(agsXMPP.protocol.extensions.si.SI)) as agsXMPP.protocol.extensions.si.SI; // get SID for file transfer m_Sid = si.Id; m_From = iq.From; file = si.File; m_lFileLength = file.Size; m_XmppCon = XmppCon; XmppCon.OnIq += new IqHandler(XmppCon_OnIq); 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 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 SendSiIq() { SIIq iq = new SIIq(); iq.To = Contact.FullJid; iq.Type = IqType.set; File afile; afile = new File(Path.GetFileName(FileName), _fileLength); afile.Description = FileDescription; afile.Range = new Range(); FeatureNeg fNeg = new FeatureNeg(); agsXMPP.protocol.x.data.Data data = new agsXMPP.protocol.x.data.Data(XDataFormType.form); Field f = new Field(FieldType.List_Single); f.Var = "stream-method"; f.AddOption().SetValue(Uri.BYTESTREAMS); data.AddField(f); fNeg.Data = data; iq.SI.File = afile; iq.SI.FeatureNeg = fNeg; iq.SI.Profile = Uri.SI_FILE_TRANSFER; _sid = Guid.NewGuid().ToString(); iq.SI.Id = _sid; _xmppConnection.IqGrabber.SendIq(iq, new IqCB(SiIqResult), null); State = FileTransferState.WaitingForResponse; }
private bool SelectedByteStream(FeatureNeg fn) { if (fn != null) { agsXMPP.protocol.x.data.Data data = fn.Data; if (data != null) { foreach (Field field in data.GetFields()) { if (field != null && field.Var == "stream-method") { if (field.GetValue() == Uri.BYTESTREAMS) { return true; } } } } } return false; }
private void SendSiIq() { /* Recv: <iq xmlns="jabber:client" from="[email protected]/Psi" to="[email protected]/SharpIM" type="set" id="aab4a"> <si xmlns="http://jabber.org/protocol/si" profile="http://jabber.org/protocol/si/profile/file-transfer" id="s5b_405645b6f2b7c681"> <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" size="719" name="Kunden.dat"> <range /> </file> <feature xmlns="http://jabber.org/protocol/feature-neg"> <x xmlns="jabber:x:data" type="form"> <field type="list-single" var="stream-method"> <option> <value>http://jabber.org/protocol/bytestreams</value> </option> </field> </x> </feature> </si> </iq> Send: <iq xmlns="jabber:client" id="agsXMPP_5" to="[email protected]/Psi" type="set"> <si xmlns="http://jabber.org/protocol/si" id="af5a2e8d-58d4-4038-8732-7fb348ff767f"> <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="ALEX1.JPG" size="22177"><range /></file> <feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form"> <field type="list-single" var="stream-method"><option>http://jabber.org/protocol/bytestreams</option></field></x></feature></si></iq> Send: <iq xmlns="jabber:client" id="aab4a" to="[email protected]/Psi" type="result"><si xmlns="http://jabber.org/protocol/si" id="s5b_405645b6f2b7c681"><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="submit"><field var="stream- method"><value>http://jabber.org/protocol/bytestreams</value></field></x></feature></si></iq> Recv: <iq xmlns="jabber:client" from="[email protected]/Psi" to="[email protected]/SharpIM" type="set" id="aab6a"> <query xmlns="http://jabber.org/protocol/bytestreams" sid="s5b_405645b6f2b7c681" mode="tcp"> <streamhost port="8010" jid="[email protected]/Psi" host="192.168.74.142" /> <streamhost port="7777" jid="proxy.ag-software.de" host="82.165.34.23"> <proxy xmlns="http://affinix.com/jabber/stream" /> </streamhost> <fast xmlns="http://affinix.com/jabber/stream" /> </query> </iq> Send: <iq xmlns="jabber:client" type="result" to="[email protected]/Psi" id="aab6a"><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost-used jid="[email protected]/Psi" /></query></iq> */ SIIq iq = new SIIq(); iq.To = m_To; iq.Type = IqType.set; m_lFileLength = new FileInfo(m_FileName).Length; agsXMPP.protocol.extensions.filetransfer.File file; file =new agsXMPP.protocol.extensions.filetransfer.File( Path.GetFileName(m_FileName), m_lFileLength); if (m_DescriptionChanged) file.Description = txtDescription.Text; file.Range = new Range(); FeatureNeg fNeg = new FeatureNeg(); Data data = new Data(XDataFormType.form); Field f = new Field(FieldType.List_Single); f.Var = "stream-method"; f.AddOption().SetValue(agsXMPP.Uri.BYTESTREAMS); data.AddField(f); fNeg.Data = data; iq.SI.File = file; iq.SI.FeatureNeg = fNeg; iq.SI.Profile = agsXMPP.Uri.SI_FILE_TRANSFER; m_Sid = Guid.NewGuid().ToString(); iq.SI.Id = m_Sid; m_XmppCon.IqGrabber.SendIq(iq, new IqCB(SiIqResult), null); }
private bool IsForm(FeatureNeg fn) { bool bRetVal = false; if ((fn != null) && (fn.Data != null)) { if (fn.Data.Type == XDataFormType.form) bRetVal = true; } return bRetVal; }