"Please register only once per session", NULL);
} else if(c->network->connection.state == NETWORK_CONNECTION_STATE_MOTD_RECVD) {
if (c->network->config->disable_cache || !client_try_cache(c, l)) {
- redirect_record(c, l);
/* Perhaps check for validity of input here ? It could save us some bandwidth
* to the server, though very unlikely to occur often */
network_send_line(c->network, c, l);
return ret;
}
-gboolean client_send_line(struct client *c, const struct line *l)
+gboolean client_send_line(const struct client *c, const struct line *l)
{
log_client_line(c, l, FALSE);
return irc_send_line(c->incoming, l);
struct query_stack {
struct query *query;
- struct network *network;
- struct client *client;
+ const struct network *network;
+ const struct client *client;
struct query_stack *next;
};
int errors[20];
/* Should add this query to the stack. return TRUE if this has
* been done successfully, FALSE otherwise */
- int (*handle) (struct line *, struct client *c, struct query *);
+ int (*handle) (const struct line *, const struct network *n, const struct client *c, struct query *);
};
-static int handle_default(struct line *, struct client *c, struct query *);
-static int handle_topic(struct line *, struct client *c, struct query *);
+static int handle_default(const struct line *, const struct network *n, const struct client *c, struct query *);
+static int handle_topic(const struct line *, const struct network *n, const struct client *c, struct query *);
static struct query queries[] = {
/* Commands that get a one-client reply:
handle_default
},
+ /* USER <username> <hostname> <servername> <realname> */
+ { "USER",
+ { 0 },
+ { 0 },
+ { ERR_NEEDMOREPARAMS, ERR_ALREADYREGISTERED, 0 },
+ handle_default
+ },
+
/* OPER <name> <password> */
{ "OPER",
{ 0 },
}
/* List of responses that should be sent to all clients */
-static int response_all[] = { RPL_NOWAWAY, RPL_UNAWAY, 0 };
+static int response_all[] = { RPL_NOWAWAY, RPL_UNAWAY, RPL_NAMREPLY,
+ RPL_ENDOFNAMES, 0 };
static int response_none[] = { ERR_NOMOTD, RPL_ENDOFMOTD, 0 };
static struct {
int response;
void redirect_response(struct network *network, struct line *l)
{
- struct query_stack *s = stack, *p = NULL;
- struct client *c = NULL;
+ struct query_stack *s, *p = NULL;
+ const struct client *c = NULL;
int n;
int i;
n = atoi(l->args[0]);
/* Find a request that this response is a reply to */
- while(s) {
+ for (s = stack; s; s = s->next) {
if(s->network == network &&
(is_reply(s->query->replies, n) ||
is_reply(s->query->errors, n) ||
g_free(s);
}
- break;
+ return;
}
- p = s; s = s->next;
+ p = s;
}
/* See if this is a response that should be sent to all clients */
}
}
+ /* Handle response using custom function */
for (i = 0; response_handler[i].handler; i++) {
if (response_handler[i].response == n) {
response_handler[i].handler(network, l);
}
}
-void redirect_record(struct client *c, struct line *l)
+void redirect_record(const struct network *n, const struct client *c, const struct line *l)
{
struct query *q;
q = find_query(l->args[0]);
if(!q) {
- log_client(NULL, LOG_WARNING, c, "Unknown command from client: %s", l->args[0]);
+ if (c) {
+ log_client(NULL, LOG_WARNING, c, "Unknown command from client: %s", l->args[0]);
+ } else {
+ log_network(NULL, LOG_WARNING, n, "Sending unknown command '%s'", l->args[0]);
+ }
return;
}
+
/* Push it up the stack! */
- q->handle(l, c, q);
+ q->handle(l, n, c, q);
}
-static int handle_default(struct line *l, struct client *c, struct query *q)
+static int handle_default(const struct line *l, const struct network *n, const struct client *c, struct query *q)
{
struct query_stack *s = g_new(struct query_stack,1);
- s->network = c->network;
+ s->network = n;
s->client = c;
s->query = q;
s->next = stack;
return 1;
}
-static int handle_topic(struct line *l, struct client *c, struct query *q)
+static int handle_topic(const struct line *l, const struct network *n, const struct client *c, struct query *q)
{
if(l->args[2])return 0;
- return handle_default(l,c,q);
+ return handle_default(l,n,c,q);
}