diff --git a/src/server/server.c b/src/server/server.c
index 559b2a5..87401fd 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -42,9 +42,6 @@
#define STREAM_RESP ""
#define FEATURES ""
-#define AUTH_RESP ""
-#define AUTH_FAIL ""
-
#define STREAM_END ""
pthread_mutex_t send_queue_lock;
@@ -170,23 +167,50 @@ auth_callback(XMPPStanza *stanza)
{
log_println("--> Auth callback fired");
+ const char *id = stanza_get_id(stanza);
XMPPStanza *query = stanza_get_child_by_ns(stanza, "jabber:iq:auth");
XMPPStanza *username = stanza_get_child_by_name(query, "username");
XMPPStanza *password = stanza_get_child_by_name(query, "password");
XMPPStanza *resource = stanza_get_child_by_name(query, "resource");
- client->username = strdup(username->content->str);
- client->password = strdup(password->content->str);
- client->resource = strdup(resource->content->str);
+ if (!username || !password || !resource) {
+ GString *authfields = g_string_new("");
+ if (!username) {
+ g_string_append(authfields, "");
+ }
+ if (!password) {
+ g_string_append(authfields, "");
+ }
+ if (!resource) {
+ g_string_append(authfields, "");
+ }
+ g_string_append(authfields, "");
+ write_stream(authfields->str);
+ g_string_free(authfields, TRUE);
+ } else {
+ client->username = strdup(username->content->str);
+ client->password = strdup(password->content->str);
+ client->resource = strdup(resource->content->str);
- char *expected_password = prime_get_passwd();
- if (g_strcmp0(client->password, expected_password) != 0) {
- write_stream(AUTH_FAIL);
- write_stream(STREAM_END);
- return;
+ char *expected_password = prime_get_passwd();
+ if (g_strcmp0(client->password, expected_password) != 0) {
+ GString *authfail = g_string_new("");
+ write_stream(authfail->str);
+ g_string_free(authfail, TRUE);
+ write_stream(STREAM_END);
+ return;
+ }
+
+ GString *authsuccess = g_string_new("");
+ write_stream(authsuccess->str);
+ g_string_free(authsuccess, TRUE);
}
-
- write_stream(AUTH_RESP);
}
void