### Home Classes Methods

### In Files

- lib/xmpp4r/httpbinding/client.rb

### Parent

Jabber::Client

### Methods

- ::new
- #close
- #connect
- #ensure_one_pending_request
- #http_proxy_env
- #http_proxy_uri=

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# Jabber::HTTPBinding::Client

This class implements an alternative Client using HTTP Binding (JEP0124).

This class is designed to be a drop-in replacement for Jabber::Client, except for the Jabber::HTTP::Client#connect method which takes an URI as argument.

HTTP requests are buffered to not exceed the negotiated 'polling' and 'requests' parameters.

Stanzas in HTTP resonses may be delayed to arrive in the order defined by 'rid' parameters.

# Debugging

Turning Jabber::debug to true will make debug output not only spit out stanzas but HTTP request/response bodies, too.

### Attributes

http_content_type[RW]

Content-Type to be used for communication (you can set this to "text/html")

http_hold[RW]

The server may hold this amount of stanzas to reduce number of HTTP requests

http_ssl_setup[RW]

Hook to initialize SSL parameters on Net::HTTP

http_wait[RW]

The server should wait this value seconds if there is no stanza to be received

### Public Class Methods

new(jid) click to toggle source

Initialize

jid

JID or String

    # File lib/xmpp4r/httpbinding/client.rb, line 51
    def initialize(jid)
      super

      @lock = Mutex.new
      @pending_requests = 0
      @last_send = Time.at(0)
      @send_buffer = ''

      @http_requests = 1
      @http_wait = 20
      @http_hold = 1
      @http_content_type = 'text/xml; charset=utf-8'

      @no_proxy = []
      @proxy_args = []
    end

### Public Instance Methods

close() click to toggle source

Close the session by sending <body type='terminate'/>

    # File lib/xmpp4r/httpbinding/client.rb, line 178
    def close
      @status = DISCONNECTED
      req_body = nil
      @lock.synchronize {
        req_body = "<body"
        req_body += " rid='#{@http_rid += 1}'"
        req_body += " sid='#{@http_sid}'"
        req_body += " type='terminate'"
        req_body += " xmlns='http://jabber.org/protocol/httpbind'"
        req_body += ">"
        req_body += "<presence type='unavailable' xmlns='jabber:client'/>"
        req_body += "</body>"
        current_rid = @http_rid
        @pending_requests += 1
        @last_send = Time.now
      }
      res_body = post(req_body, "terminate sid=#{@http_sid} rid=#{@http_rid}")
      sleep(3)
      Jabber::debuglog("Connection closed")
    end

connect(uri, host=nil, port=5222) click to toggle source

Set up the stream using uri as the HTTP Binding URI

You may optionally pass host and port parameters to make use of the JEP0124 'route' feature.

uri

URI::Generic or String

host

String

  Optional host to route to

port

Fixnum

  Port for route feature

    # File lib/xmpp4r/httpbinding/client.rb, line 118
    def connect(uri, host=nil, port=5222)
      uri = URI::parse(uri) unless uri.kind_of? URI::Generic
      @uri = uri

      @allow_tls = false  # Shall be done at HTTP level
      @stream_mechanisms = []
      @stream_features = {}
      @http_rid = IdGenerator.generate_id.to_i
      @pending_rid = @http_rid
      @pending_rid_lock = Mutex.new
      @pending_rid_cv = [] # [ [rid, cv], [rid, cv], ... ]

      req_body = REXML::Element.new('body')
      req_body.attributes['rid'] = @http_rid
      req_body.attributes['content'] = @http_content_type
      req_body.attributes['hold'] = @http_hold.to_s
      req_body.attributes['wait'] = @http_wait.to_s
      req_body.attributes['to'] = @jid.domain
      if host
        req_body.attributes['route'] = "xmpp:#{host}:#{port}"
      end
      req_body.attributes['secure'] = 'true'
      req_body.attributes['xmlns'] = 'http://jabber.org/protocol/httpbind'
      res_body = post(req_body, "sid=new rid=#{@http_rid}")
      unless res_body.name == 'body'
        raise 'Response body is no <body/> element'
      end

      @streamid = res_body.attributes['authid']
      @status = CONNECTED
      @http_sid = res_body.attributes['sid']
      @http_wait = res_body.attributes['wait'].to_i if res_body.attributes['wait']
      @http_hold = res_body.attributes['hold'].to_i if res_body.attributes['hold']
      @http_inactivity = res_body.attributes['inactivity'].to_i
      @http_polling = res_body.attributes['polling'].to_i
      @http_polling = 5 if @http_polling == 0
      @http_requests = res_body.attributes['requests'].to_i
      @http_requests = 1 if @http_requests == 0

      receive_elements_with_rid(@http_rid, res_body.children)

      @features_sem.run
    end

ensure_one_pending_request() click to toggle source

Ensure that there is one pending request

Will be automatically called if you've sent a stanza.

    # File lib/xmpp4r/httpbinding/client.rb, line 167
    def ensure_one_pending_request
      return if is_disconnected?

      if @lock.synchronize { @pending_requests } < 1
        send_data('')
      end
    end

http_proxy_env() click to toggle source

Set up proxy from the environment variables

Following environment variables are considered HTTP_PROXY, http_proxy NO_PROXY, no_proxy HTTP_PROXY_USER, HTTP_PROXY_PASSWORD

    # File lib/xmpp4r/httpbinding/client.rb, line 93
    def http_proxy_env
      @proxy_args = []
      env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
      return if env_proxy.nil? or env_proxy.empty?

      uri = URI.parse env_proxy
      unless uri.user or uri.password then
        uri.user     = CGI.escape (ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER']) rescue nil
        uri.password = CGI.escape (ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS']) rescue nil
      end

      self.http_proxy_uri = uri

      @no_proxy = (ENV['NO_PROXY'] || ENV['no_proxy'] || 'localhost, 127.0.0.1').split(/\s*,\s*/)
    end

http_proxy_uri=(uri) click to toggle source

url

URI::Generic or String

  of the form:

when without proxy authentication

    http://proxy_host:proxy_port/

when with proxy authentication

    http://proxy_user:proxy_password@proxy_host:proxy_port/

    # File lib/xmpp4r/httpbinding/client.rb, line 76
    def http_proxy_uri=(uri)
      uri = URI.parse(uri) unless uri.respond_to?(:host)
      @proxy_args = [
                     uri.host,
                     uri.port,
                     uri.user,
                     uri.password,
                    ]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.