Skip to content

Commit

Permalink
Move Notifo-specific details into send_message()
Browse files Browse the repository at this point in the history
Issue #226
  • Loading branch information
amyreese committed Sep 29, 2011
1 parent 0af5679 commit 4667fd5
Showing 1 changed file with 31 additions and 39 deletions.
70 changes: 31 additions & 39 deletions push.cpp
Expand Up @@ -144,13 +144,6 @@ class CPushMod : public CModule
// Application name
CString app;

// BASIC auth string, needs to be encoded each time username/secret is changed
CString notifo_auth;

// Host and URL to send messages to
CString notifo_host;
CString notifo_url;

// Time last notification was sent for a given context
map <CString, unsigned int> last_notification_time;

Expand All @@ -176,9 +169,6 @@ class CPushMod : public CModule
app = "ZNC";

idle_time = time(NULL);
notifo_auth = "";
notifo_host = "api.notifo.com";
notifo_url = "/v1/send_notification";

// Current user
user = GetUser();
Expand Down Expand Up @@ -229,16 +219,6 @@ class CPushMod : public CModule

protected:

/**
* Re-encode the authentication credentials.
*/
void authencode()
{
// BASIC auth, base64-encoded username:password
CString auth = options["username"] + CString(":") + options["secret"];
notifo_auth = auth.Base64Encode_n();
}

/**
* Performs string expansion on a set of keywords.
* Given an initial string and a dictionary of string replacments,
Expand Down Expand Up @@ -298,17 +278,41 @@ class CPushMod : public CModule
replace["{unixtime}"] = CString(time(NULL));
CString uri = expand(options["message_uri"], replace);

// Set up the connection profile
CString service = options["service"];
bool use_post = true;
int use_port = 443;
bool use_ssl = true;
CString service_host;
CString service_url;
CString service_auth;
MCString params;
params["to"] = options["username"];
params["msg"] = short_message;
params["label"] = app;
params["title"] = title;
params["uri"] = uri;

if (service == "notifo")
{
service_host = "api.notifo.com";
service_url = "/v1/send_notification";

// BASIC auth, base64-encoded username:password
service_auth = options["username"] + CString(":") + options["secret"];
service_auth.Base64Encode();

params["to"] = options["username"];
params["msg"] = short_message;
params["label"] = app;
params["title"] = title;
params["uri"] = uri;
}
else
{
PutModule("Error: service type not selected");
return;
}

// Create the socket connection, write to it, and add it to the queue
CPushSocket *sock = new CPushSocket(this);
sock->Connect(notifo_host, 443, true);
sock->Request(true, notifo_host, notifo_url, params, notifo_auth);
sock->Connect(service_host, use_port, use_ssl);
sock->Request(use_post, service_host, service_url, params, service_auth);
AddSocket(sock);
}

Expand Down Expand Up @@ -677,8 +681,6 @@ class CPushMod : public CModule
}
}

authencode();

return true;
}

Expand Down Expand Up @@ -903,8 +905,6 @@ class CPushMod : public CModule

options[option] = value;
SetNV(option, options[option]);

authencode();
}
}
// APPEND command
Expand Down Expand Up @@ -933,8 +933,6 @@ class CPushMod : public CModule
options[option] += " " + value;
options[option].Trim();
SetNV(option, options[option]);

authencode();
}
}
// PREPEND command
Expand Down Expand Up @@ -963,8 +961,6 @@ class CPushMod : public CModule
options[option] = value + " " + options[option];
options[option].Trim();
SetNV(option, options[option]);

authencode();
}
}
// UNSET command
Expand All @@ -987,8 +983,6 @@ class CPushMod : public CModule
{
options[option] = defaults[option];
DelNV(option);

authencode();
}
}
// GET command
Expand Down Expand Up @@ -1099,8 +1093,6 @@ class CPushMod : public CModule
SetNV(option, options[option]);
}
}

authencode();
}
else
{
Expand Down

0 comments on commit 4667fd5

Please sign in to comment.