Mercurial > hg > nnchat
comparison nnchat.c @ 196:edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 17 Nov 2010 05:13:12 +0200 |
parents | 829457be9eea |
children | e0ec2280a778 |
comparison
equal
deleted
inserted
replaced
195:829457be9eea | 196:edd5ce3e5399 |
---|---|
867 } | 867 } |
868 | 868 |
869 return FALSE; | 869 return FALSE; |
870 } | 870 } |
871 | 871 |
872 char *promptRequester(const char *info) | |
873 { | |
874 char tmpBuf[512]; | |
875 ssize_t bufLen; | |
876 | |
877 fputs(info, stdout); | |
878 fgets(tmpBuf, sizeof(tmpBuf), stdin); | |
879 | |
880 for (bufLen = strlen(tmpBuf) - 1; bufLen > 0 && (tmpBuf[bufLen] == '\n' || tmpBuf[bufLen] == '\r' || th_isspace(tmpBuf[bufLen])); bufLen--) | |
881 tmpBuf[bufLen] = 0; | |
882 | |
883 if (bufLen > 0) | |
884 return th_strdup(tmpBuf); | |
885 else | |
886 return NULL; | |
887 } | |
872 | 888 |
873 int main(int argc, char *argv[]) | 889 int main(int argc, char *argv[]) |
874 { | 890 { |
875 nn_conn_t *conn = NULL; | 891 nn_conn_t *conn = NULL; |
876 int curVis = ERR, updateCount = 0; | 892 int curVis = ERR, updateCount = 0; |
937 THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); | 953 THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); |
938 | 954 |
939 if ((cfgfile = fopen(setConfigFile, "r")) != NULL) | 955 if ((cfgfile = fopen(setConfigFile, "r")) != NULL) |
940 th_cfg_read(cfgfile, setConfigFile, cfg); | 956 th_cfg_read(cfgfile, setConfigFile, cfg); |
941 } | 957 } |
942 | 958 |
943 setBrowser = getenv("BROWSER"); | 959 setBrowser = getenv("BROWSER"); |
944 if (setBrowser == NULL) | 960 if (setBrowser == NULL) |
945 setBrowser = "firefox"; | 961 setBrowser = "firefox"; |
946 | 962 |
947 /* Parse command line arguments */ | 963 /* Parse command line arguments */ |
948 argsOK = th_args_process(argc, argv, optList, optListN, | 964 argsOK = th_args_process(argc, argv, optList, optListN, |
949 argHandleOpt, argHandleFile, FALSE); | 965 argHandleOpt, argHandleFile, FALSE); |
950 | 966 |
951 /* Check if we have username and password */ | 967 /* Check if we have username and password */ |
952 if (optUserName == NULL || optPassword == NULL) { | 968 if (optUserName == NULL || optPassword == NULL) { |
953 THERR("User/pass not specified, get some --help\n"); | 969 printf("\nYou can avoid this prompt by issuing '/save' after logging in.\n\n"); |
954 return -1; | 970 optUserName = promptRequester("NN username: "); |
971 optPassword = promptRequester("NN password: "); | |
972 if (optUserName == NULL || optPassword == NULL) { | |
973 THERR("User/pass not specified, get some --help\n"); | |
974 return -1; | |
975 } | |
955 } | 976 } |
956 | 977 |
957 if (!argsOK) | 978 if (!argsOK) |
958 return -2; | 979 return -2; |
959 | 980 |