From ffef7816a745964e42bbf7409975b127bb454152 Mon Sep 17 00:00:00 2001 From: pk910 Date: Thu, 24 Jul 2014 15:17:22 +0200 Subject: [PATCH] added some code --- src/Makefile.am | 1 + src/cmd.h | 4 ++-- src/cmd_nick.c | 15 +++++++++++++++ src/cmd_nick.h | 27 --------------------------- src/cmd_user.c | 5 +++-- src/ircd_parse.c | 38 ++++++++++++++++++++++---------------- src/ircd_users.c | 8 +++++++- src/ircd_users.h | 1 + 8 files changed, 51 insertions(+), 48 deletions(-) delete mode 100644 src/cmd_nick.h diff --git a/src/Makefile.am b/src/Makefile.am index 5fc1b20..9534bf4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,5 +24,6 @@ nextircd_SOURCES = \ ircd_auth.c \ ircd_users.c \ cmd_nick.c \ + cmd_user.c \ main.c diff --git a/src/cmd.h b/src/cmd.h index a2896a4..b3ec269 100644 --- a/src/cmd.h +++ b/src/cmd.h @@ -22,9 +22,9 @@ struct Client; struct Auth; struct Server; - int cmd_nick_cli(struct Client *client, char *argv[], int argc); int cmd_nick_auth(struct Auth *auth, char *argv[], int argc); - +int cmd_user_cli(struct Client *client, char *argv[], int argc); +int cmd_user_auth(struct Auth *auth, char *argv[], int argc); #endif diff --git a/src/cmd_nick.c b/src/cmd_nick.c index effb22f..ae47e01 100644 --- a/src/cmd_nick.c +++ b/src/cmd_nick.c @@ -15,8 +15,12 @@ * along with this program. If not, see . */ +#include + #include "cmd.h" #include "struct_auth.h" +#include "ircd_users.h" +#include "ircd_auth.h" int cmd_nick_cli(struct Client *client, char *argv[], int argc) { @@ -24,6 +28,17 @@ int cmd_nick_cli(struct Client *client, char *argv[], int argc) { } int cmd_nick_auth(struct Auth *auth, char *argv[], int argc) { + char *nick = argv[0]; + + if(!is_nick_valid(nick)) { + + return 0; + } + + strncpy(auth->nick, nick, NICKLEN); + auth->have_nick = 1; + + auth_try_finish(auth); return 0; } diff --git a/src/cmd_nick.h b/src/cmd_nick.h deleted file mode 100644 index 66df83d..0000000 --- a/src/cmd_nick.h +++ /dev/null @@ -1,27 +0,0 @@ -/* cmd_ping.h - NextIRCd - * Copyright (C) 2012-2013 Philipp Kreil (pk910) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef _cmd_ping_h -#define _cmd_ping_h - -struct Client; -struct Auth; - -int cmd_nick_cli(struct Client *client, char *argv[], int argc); -int cmd_nick_auth(struct Auth *auth, char *argv[], int argc); - -#endif diff --git a/src/cmd_user.c b/src/cmd_user.c index ea06a08..f2a8d38 100644 --- a/src/cmd_user.c +++ b/src/cmd_user.c @@ -19,6 +19,7 @@ #include "cmd.h" #include "struct_auth.h" +#include "struct_user.h" #include "ircd_users.h" #include "ircd_auth.h" @@ -38,12 +39,12 @@ int cmd_user_auth(struct Auth *auth, char *argv[], int argc) { if(user == hostname) user = "NoUser"; } - if(!is_user_valid(user)) { + if(!is_ident_valid(user)) { // invalid user return 0; } - strncpy(auth->ident, user, USERLEN); + strncpy(auth->ident, user, IDENTLEN); strncpy(auth->realname, realname, REALLEN); auth->have_user = 1; diff --git a/src/ircd_parse.c b/src/ircd_parse.c index 12dc6de..54cdad2 100644 --- a/src/ircd_parse.c +++ b/src/ircd_parse.c @@ -15,8 +15,14 @@ * along with this program. If not, see . */ +#include + #include "tools.h" #include "IOHandler/IOSockets.h" +#include "ircd_parse.h" +#include "struct_client.h" +#include "struct_auth.h" +#include "struct_servermsg.h" typedef int cmd_client_t(struct Client *client, char *argv[], int argc); typedef int cmd_auth_t(struct Auth *auth, char *argv[], int argc); @@ -27,7 +33,7 @@ static struct ServerMsg parse_static_srvmsg; #define PARSE_CLIFLAG_OPONLY 0x01 //include all commands -#include "cmd_ping.h" +#include "cmd.h" struct { @@ -54,7 +60,7 @@ struct { unsigned int flags : 8; } server; -} parse_command_list { +} parse_command_list[] = { {{"PING", "P"}, /* Ping Command */ {NULL, 0, 1, 0}, /* Client */ {NULL, 0, 1, 0}, /* Unauthed */ @@ -71,8 +77,8 @@ struct { {NULL, 0, 1, 0} /* Server */ }, {{"USER", "U"}, /* User Command */ - {NULL, 0, 1, 0}, /* Client */ - {NULL, 0, 1, 0}, /* Unauthed */ + {cmd_user_cli, 4, 4, 0}, /* Client */ + {cmd_user_auth, 4, 1, 0}, /* Unauthed */ {NULL, 0, 1, 0} /* Server */ }, @@ -101,18 +107,18 @@ static char **parse_irc_params(char *data, int *argc, int maxargs) { char **argv = calloc(maxargs, sizeof(*argv)); while(*data) { //skip leading spaces - while (*line == ' ') - *line++ = 0; - if (*line == ':') { + while (*data == ' ') + *data++ = 0; + if (*data == ':') { //the rest is a single parameter - argv[*argc++] = line + 1; + argv[*argc++] = data + 1; break; } - argv[*argc++] = line; - if (argc >= maxargs) + argv[*argc++] = data; + if (*argc >= maxargs) break; - while (*line != ' ' && *line) - line++; + while (*data != ' ' && *data) + data++; } return argv; } @@ -237,7 +243,7 @@ void parse_server_data(struct Server *server, struct IOSocketBuffer *buffer) { srvmsg->destinations = malloc(sizeof(struct ServerMsgDstMap)); srvmsg->destinations->dstcount = 1; srvmsg->destinations->dst[0].destination.srvnum = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); - srvmsg->destinations->dst[0].destination.resolved_destination = 0; + srvmsg->destinations->dst[0].resolved_destination = 0; break; case SERVERMSG_TYPE_MULTICAST: if(buflen < 5) { @@ -255,7 +261,7 @@ void parse_server_data(struct Server *server, struct IOSocketBuffer *buffer) { srvmsg->destinations->dstcount = srvcount; for(i = 0; i < srvcount; i++) { srvmsg->destinations->dst[i].destination.srvnum = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); - srvmsg->destinations->dst[i].destination.resolved_destination = 0; + srvmsg->destinations->dst[i].resolved_destination = 0; buf += 4; buflen -= 4; } @@ -275,7 +281,7 @@ void parse_server_data(struct Server *server, struct IOSocketBuffer *buffer) { goto parse_server_data_finish; } - srvmsg->arglen = srvmsg->msglen - (buf - buffer->buffer); + srvmsg->arglen = srvmsg->msglen - (buf - (unsigned char*)buffer->buffer); srvmsg->args = buf; int found = 0; @@ -299,7 +305,7 @@ void parse_server_data(struct Server *server, struct IOSocketBuffer *buffer) { memmove(buffer->buffer, buffer->buffer + srvmsg->msglen, srvmsg->msglen - buffer->bufpos); buffer->bufpos -= srvmsg->msglen; } else - srvmsg->bufpos = 0; + buffer->bufpos = 0; } } diff --git a/src/ircd_users.c b/src/ircd_users.c index 9faaacd..f3fcbb5 100644 --- a/src/ircd_users.c +++ b/src/ircd_users.c @@ -14,6 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +#include + #include "struct_user.h" struct UserDictEntry { @@ -33,6 +36,9 @@ void find_user_by_nick(char *nick) { } int is_nick_valid(char *nick) { - + return 1; } +int is_ident_valid(char *ident) { + return 1; +} diff --git a/src/ircd_users.h b/src/ircd_users.h index a45a176..56c77ad 100644 --- a/src/ircd_users.h +++ b/src/ircd_users.h @@ -19,5 +19,6 @@ #define _ircd_users_h int is_nick_valid(char *nick); +int is_ident_valid(char *ident); #endif -- 2.20.1