# HG changeset patch # User Emmanuel Gil Peyrot # Date 1288565887 -3600 # Node ID 5fc4ee90c1bcd9c21f6f207632db1e75417ba21f # Parent 0f42c9c8085af26934b5b4865a4c08389fdeb5dd A lot of refactorization. First attempt to modularize the server. diff --git a/errors.js b/errors.js --- a/errors.js +++ b/errors.js @@ -196,3 +196,23 @@ function reverseError(o) { } reverseError(errors); + +exports.makeError = function(response, errorNumber, payload) { + response.attr.type = 'error'; + if (payload) + response.cnode(payload); + + var e = errors.reverse[errorNumber]; + response.c('error', {type: e.type}); + + response.c(e.error, {xmlns: 'urn:ietf:params:xml:ns:xmpp-stanzas'}).up(); + + if (e.reason) { + if (e.feature) + response.c(e.reason, {xmlns: 'http://jabber.org/protocol/pubsub#errors', feature: e.feature}).up(); + else + response.c(e.reason, {xmlns: 'http://jabber.org/protocol/pubsub#errors'}).up(); + } + + return response; +} diff --git a/forms.js b/forms.js --- a/forms.js +++ b/forms.js @@ -33,14 +33,14 @@ exports.build = function(type, desc, con desc = service_configuration[desc]; if (desc._TITLE) - x.s('title').t(desc._TITLE); + x.c('title').t(desc._TITLE).up(); else if (title) - x.s('title').t(title); + x.c('title').t(title).up(); if (desc._INSTRUCTIONS) - x.s('instructions').t(desc._INSTRUCTIONS); + x.c('instructions').t(desc._INSTRUCTIONS).up(); else if (instructions) - x.s('instructions').t(instructions); + x.c('instructions').t(instructions).up(); if (content == 'default') { content = {}; @@ -60,7 +60,7 @@ exports.build = function(type, desc, con if (desc[i].label) fieldAttr.label = desc[i].label; } - var field = xmpp.stanza('field', fieldAttr); + x.c('field', fieldAttr); if (labels && (desc[i].type == 'list-multi' || @@ -69,29 +69,27 @@ exports.build = function(type, desc, con var optAttr = {}; if (desc[i].options[j].label) optAttr.label = desc[i].options[j].label; - field.s('option', optAttr).c('value').t(j); + x.c('option', optAttr).c('value').t(j).up().up(); } } if (i == 'FORM_TYPE') - field.s('value').t(desc[i].value); + x.c('value').t(desc[i].value).up(); else if (typeof content[i] != 'undefined') { var md = content[i]; if (desc[i].type == 'jid-multi' || desc[i].type == 'list-multi' || desc[i].type == 'text-multi') { for (var j=0; j