# HG changeset patch # User Matti Hamalainen # Date 1290036401 -7200 # Node ID 21a37995c3fbde58c8cc17e1db56d4e0101c176c # Parent e0ec2280a778a83914a2bb689784fee4311e46fc Make configuration username/password overridable on command line. diff -r e0ec2280a778 -r 21a37995c3fb nnchat.c --- a/nnchat.c Wed Nov 17 09:57:32 2010 +0200 +++ b/nnchat.c Thu Nov 18 01:26:41 2010 +0200 @@ -38,8 +38,10 @@ int optUserColor = 0x006080; char *optServer = "chat.newbienudes.com", *optUserName = NULL, - *optUserName2 = NULL, + *optUserNameCmd = NULL, + *optUserNameEnc = NULL, *optPassword = NULL, + *optPasswordCmd = NULL, *optLogFilename = NULL, *setTarget = NULL, *optSite = "NN"; @@ -143,12 +145,12 @@ BOOL argHandleFile(char *currArg) { - if (!optUserName) - optUserName = currArg; - else if (!optPassword) - optPassword = currArg; + if (!optUserNameCmd) + optUserNameCmd = currArg; + else if (!optPasswordCmd) + optPasswordCmd = currArg; else { - THERR("Username '%s' already specified on commandline!\n", optUserName); + THERR("Username '%s' already specified on commandline!\n", optUserNameCmd); return FALSE; } @@ -474,7 +476,7 @@ return -2; } else if (!strncmp(str, "SUCCESS", 7)) { printMsg("½2½Login success½0½ - ½3½%s½0½\n", tmpStr); - nn_conn_send_msg(conn, optUserName2, "%%2FRequestUserList"); + nn_conn_send_msg(conn, optUserNameEnc, "%%2FRequestUserList"); return 0; } else return 1; @@ -615,7 +617,7 @@ } optUserColor = tmpInt; printMsg("Setting color to #%06x\n", optUserColor); - nn_conn_send_msg(conn, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); + nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); return 0; } else if (!strncasecmp(buf, "/ignore", 7)) { char *name = trimLeft(buf + 7); @@ -724,7 +726,7 @@ /* Send double-encoded */ tmpStr = nn_dblencode_str(decodeUsername(buf)); if (tmpStr == 0) return -2; - result = nn_conn_send_msg(conn, optUserName2, "%s", tmpStr); + result = nn_conn_send_msg(conn, optUserNameEnc, "%s", tmpStr); th_free(tmpStr); return result ? 0 : -1; @@ -973,6 +975,11 @@ argsOK = th_args_process(argc, argv, optList, optListN, argHandleOpt, argHandleFile, FALSE); + if (optUserNameCmd != NULL) { + optUserName = optUserNameCmd; + optPassword = optPasswordCmd; + } + /* Check if we have username and password */ if (optUserName == NULL || optPassword == NULL) { printf("\nYou can avoid this prompt by issuing '/save' after logging in.\n\n"); @@ -1049,9 +1056,9 @@ } THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite); - optUserName2 = nn_dblencode_str(optUserName); + optUserNameEnc = nn_dblencode_str(optUserName); tmpStr = nn_dblencode_str(optSite); - nn_conn_send_msg(conn, optUserName2, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); + nn_conn_send_msg(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); th_free(tmpStr); /* Initialize NCurses */ @@ -1339,7 +1346,7 @@ if (++updateCount > 10) { time_t tmpTime = time(NULL); if (tmpTime - prevTime > SET_KEEPALIVE) { - nn_conn_send_msg(conn, optUserName2, "/listallusers"); + nn_conn_send_msg(conn, optUserNameEnc, "/listallusers"); prevTime = tmpTime; } @@ -1348,7 +1355,7 @@ printMsg("%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_fullname); printMsg("%s\n", th_prog_author); printMsg("%s\n", th_prog_license); - nn_conn_send_msg(conn, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); + nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); } updateStatus(insertMode); @@ -1377,7 +1384,7 @@ THMSG(1, "Error exit.\n"); } - th_free(optUserName2); + th_free(optUserNameEnc); nn_conn_close(conn);