xmpp/xmpp.go
changeset 146 aa9a0ae8f875
parent 144 9d7fdb1d2fc1
child 147 d7679d991b17
equal deleted inserted replaced
145:21a390dd3506 146:aa9a0ae8f875
    33 	NsRoster  = "jabber:iq:roster"
    33 	NsRoster  = "jabber:iq:roster"
    34 
    34 
    35 	// DNS SRV names
    35 	// DNS SRV names
    36 	serverSrv = "xmpp-server"
    36 	serverSrv = "xmpp-server"
    37 	clientSrv = "xmpp-client"
    37 	clientSrv = "xmpp-client"
       
    38 )
       
    39 
       
    40 // Flow control for preventing sending stanzas until negotiation has
       
    41 // completed.
       
    42 type sendCmd bool
       
    43 
       
    44 var (
       
    45 	sendAllow sendCmd = true
       
    46 	sendDeny  sendCmd = false
    38 )
    47 )
    39 
    48 
    40 // A filter can modify the XMPP traffic to or from the remote
    49 // A filter can modify the XMPP traffic to or from the remote
    41 // server. It's part of an Extension. The filter function will be
    50 // server. It's part of an Extension. The filter function will be
    42 // called in a new goroutine, so it doesn't need to return. The filter
    51 // called in a new goroutine, so it doesn't need to return. The filter
    66 	socket       net.Conn
    75 	socket       net.Conn
    67 	socketSync   sync.WaitGroup
    76 	socketSync   sync.WaitGroup
    68 	saslExpected string
    77 	saslExpected string
    69 	authDone     bool
    78 	authDone     bool
    70 	handlers     chan *callback
    79 	handlers     chan *callback
    71 	inputControl chan int
    80 	inputControl chan sendCmd
    72 	// Incoming XMPP stanzas from the remote will be published on
    81 	// Incoming XMPP stanzas from the remote will be published on
    73 	// this channel. Information which is used by this library to
    82 	// this channel. Information which is used by this library to
    74 	// set up the XMPP stream will not appear here.
    83 	// set up the XMPP stream will not appear here.
    75 	Recv <-chan Stanza
    84 	Recv <-chan Stanza
    76 	// Outgoing XMPP stanzas to the server should be sent to this
    85 	// Outgoing XMPP stanzas to the server should be sent to this
   136 	cl.Roster = *roster
   145 	cl.Roster = *roster
   137 	cl.password = password
   146 	cl.password = password
   138 	cl.Jid = *jid
   147 	cl.Jid = *jid
   139 	cl.socket = tcp
   148 	cl.socket = tcp
   140 	cl.handlers = make(chan *callback, 100)
   149 	cl.handlers = make(chan *callback, 100)
   141 	cl.inputControl = make(chan int)
   150 	cl.inputControl = make(chan sendCmd)
   142 	cl.tlsConfig = tlsconf
   151 	cl.tlsConfig = tlsconf
   143 	cl.sendFilterAdd = make(chan Filter)
   152 	cl.sendFilterAdd = make(chan Filter)
   144 	cl.recvFilterAdd = make(chan Filter)
   153 	cl.recvFilterAdd = make(chan Filter)
   145 
   154 
   146 	extStanza := make(map[xml.Name]reflect.Type)
   155 	extStanza := make(map[xml.Name]reflect.Type)
   227 
   236 
   228 // bindDone is called when we've finished resource binding (and all
   237 // bindDone is called when we've finished resource binding (and all
   229 // the negotiations that precede it). Now we can start accepting
   238 // the negotiations that precede it). Now we can start accepting
   230 // traffic from the app.
   239 // traffic from the app.
   231 func (cl *Client) bindDone() {
   240 func (cl *Client) bindDone() {
   232 	cl.inputControl <- 1
   241 	cl.inputControl <- sendAllow
   233 }
   242 }
   234 
   243 
   235 // Start an XMPP session. A typical XMPP client should call this
   244 // Start an XMPP session. A typical XMPP client should call this
   236 // immediately after creating the Client in order to start the session
   245 // immediately after creating the Client in order to start the session
   237 // and broadcast an initial presence. The presence can be as simple as
   246 // and broadcast an initial presence. The presence can be as simple as