Skip to content
Browse files

- moved files around a bit

- made it an option to pass authenticate params on connect() to reduce common authenticate dance
  • Loading branch information...
1 parent e818b0e commit 4f4c9810c7fb34a7446dcf8ffa8c194a99178da8 @benvanik committed
View
16 examples/client-ex.js
@@ -3,20 +3,8 @@ var nntp = require("../lib/node-nntp");
var exconfig = require("./example-config");
var client = new nntp.Client();
-client.connect(exconfig.host, exconfig.port).addCallback(function() {
- // if username provided, attempt to authenticate
- if (exconfig.username) {
- client.authenticate(
- exconfig.username, exconfig.password
- ).addCallback(function(responseCode, responseLine) {
- onReady();
- }).addErrback(function() {
- sys.puts("failed to authenticate");
- client.quit().wait();
- });
- } else {
- onReady();
- }
+client.connect(exconfig.host, exconfig.port, exconfig.username, exconfig.password).addCallback(function() {
+ onReady();
}).addErrback(function() {
sys.puts("failed to connect");
});
View
0 lib/nntp/NZBFile.js → lib/content/NZBFile.js
File renamed without changes.
View
20 lib/nntp/Client.js
@@ -1,6 +1,6 @@
var sys = require("sys");
var tcp = require("tcp");
-require("./utils");
+require("../utils");
var Client = function() {
var self = this;
@@ -19,7 +19,7 @@ var Client = function() {
this.pendingReadBlock = null;
}
-Client.prototype.connect = function(host, port) {
+Client.prototype.connect = function(host, port, username, password) {
var self = this;
var promise = new process.Promise();
@@ -47,7 +47,19 @@ Client.prototype.connect = function(host, port) {
case 200: // Posting allowed
case 201: // Posting prohibited
self.state = "connected";
- promise.emitSuccess();
+ if (username) {
+ // if passed a username/password, authenticate inline
+ self.authenticate(
+ username, password
+ ).addCallback(function(responseCode, responseLine) {
+ promise.emitSuccess();
+ }).addErrback(function() {
+ self.quit();
+ promise.emitError();
+ });
+ } else {
+ promise.emitSuccess();
+ }
break;
default:
// TODO: error code/text
@@ -102,7 +114,7 @@ Client.prototype.readLine = function() {
}
Client.prototype.writeLine = function(line) {
- sys.puts("C" + this.debugName+ "> " + line);
+ sys.puts("C" + this.debugName + "> " + line);
// assumes no trailing linefeed passed in
this.socket.send(line + "\r\n");
}
View
18 lib/nntp/Queue.js
@@ -1,6 +1,6 @@
var sys = require("sys");
var tcp = require("tcp");
-require("./utils");
+require("../utils");
var Client = require("./client").Client;
var Queue = function() {
@@ -46,20 +46,8 @@ Queue.prototype.connect = function(count, connSettings) {
var client = new Client();
client.debugName = n.toString();
pendingClients.push(client);
- client.connect(connSettings.host, connSettings.port).addCallback(function() {
- // if username provided, attempt to authenticate
- if (connSettings.username) {
- client.authenticate(
- connSettings.username, connSettings.password
- ).addCallback(function(responseCode, responseLine) {
- onConnected(client);
- }).addErrback(function() {
- sys.puts("failed to authenticate");
- onFailed(client);
- });
- } else {
- onConnected(client);
- }
+ client.connect(connSettings.host, connSettings.port, connSettings.username, connSettings.password).addCallback(function() {
+ onConnected(client);
}).addErrback(function() {
sys.puts("failed to connect");
onFailed(client);
View
2 lib/node-nntp.js
@@ -1,4 +1,4 @@
exports.Client = require("./nntp/Client").Client;
exports.Queue = require("./nntp/Queue").Queue;
-exports.NZBFile = require("./nntp/NZBFile").NZBFile;
+exports.NZBFile = require("./content/NZBFile").NZBFile;
View
0 lib/nntp/utils.js → lib/utils.js
File renamed without changes.

0 comments on commit 4f4c981

Please sign in to comment.
Something went wrong with that request. Please try again.