JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
starting to switch to node-xml
authorJason Woofenden <jason@jasonwoof.com>
Thu, 6 Oct 2011 20:52:38 +0000 (16:52 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 6 Oct 2011 20:52:38 +0000 (16:52 -0400)
auth.coffee

index 833b553..1b776ab 100644 (file)
@@ -1,7 +1,7 @@
 fs = require 'fs'
 http = require 'http'
 crypto = require 'crypto'
-expat = require 'node-expat'
+xml = require 'node-xml'
 
 auth = {}
 
@@ -51,21 +51,21 @@ login = (callback) ->
                        res.on 'data', (chunk) ->
                                body += chunk
                        res.on 'end', ->
-                               parser = new expat.Parser 'UTF-8'
                                cur_tag = ''
                                done = false
-                               parser.on 'startElement', (name, attrs) ->
-                                       cur_tag = name
-                               parser.on 'text', (str) ->
-                                       if cur_tag is 'key'
-                                               done = true
-                                               auth.sk = str
-                                               console.log("got key \"#{str}\"")
-                                               callback null, str
-                                       else if cur_tag is 'error'
-                                               done = true
-                                               callback "login failed: #{str}"
-                                       # ignore other stuff in there
+                               parser = new xml.SaxParser (cb) ->
+                                       cb.onStartElementNS (name, attrs, prefix, uri, namespaces) ->
+                                               cur_tag = name
+                                       cb.onCharacters (str) ->
+                                               if cur_tag is 'key'
+                                                       done = true
+                                                       auth.sk = str
+                                                       console.log("got key \"#{str}\"")
+                                                       callback null, str
+                                               else if cur_tag is 'error'
+                                                       done = true
+                                                       callback "login failed: #{str}"
+                                               # ignore other stuff in there
                                unless parser.parse body, true
                                        done = true
                                        callback "login server response wouldn't parse as XML."