async dialog work for ftp; generalized async interface

This commit is contained in:
spence%netscape.com 1999-04-08 07:37:37 +00:00
Родитель 370ed1b1aa
Коммит 8cf2a49871
20 изменённых файлов: 128 добавлений и 41 удалений

2
network/cache/mkmemcac.c поставляемый
Просмотреть файл

@ -2045,6 +2045,7 @@ NET_InitMemCacProtocol(void) /* no prototype when NU_CACHE */
mem_cac_proto_impl.init = net_MemoryCacheLoad;
mem_cac_proto_impl.process = net_ProcessMemoryCache;
mem_cac_proto_impl.interrupt = net_InterruptMemoryCache;
mem_cac_proto_impl.resume = NULL;
mem_cac_proto_impl.cleanup = net_CleanupMemoryCacheProtocol;
NET_RegisterProtocolImplementation(&mem_cac_proto_impl, MEMORY_CACHE_TYPE_URL);
@ -2310,6 +2311,7 @@ NET_InitNuCacheProtocol(void)
nu_cache_proto_impl.init = net_NuCacheLoad;
nu_cache_proto_impl.process = net_ProcessNuCache;
nu_cache_proto_impl.interrupt = net_InterruptNuCache;
nu_cache_proto_impl.resume = NULL;
nu_cache_proto_impl.cleanup = net_CleanupNuCacheProtocol;
NET_RegisterProtocolImplementation(&nu_cache_proto_impl, NU_CACHE_TYPE_URL);

Просмотреть файл

@ -3143,10 +3143,6 @@ redo_load_switch: /* come here on file/ftp retry */
#endif
}
/* forward declaration */
PUBLIC void NET_ResumeHTTP (ActiveEntry *, PRBool);
/* this thing is a hack that will allow http streams
waiting on passwd auth to resume XXX */
PUBLIC void NET_ResumeWithAuth (void *closure)
@ -3162,27 +3158,27 @@ PUBLIC void NET_ResumeWithAuth (void *closure)
}
iter = net_EntryList;
while (tmpEntry = (ActiveEntry *) XP_ListNextObject(iter)) {
while ((tmpEntry = (ActiveEntry *) XP_ListNextObject(iter))) {
if (tmpEntry == (ActiveEntry *) auth_closure->_private) {
break;
} else {
return;
}
}
if (!tmpEntry)
return;
if (auth_closure && auth_closure->pass && *auth_closure->pass) {
TRACEMSG (("NET_ResumeWithAuth: auth succeeded: %s", tmpEntry->URL_s->address));
/* now update the user/pass */
tmpEntry->URL_s->username = PL_strdup (auth_closure->user);
tmpEntry->URL_s->password = PL_strdup (auth_closure->pass);
/* now try it again */
NET_ResumeHTTP(tmpEntry, PR_TRUE);
if (tmpEntry->proto_impl->resume)
tmpEntry->proto_impl->resume (tmpEntry, auth_closure, PR_TRUE);
} else {
TRACEMSG (("NET_ResumeWithAuth(): auth failed: %s", tmpEntry->URL_s->address));
NET_ResumeHTTP(tmpEntry, PR_FALSE);
if (tmpEntry->proto_impl->resume)
tmpEntry->proto_impl->resume (tmpEntry, auth_closure, PR_FALSE);
}
/* now free the closure struct */
@ -4611,6 +4607,7 @@ net_reg_random_protocol(NET_ProtoInitFunc *LoadRoutine, int type)
random_proto_impl->init = LoadRoutine;
random_proto_impl->process = net_ProtoMainStub;
random_proto_impl->interrupt = net_ProtoMainStub;
random_proto_impl->resume = NULL; /* not usually need */
random_proto_impl->cleanup = net_ProtoCleanupStub;
NET_RegisterProtocolImplementation(random_proto_impl, type);
@ -5120,7 +5117,7 @@ int32 net_MailtoLoad (ActiveEntry * cur_entry)
if(newshost)
{
char *prefix = "news://";
char *slash = PL_strrchr (newshost, '/');
/* char *slash = PL_strrchr (newshost, '/'); -- unused */
HG32828
newspost_url = (char *) PR_Malloc (PL_strlen (prefix) +
PL_strlen (newshost) + 10);
@ -5192,6 +5189,7 @@ NET_InitMailtoProtocol(void)
mailto_proto_impl.init = net_MailtoLoad;
mailto_proto_impl.process = net_MailtoStub;
mailto_proto_impl.interrupt = net_MailtoStub;
mailto_proto_impl.resume = NULL;
mailto_proto_impl.cleanup = net_CleanupMailtoStub;
NET_RegisterProtocolImplementation(&mailto_proto_impl, MAILTO_TYPE_URL);

Просмотреть файл

@ -106,6 +106,8 @@ struct _NET_ProtoImpl {
int32 (*init) (ActiveEntry *ce);
int32 (*process) (ActiveEntry *ce);
int32 (*interrupt) (ActiveEntry *ce);
void (*resume) (ActiveEntry *ce, NET_AuthClosure *, PRBool);
/* callback to resume paused streams */
void (*cleanup) (void); /* note that cleanup can be called more
* than once, when we need to shut down
* connections or free up memory

Просмотреть файл

@ -3338,6 +3338,7 @@ NET_InitURNProtocol(void)
urn_proto_impl.init = net_URNProtoLoad;
urn_proto_impl.process = net_URNProtoStub;
urn_proto_impl.interrupt = net_URNProtoStub;
urn_proto_impl.resume = NULL;
urn_proto_impl.cleanup = net_URNProtoCleanupStub;
NET_RegisterProtocolImplementation(&urn_proto_impl, URN_TYPE_URL);
@ -3380,6 +3381,7 @@ NET_InitNFSProtocol(void)
nfs_proto_impl.init = net_NFSProtoLoad;
nfs_proto_impl.process = net_NFSProtoStub;
nfs_proto_impl.interrupt = net_NFSProtoStub;
nfs_proto_impl.resume = NULL;
nfs_proto_impl.cleanup = net_NFSProtoCleanupStub;
NET_RegisterProtocolImplementation(&nfs_proto_impl, NFS_TYPE_URL);
@ -3420,6 +3422,7 @@ NET_InitWAISProtocol(void)
wais_proto_impl.init = net_WAISProtoLoad;
wais_proto_impl.process = net_WAISProtoStub;
wais_proto_impl.interrupt = net_WAISProtoStub;
wais_proto_impl.resume = NULL;
wais_proto_impl.cleanup = net_WAISProtoCleanupStub;
NET_RegisterProtocolImplementation(&wais_proto_impl, WAIS_TYPE_URL);

Просмотреть файл

@ -401,12 +401,16 @@ PRIVATE XP_Bool _stub_PromptUsernameAndPassword(MWContext *context,
}
PRIVATE
char *stub_PromptPassword(MWContext *context,
const char *msg)
char *_stub_PromptPassword(MWContext *context,
char *msg,
XP_Bool *remember,
XP_Bool is_secure,
void *closure)
{
nsINetSupport *ins;
char *result = nsnull;
#ifndef XP_UNIX
if (nsnull != (ins = getNetSupport(context->modular_data))) {
nsAutoString str(msg);
nsAutoString res;
@ -418,20 +422,36 @@ char *stub_PromptPassword(MWContext *context,
}
/* No nsINetSupport interface... */
else {
else
#endif /* !XP_UNIX */
{
NET_AuthClosure *auth_closure = (NET_AuthClosure *) closure;
char buf[256];
printf("%s\n", msg);
printf("%cPassword: ", '\007');
fgets(buf, sizeof buf, stdin);
if (PL_strlen(buf)) {
result = PL_strdup(buf);
auth_closure->pass = PL_strdup(buf);
auth_closure->pass[strlen(buf)-1] = '\0';
NET_ResumeWithAuth (closure);
}
}
return result;
}
extern "C" char *
stub_PromptPassword(MWContext *context,
char *msg,
XP_Bool *remember,
XP_Bool is_secure,
void * closure)
{
return _stub_PromptPassword(context, msg, remember,
is_secure, closure);
}
extern "C" XP_Bool
stub_PromptUsernameAndPassword(MWContext *context,
const char *msg,

Просмотреть файл

@ -933,6 +933,7 @@ NET_InitAboutProtocol(void)
about_proto_impl.init = net_AboutLoad;
about_proto_impl.process = net_AboutStub;
about_proto_impl.interrupt = net_AboutStub;
about_proto_impl.resume = NULL;
about_proto_impl.cleanup = net_CleanupAbout;
NET_RegisterProtocolImplementation(&about_proto_impl, ABOUT_TYPE_URL);

Просмотреть файл

@ -134,6 +134,7 @@ NET_InitCertLdapProtocol(void)
certldap_proto_impl.init = net_CertLdapLoad;
certldap_proto_impl.process = net_ProcessCertLdap;
certldap_proto_impl.interrupt = net_InterruptCertLdap;
certldap_proto_impl.resume = NULL;
certldap_proto_impl.cleanup = net_CleanupCertLdap;
NET_RegisterProtocolImplementation(&certldap_proto_impl, INTERNAL_CERTLDAP_TYPE_URL);

Просмотреть файл

@ -156,6 +156,7 @@ NET_InitDataURLProtocol(void)
dataurl_proto_impl.init = net_DataURLLoad;
dataurl_proto_impl.process = net_ProcessDataURL;
dataurl_proto_impl.interrupt = net_InterruptDataURL;
dataurl_proto_impl.resume = NULL;
dataurl_proto_impl.cleanup = net_CleanupDataURL;
NET_RegisterProtocolImplementation(&dataurl_proto_impl, DATA_TYPE_URL);

Просмотреть файл

@ -1851,6 +1851,7 @@ NET_InitFileProtocol(void)
file_proto_impl.init = net_FileLoad;
file_proto_impl.process = net_ProcessFile;
file_proto_impl.interrupt = net_InterruptFile;
file_proto_impl.resume = NULL;
file_proto_impl.cleanup = net_CleanupFile;
NET_RegisterProtocolImplementation(&file_proto_impl, FILE_TYPE_URL);

Просмотреть файл

@ -154,6 +154,7 @@ typedef struct _FTPConnection {
*/
typedef enum _FTPStates {
FTP_WAIT_FOR_RESPONSE,
FTP_WAIT_FOR_AUTH,
FTP_CONTROL_CONNECT,
FTP_CONTROL_CONNECT_WAIT,
FTP_SEND_USERNAME,
@ -291,6 +292,11 @@ typedef struct _FTPConData {
/* forward decls */
static const char *pref_email_as_ftp_password = "security.email_as_ftp_password";
PRIVATE int32 net_ProcessFTP(ActiveEntry * ce);
PUBLIC PRBool stub_PromptPassword(MWContext *context,
char *prompt,
XP_Bool *remember,
XP_Bool is_secure,
void *closure);
/* function prototypes
*/
@ -3752,6 +3758,7 @@ net_parse_dir_entry (char *entry, int server_type)
} /* net_parse_dir_entry */
PRIVATE int
net_get_ftp_password(ActiveEntry *ce)
{
@ -3788,37 +3795,40 @@ net_get_ftp_password(ActiveEntry *ce)
if(!cd->password)
{
PRBool status;
NET_AuthClosure * auth_closure = PR_NEWZAP (NET_AuthClosure);
PR_snprintf(cd->output_buffer, OUTPUT_BUFFER_SIZE,
XP_GetString(XP_PROMPT_ENTER_PASSWORD),
host_string);
#if defined(SingleSignon)
cd->password = (char *)SI_PromptPassword(ce->window_id,
cd->output_buffer, host_string,
FALSE /* pickFirstUser */);
#else
cd->password = (char *)PC_PromptPassword(ce->window_id,
cd->output_buffer, &cd->store_password,
FALSE /* not secure */);
#endif
if(!cd->password)
{
PR_Free(host_string);
return(MK_INTERRUPTED); /* user canceled */
}
/* the new multi-threaded case -- we return asynchronously */
if (!auth_closure) {
return(MK_INTERRUPTED);
}
auth_closure->_private = (void *) ce;
auth_closure->user = NULL;
auth_closure->pass = NULL;
auth_closure->msg = PL_strdup (cd->output_buffer);
status = stub_PromptPassword(ce->window_id,
cd->output_buffer,
&cd->store_password,
FALSE /* not secure */,
(void *) auth_closure);
PR_Free(host_string);
/* this no longer a user cancel - password prompting is async */
return(FTP_WAIT_FOR_AUTH);
}
StrAllocCopy(ftp_last_password_host, host_string);
StrAllocCopy(ftp_last_password, cd->password);
}
PR_Free(host_string);
}
cd->next_state = FTP_SEND_PASSWORD;
return 0;
}
PRIVATE int
net_get_ftp_password_response(FTPConData *cd)
{
@ -4160,6 +4170,30 @@ net_FTPLoad (ActiveEntry * ce)
}
PUBLIC void
net_ResumeFTP(ActiveEntry *ce, NET_AuthClosure *auth_closure, PRBool resume)
{
FTPConData * cd = (FTPConData *) ce->con_data;
TRACEMSG (("net_ResumeFTP: %s", ce->URL_s->address));
if (resume) {
char * host_string = NET_ParseURL(ce->URL_s->address, (GET_USERNAME_PART | GET_HOST_PART) );
cd->password = PL_strdup (auth_closure->pass);
cd->next_state = FTP_SEND_PASSWORD;
StrAllocCopy(ftp_last_password_host, host_string);
StrAllocCopy(ftp_last_password, cd->password);
PR_Free (host_string);
} else {
cd->next_state = FTP_DONE;
}
return;
}
/* the main state machine control routine. Calls
* the individual state processors
*
@ -4178,6 +4212,10 @@ net_ProcessFTP(ActiveEntry * ce)
switch(cd->next_state) {
case FTP_WAIT_FOR_AUTH:
printf ("ProcessFTP: waiting for password\n");
break;
case FTP_WAIT_FOR_RESPONSE:
ce->status = net_ftp_response(ce);
break;
@ -4835,6 +4873,7 @@ NET_InitFTPProtocol(void)
ftp_proto_impl.init = net_FTPLoad;
ftp_proto_impl.process = net_ProcessFTP;
ftp_proto_impl.interrupt = net_InterruptFTP;
ftp_proto_impl.resume = net_ResumeFTP;
ftp_proto_impl.cleanup = net_CleanupFTP;
NET_RegisterProtocolImplementation(&ftp_proto_impl, FTP_TYPE_URL);

Просмотреть файл

@ -1169,6 +1169,7 @@ NET_InitGopherProtocol(void)
gopher_proto_impl.init = net_GopherLoad;
gopher_proto_impl.process = net_ProcessGopher;
gopher_proto_impl.interrupt = net_InterruptGopher;
gopher_proto_impl.resume = NULL;
gopher_proto_impl.cleanup = net_CleanupGopher;
NET_RegisterProtocolImplementation(&gopher_proto_impl, GOPHER_TYPE_URL);

Просмотреть файл

@ -2646,15 +2646,22 @@ net_setup_http_stream(ActiveEntry * ce) {
}
PUBLIC void
NET_ResumeHTTP(ActiveEntry * ce, PRBool resume)
net_ResumeHTTP(ActiveEntry * ce, NET_AuthClosure *auth_closure, PRBool resume)
{
HTTPConData * cd = (HTTPConData *) ce->con_data;
TRACEMSG (("NET_ResumeHTTP: %s", ce->URL_s->address));
if (resume)
if (resume) {
/* now update the user/pass */
ce->URL_s->username = PL_strdup (auth_closure->user);
ce->URL_s->password = PL_strdup (auth_closure->pass);
cd->next_state = HTTP_SETUP_STREAM;
else
} else {
cd->next_state = HTTP_DONE;
}
return;
}
@ -3887,6 +3894,7 @@ NET_InitHTTPProtocol(void)
http_proto_impl.init = net_HTTPLoad;
http_proto_impl.process = net_ProcessHTTP;
http_proto_impl.interrupt = net_InterruptHTTP;
http_proto_impl.resume = net_ResumeHTTP;
http_proto_impl.cleanup = net_CleanupHTTP;
StrAllocCopy(http_proto_impl.scheme, HTTP_SCHEME);

Просмотреть файл

@ -10283,6 +10283,7 @@ NET_InitIMAP4Protocol(void)
imap4_proto_impl.init = NET_IMAP4Load;
imap4_proto_impl.process = NET_ProcessIMAP4;
imap4_proto_impl.interrupt = NET_InterruptIMAP4;
imap4_proto_impl.resume = NULL;
imap4_proto_impl.cleanup = net_CleanupIMAP4;
NET_RegisterProtocolImplementation(&imap4_proto_impl, IMAP_TYPE_URL);

Просмотреть файл

@ -744,6 +744,7 @@ NET_InitMochaProtocol(void)
mocha_proto_impl.init = net_MochaLoad;
mocha_proto_impl.process = net_ProcessMocha;
mocha_proto_impl.interrupt = net_InterruptMocha;
mocha_proto_impl.resume = NULL;
mocha_proto_impl.cleanup = net_CleanupMocha;
NET_RegisterProtocolImplementation(&mocha_proto_impl, MOCHA_TYPE_URL);

Просмотреть файл

@ -3285,6 +3285,7 @@ NET_InitLDAPProtocol(void)
ldap_proto_impl.init = net_LoadLdap;
ldap_proto_impl.process = net_ProcessLdap;
ldap_proto_impl.interrupt = net_InterruptLdap;
ldap_proto_impl.resume = NULL;
ldap_proto_impl.cleanup = net_CleanupLdap;
NET_RegisterProtocolImplementation(&ldap_proto_impl, LDAP_TYPE_URL);

Просмотреть файл

@ -808,6 +808,7 @@ NET_InitMailboxProtocol(void)
mailbox_proto_impl.init = net_MailboxLoad;
mailbox_proto_impl.process = net_ProcessMailbox;
mailbox_proto_impl.interrupt = net_InterruptMailbox;
mailbox_proto_impl.resume = NULL;
mailbox_proto_impl.cleanup = net_CleanupMailbox;
NET_RegisterProtocolImplementation(&mailbox_proto_impl, MAILBOX_TYPE_URL);
@ -867,6 +868,7 @@ NET_InitMsgSearchProtocol(void)
msgsearch_proto_impl.init = net_MsgSearchLoad;
msgsearch_proto_impl.process = net_ProcessMsgSearch;
msgsearch_proto_impl.interrupt = net_InterruptMsgSearch;
msgsearch_proto_impl.resume = NULL;
msgsearch_proto_impl.cleanup = net_CleanupMsgSearch;
NET_RegisterProtocolImplementation(&msgsearch_proto_impl, MSG_SEARCH_TYPE_URL);

Просмотреть файл

@ -3259,6 +3259,7 @@ NET_InitPop3Protocol(void)
pop3_proto_impl.init = net_Pop3Load;
pop3_proto_impl.process = net_ProcessPop3;
pop3_proto_impl.interrupt = net_InterruptPop3;
pop3_proto_impl.resume = NULL;
pop3_proto_impl.cleanup = net_CleanupPop3;
NET_RegisterProtocolImplementation(&pop3_proto_impl, POP3_TYPE_URL);
NET_InitMailboxProtocol();
@ -3863,6 +3864,7 @@ NET_InitMailboxProtocol(void)
mbox_proto_impl.init = net_MBoxLoad;
mbox_proto_impl.process = net_ProcessMBox;
mbox_proto_impl.interrupt = net_InterruptMBox;
mbox_proto_impl.resume = NULL;
mbox_proto_impl.cleanup = net_CleanupMBox;
NET_RegisterProtocolImplementation(&mbox_proto_impl, MAILBOX_TYPE_URL);
}

Просмотреть файл

@ -172,6 +172,7 @@ NET_InitRemoteProtocol(void)
remote_proto_impl.init = NET_RemoteHostLoad;
remote_proto_impl.process = net_ProcessRemote;
remote_proto_impl.interrupt = net_InterruptRemote;
remote_proto_impl.resume = NULL;
remote_proto_impl.cleanup = net_CleanupRemote;
NET_RegisterProtocolImplementation(&remote_proto_impl, RLOGIN_TYPE_URL);

Просмотреть файл

@ -1614,6 +1614,7 @@ NET_InitMailtoProtocol(void)
mailto_proto_impl.init = net_MailtoLoad;
mailto_proto_impl.process = net_ProcessMailto;
mailto_proto_impl.interrupt = net_InterruptMailto;
mailto_proto_impl.resume = NULL;
mailto_proto_impl.cleanup = net_CleanupMailto;
NET_RegisterProtocolImplementation(&mailto_proto_impl, MAILTO_TYPE_URL);

Просмотреть файл

@ -640,6 +640,7 @@ NET_InitSockStubProtocol(void)
sockstub_proto_impl.init = net_LoadSockStub;
sockstub_proto_impl.process = net_ProcessSockStub;
sockstub_proto_impl.interrupt = net_InterruptSockStub;
sockstub_proto_impl.resume = NULL;
sockstub_proto_impl.cleanup = net_CleanupSockStub;
StrAllocCopy(sockstub_proto_impl.scheme, SOCKSTUB_SCHEME);