summaryrefslogtreecommitdiff
path: root/atari/login.c
blob: 2dc766f56b603b6242b523b7f985bab9acb0d080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright 2010 Ole Loots <ole@monochrom.net>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "desktop/401login.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <windom.h>
#include "utils/config.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "content/urldb.h"
#include "desktop/browser.h"
#include "desktop/401login.h"
#include "desktop/gui.h"
#include "utils/errors.h"
#include "utils/utils.h"
#include "utils/messages.h"
#include "utils/log.h"
#include "utils/url.h"
#include "content/urldb.h"
#include "content/fetch.h"
#include "atari/login.h"
#include "atari/res/netsurf.rsh"


extern void * h_gem_rsrc;

bool login_form_do( char * url, char * realm, char ** out )
{
	OBJECT *tree, *newtree;
	WINDOW * form;
	char user[255];
	char pass[255];
	bool bres = false;
	int res = 0;
	const char * auth;
	char * host;
	assert( url_host( url, &host) == URL_FUNC_OK );	

	if( realm == NULL ){
		realm = (char*)"Secure Area";
	}

	int len = strlen(realm) + strlen(host) + 4;
	char * title = malloc( len );
	strncpy(title, realm, len );
	strncpy(title, ": ", len-strlen(realm) );
	strncat(title, host, len-strlen(realm)+2 );
  	
	auth = urldb_get_auth_details(url, realm);
	user[0] = 0;
	pass[0] = 0;
	/*
		TODO: use auth details if available:
	if( auth == NULL ){

	} else {
		
	}*/
	
	RsrcGaddr (h_gem_rsrc , R_TREE, LOGIN, &tree);
	ObjcChange( OC_OBJC, tree, LOGIN_BT_LOGIN, 0, 0 );
	ObjcChange( OC_OBJC, tree, LOGIN_BT_ABORT, 0, 0 );
	ObjcString( tree, LOGIN_TB_USER, (char*)&user );
	ObjcString( tree,  LOGIN_TB_PASSWORD, (char*)&pass  );
	form = FormWindBegin( tree, (char *)title );
	res = -1;
	while( res != LOGIN_BT_LOGIN && res != LOGIN_BT_ABORT ){
		res = FormWindDo( MU_MESAG );
		switch( res ){
			case LOGIN_BT_LOGIN:
				bres = true;
				break;

			case LOGIN_BT_ABORT:
				bres = false;
				break;
		}
	}
	
	if( bres ) {
		*out = malloc(strlen((char*)&user) + strlen((char*)&pass) + 2 );
		strcpy(*out, (char*)&user);
		strcat(*out, ":");
		strcat(*out, (char*)&pass);
	} else {
		*out = NULL;
	}

	FormWindEnd( );
	free( title );
	return( bres );
}