public SOCKS5ByteStreamLogic(XMPPClient client, FileTransfer trans)
     : base(client, trans)
 {
 }
        public override bool NewIQ(IQ iq)
        {
            if (iq is StreamInitIQ)
            {
                StreamInitIQ siiq = iq as StreamInitIQ;
                if (iq.Type == IQType.result.ToString())
                {
                    /// May be a response to our pending request to send
                    ///
                    StreamInitIQ initalrequest = null;
                    if (FileSendRequests.ContainsKey(iq.ID) == true)
                    {
                        initalrequest = FileSendRequests[iq.ID];
                        FileSendRequests.Remove(iq.ID);
                    }

                    if (initalrequest != null)
                    {
                        //if (siiq.StreamOptions != StreamOptions.ibb)
                        //{
                        //    /// Tell the host we failed to send the file because we only support ibb
                        //    return true;
                        //}

                        /// Looks like they agree, start an ibb file transfer logic to perform the transfer
                        ///

                        if ((siiq.StreamOptions & StreamOptions.bytestreams) == StreamOptions.bytestreams)
                            initalrequest.FileTransferObject.FileTransferType = FileTransferType.ByteStreams;
                        else if ((siiq.StreamOptions & StreamOptions.ibb) == StreamOptions.ibb)
                            initalrequest.FileTransferObject.FileTransferType = FileTransferType.IBB;

                        XMPPClient.FileTransferManager.StartNewReceiveStream(initalrequest.FileTransferObject);
                    }

                }
                else if (iq.Type == IQType.error.ToString())
                {
                    /// May be a response to our pending request to send
                    ///
                    StreamInitIQ initalrequest = null;
                    if (FileSendRequests.ContainsKey(iq.ID) == true)
                    {
                        initalrequest = FileSendRequests[iq.ID];
                        FileSendRequests.Remove(iq.ID);
                    }

                    if (initalrequest != null)
                    {

                        XMPPClient.FileTransferManager.GotStreamErrorResponse(initalrequest.FileTransferObject, iq);
                    }

                }
                //else if (siiq.StreamInitIQType == StreamInitIQType.Offer)
                else if (iq.Type == IQType.set.ToString())
                {
                    /// They want to send a file to us?
                    /// Ask the user if it's OK, and if it is, start an ibb to receive it and send ok
                    ///

                    if ((siiq.sid == null) || (siiq.sid.Length <= 0) )
                    {
                        IQ iqresponse = new StreamInitIQ(StreamInitIQType.Result);
                        iqresponse.ID = siiq.ID;
                        iqresponse.Type = IQType.error.ToString();
                        iqresponse.To = iq.From;
                        iqresponse.From = XMPPClient.JID;
                        iqresponse.Error = new Error(ErrorType.invalidid);
                        XMPPClient.SendXMPP(iqresponse);
                        return true;
                    }
                    if ((siiq.filename == null) || (siiq.filename.Length <= 0))
                    {
                        IQ iqresponse = new StreamInitIQ(StreamInitIQType.Result);
                        iqresponse.ID = siiq.ID;
                        iqresponse.Type = IQType.error.ToString();
                        iqresponse.To = iq.From;
                        iqresponse.From = XMPPClient.JID;
                        iqresponse.Error = new Error(ErrorType.notacceptable);
                        XMPPClient.SendXMPP(iqresponse);
                        return true;
                    }

                    /// Can only do bytes streams or inband byte streams
                    if ( ((siiq.StreamOptions & StreamOptions.ibb) != StreamOptions.ibb) &&
                         ((siiq.StreamOptions & StreamOptions.bytestreams) != StreamOptions.bytestreams))
                    {
                        IQ iqresponse = new StreamInitIQ(StreamInitIQType.Result);
                        iqresponse.ID = siiq.ID;
                        iqresponse.Type = IQType.error.ToString();
                        iqresponse.To = iq.From;
                        iqresponse.From = XMPPClient.JID;
                        iqresponse.Error = new Error(ErrorType.notacceptable);
                        XMPPClient.SendXMPP(iqresponse);
                        return true;
                    }

                    FileTransfer newreq = new FileTransfer(siiq.filename, siiq.filesize, siiq.From);
                    if ((siiq.StreamOptions & StreamOptions.bytestreams) == StreamOptions.bytestreams)
                        newreq.FileTransferType = FileTransferType.ByteStreams;
                    else if ((siiq.StreamOptions & StreamOptions.ibb) == StreamOptions.ibb)
                        newreq.FileTransferType = FileTransferType.IBB;

                    newreq.sid = siiq.sid;

                    FileDownloadRequests.Add(siiq.sid, siiq);

                    XMPPClient.FileTransferManager.NewIncomingFileRequest(newreq);
                }

                return true;
            }
            return false;
        }
 public ByteStreamStreamLogic(XMPPClient client, FileTransfer trans)
     : base(client)
 {
     FileTransfer = trans;
 }
 public InbandByteStreamLogic(XMPPClient client, FileTransfer trans)
     : base(client, trans)
 {
 }
 /// <summary>
 /// Remove this send request from our list.  
 /// TODO.. send a graceful cancel instead of just ignoring the acceptance
 /// </summary>
 /// <param name="trans"></param>
 internal void RevokeSendRequest(FileTransfer trans)
 {
     string strIdRemove = null;
     foreach (string strId in FileSendRequests.Keys)
     {
         StreamInitIQ iq = FileSendRequests[strId];
         if (iq.sid == trans.sid)
         {
             strIdRemove = strId;
             break;
         }
     }
     if (strIdRemove != null)
         FileSendRequests.Remove(strIdRemove);
 }
        public static StreamInitIQ BuildDefaultStreamInitOffer(XMPPClient client, FileTransfer trans)
        {
            StreamInitIQ q = new StreamInitIQ(StreamInitIQType.Offer);
            q.mimetype = trans.MimeType;
            q.filename = trans.FileName;
            q.sid = trans.sid;
            q.filesize = trans.BytesTotal;
            q.FileTransferObject = trans;

            q.StreamOptions = XMPP.StreamOptions.ibb;

            /// Don't offer byte streams if the server doesn't support a SOCKS 5 proxy, since windows phone can't listen for connections
            item filetransfer = client.ServerServiceDiscoveryFeatureList.GetItemByType(ItemType.SOCKS5ByteStream);

            if ((FileTransferManager.SOCKS5Proxy != null) && (FileTransferManager.SOCKS5Proxy.Length > 0))
                filetransfer = new item(); /// User has supplied a socks5 proxy, so we don't need our xmpp server to supply one to use bytestreams

            if ((filetransfer != null) && (FileTransferManager.UseIBBOnly == false))
            {
                q.StreamOptions |= StreamOptions.bytestreams;
            }

            return q;
        }
        /// <summary>
        /// Tell the remote end we decline their stream request
        /// </summary>
        /// <param name="trans"></param>
        internal void DeclineIncomingFileRequest(FileTransfer trans)
        {
            if (FileDownloadRequests.ContainsKey(trans.sid) == true)
            {
                StreamInitIQ siiq = FileDownloadRequests[trans.sid];
                FileDownloadRequests.Remove(trans.sid);

                StreamInitIQ iqdecline = StreamInitIQ.BuildDefaultStreamInitResult(StreamOptions.ibb);
                iqdecline.ID = siiq.ID;
                iqdecline.Type = IQType.error.ToString();
                iqdecline.To = siiq.From;
                iqdecline.From = XMPPClient.JID;
                iqdecline.Error = new Error(ErrorType.notacceptable);
                XMPPClient.SendXMPP(iqdecline);
            }
        }
 /// <summary>
 /// Send out a stream initiation request
 /// </summary>
 /// <param name="trans"></param>
 internal void RequestStartFileTransfer(FileTransfer trans)
 {
     if (trans.FileTransferDirection != FileTransferDirection.Send)
         return;
     StreamInitIQ iq = StreamInitIQ.BuildDefaultStreamInitOffer(this.XMPPClient, trans);
     iq.From = XMPPClient.JID;
     iq.To = trans.RemoteJID;
     iq.Type = IQType.set.ToString();
     iq.mimetype = trans.MimeType;
     FileSendRequests.Add(iq.ID, iq);
     XMPPClient.SendXMPP(iq);
 }
        /// <summary>
        /// Tell the remote end we accept their stream request
        /// </summary>
        /// <param name="trans"></param>
        internal void AcceptIncomingFileRequest(FileTransfer trans)
        {
            if (FileDownloadRequests.ContainsKey(trans.sid) == true)
            {
                StreamInitIQ siiq = FileDownloadRequests[trans.sid];
                FileDownloadRequests.Remove(trans.sid);

                StreamOptions options = StreamOptions.bytestreams;
                if ( (siiq.StreamOptions&StreamOptions.bytestreams) == StreamOptions.bytestreams)
                    options = StreamOptions.bytestreams;
                else if ((siiq.StreamOptions & StreamOptions.ibb) == StreamOptions.ibb)
                    options = StreamOptions.ibb;

                StreamInitIQ iqaccept = StreamInitIQ.BuildDefaultStreamInitResult(options);
                iqaccept.ID = siiq.ID;
                iqaccept.From = XMPPClient.JID;
                iqaccept.To = siiq.From;
                iqaccept.Type = IQType.result.ToString();
                XMPPClient.SendXMPP(iqaccept);
            }
        }
Ejemplo n.º 10
0
 void SafeOnNewIncomingFileTransferRequest(FileTransfer trans, RosterItem itemfrom)
 {
     this.ListBoxFileTransfers.ItemsSource = null;
     this.ListBoxFileTransfers.ItemsSource = App.XMPPClient.FileTransferManager.FileTransfers;
 }
Ejemplo n.º 11
0
 void FileTransferManager_OnNewIncomingFileTransferRequest(FileTransfer trans, RosterItem itemfrom)
 {
     Dispatcher.BeginInvoke(new FileTransferManager.DelegateIncomingFile(SafeOnNewIncomingFileTransferRequest), trans, itemfrom);
 }
Ejemplo n.º 12
0
 void SafeOnNewIncomingFileTransferRequest(FileTransfer trans, RosterItem itemfrom)
 {
     this.RootFrame.Navigate(new Uri("/FileTransferPage.xaml", UriKind.Relative));
 }
Ejemplo n.º 13
0
 void FileTransferManager_OnTransferFinished(FileTransfer trans)
 {
 }