Subject: 24.3; open-network-stream with starttls fails with protocol that has no greeting

From: Dan Starr <[email-masked]>
Date: Tue, 23 Jul 2013 09:14:15 -0400

I have been trying to use open-network-stream in emacs 24.3 to interact
with a server that runs the Infinote protocol on top of STARTTLS (
http://gobby.0x539.de/trac/wiki/Infinote/Protocol).

This is my usage of open-network-stream:

<code>

  (setq myprocess (open-network-stream
                   "testname" ; name
                   "blah" ; buffer
                   "127.0.0.1" ; host
                   6523   ; port
                   :type 'starttls
                   :starttls-function 'my-starttls-function
                   ;; sent to server when connection initially established
                   :capability-command "<stream:stream version=\"1.0\"
xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\"
to=\"127.0.0.1\">"
                   :end-of-capability "</stream:features>"
                   :end-of-command "/>"
                   :success "proceed"
                   :client-certificate '(/home/dstarr/key/dstarr.key
/home/dstarr/key/dstarr.cert)
                   ))

(defun my-starttls-function (capabilityCommandResponse)
  "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>")

</code>

The problem that I have run into is that the Infinote protocol does not
emit a "greeting" upon initial connection, whereas it seems that the
implementation of the function network-stream-open-starttls
in lisp/net/network-stream.el expects such a greeting.

Line 214 of network-stream.el reads: (greeting (network-stream-get-response
stream start eoc)).

For my particular protocol, I have eoc set to "/>", as I have to be able to
detect the server's response to my starttls command (Line 266). Since my
server does not emit a greeting, emacs hangs on Line 214 waiting for an
"eoc" that never comes.  If I set eoc to nil, emacs will proceed past that
line, but it will fail to detect the starttls response (obviously, as it
has no way to detect the end of a command).

To temporarily fix my issue, I removed the 'greeting' line from
network-stream.el.  A more robust solution would be to perhaps allow a
parameter to open-network-stream that indicates whether a greeting is
expected or not.

R,
Dan