/* Prompt for answer and get text back. Reply text is either NULL on ** error or a dynamic string which the caller must HT_FREE. */ PUBLIC BOOL HTPrompt (HTRequest * request, HTAlertOpcode op, int msgnum, const char * dfault, void * input, HTAlertPar * reply) { HTPrint("%s ", HTDialogs[msgnum]); if (input) HTPrint(" (%s) ", (char *) input); if (dfault) HTPrint("(RETURN for [%s]) ", (char *) dfault); if (reply && msgnum>=0) { char buffer[200]; if (!fgets(buffer, 200, stdin)) return NO; buffer[strlen(buffer)-1] = '\0'; /* Overwrite newline */ if (*buffer) HTAlert_setReplyMessage(reply, buffer); else if (dfault) HTAlert_setReplyMessage(reply, (char *) dfault); else return NO; return YES; } return NO; }
PUBLIC BOOL UserNameAndPassword (HTRequest * request, HTAlertOpcode op, int msgnum, const char * dfault, void * input, HTAlertPar * reply) { CUserParameters UserParams(request, op, msgnum, dfault, input, reply); CPassword AskUserNameAndPassword( &UserParams ); if (AskUserNameAndPassword.DoModal() == IDOK) { HTAlert_setReplyMessage(reply, AskUserNameAndPassword.m_username); HTAlert_setReplySecret(reply, AskUserNameAndPassword.m_password); return YES; } return NO; }
PRIVATE BOOL PromptUsernameAndPassword (HTRequest * request, HTAlertOpcode op, int msgnum, const char * dfault, void * input, HTAlertPar * reply) { ComLine * cl = (ComLine *) HTRequest_context(request); char * realm = (char *) input; if (request && cl) { /* ** If we have a realm then check that it matches the realm ** that we got from the server. */ if (realm && cl->realm && !strcmp(cl->realm, realm)) { HTAlert_setReplyMessage(reply, cl->user ? cl->user : ""); HTAlert_setReplySecret(reply, cl->password ? cl->password : ""); return YES; } else { BOOL status = HTPrompt(request, op, msgnum, dfault, input, reply); return status ? HTPromptPassword(request, op, HT_MSG_PW, dfault, input, reply) : NO; } } return NO; }