diff --git a/src/server/slave.c b/src/server/slave.c --- a/src/server/slave.c +++ b/src/server/slave.c @@ -29,24 +29,44 @@ // Provides DISTREN_REQUEST* which is in reality, DISTREN_SEND(signal) in the minds of your average joe #include "protocol.h" +#include -int main(int argc, char *arvg[]) +int slavestatus = 0; // Ugh global vars + +int main(int argc, char *argv[]) { - /* Semi-pseudo Slave Code */ - - - int slavestatus = 0; +/* Parses arguments, skips if there are no args */ + if(argc>1 + && (strcmp("-c", argv[1]) == 0)) + { + char *username; + char *email; - if('no username in config file, no key present'){ - fprintf(stderr "run distrend -c username] [emailaddr] to register") - } - if('they use a -c flag according to getopt, with 2 args'){ + if(argc != 4) + { + fprintf(stderr, "I need more arguments!\n%d is not enough!\n Invoke 'slave -c to register'", argc - 1); + return 234; + } + + username = argv[2]; + email = argv[3]; + + if(!strchr(email, '@')) + { + fprintf(stderr, "I want to see an '@' in your email address!\n%s may be good enough for you, but I need more!\n", email); + return 235; + } *key = register_user(username, email); // register_user returns a uniquely random url to a key get("http://protofusion.org/distren/key/%s",key); fprintf(stderr, "you registered, hopefully successfully. Invoke distrend with no args now."); + exec('echo %s >> distrend.conf',key); } - if('username is in conf file and key is present'){ +/* End arg parser */ + + + + if('username and the user\'s key filename are in conf file'){ loginuser(username); }