From: Jason Woofenden Date: Thu, 6 Oct 2011 20:52:38 +0000 (-0400) Subject: starting to switch to node-xml X-Git-Url: https://jasonwoof.com/gitweb/?p=libre-fm-client-daemon.git;a=commitdiff_plain;h=96118d765980c472bb3cafe75cd16b736724fe0d starting to switch to node-xml --- diff --git a/auth.coffee b/auth.coffee index 833b553..1b776ab 100644 --- a/auth.coffee +++ b/auth.coffee @@ -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."