1 #include "links.h"
2 
prog_func(struct terminal * term,struct list_head * list,unsigned char * param,unsigned char * name)3 void prog_func(struct terminal *term, struct list_head *list, unsigned char *param, unsigned char *name)
4 {
5 	unsigned char *prog, *cmd;
6 	if (!(prog = get_prog(list)) || !*prog) {
7 		msg_box(term, NULL, TEXT_(T_NO_PROGRAM), AL_CENTER | AL_EXTD_TEXT, TEXT_(T_NO_PROGRAM_SPECIFIED_FOR), " ", name, ".", NULL, NULL, 1, TEXT_(T_CANCEL), NULL, B_ENTER | B_ESC);
8 		return;
9 	}
10 	if ((cmd = subst_file(prog, param, 0))) {
11 		exec_on_terminal(term, cmd, "", 1);
12 		mem_free(cmd);
13 	}
14 }
15 
mailto_func(struct session * ses,unsigned char * url)16 void mailto_func(struct session *ses, unsigned char *url)
17 {
18 	unsigned char *user, *host, *m;
19 	int f = 1;
20 	if (!(user = get_user_name(url))) goto fail;
21 	if (!(host = get_host_name(url))) goto fail1;
22 	m = mem_alloc(strlen(user) + strlen(host) + 2);
23 	f = 0;
24 	strcpy(m, user);
25 	strcat(m, "@");
26 	strcat(m, host);
27 	check_shell_security(&m);
28 	prog_func(ses->term, &mailto_prog, m, TEXT_(T_MAIL));
29 	mem_free(m);
30 	mem_free(host);
31 	fail1:
32 	mem_free(user);
33 	fail:
34 	if (f) msg_box(ses->term, NULL, TEXT_(T_BAD_URL_SYNTAX), AL_CENTER, TEXT_(T_BAD_MAILTO_URL), NULL, 1, TEXT_(T_CANCEL), NULL, B_ENTER | B_ESC);
35 }
36 
tn_func(struct session * ses,unsigned char * url,struct list_head * prog,unsigned char * t1,unsigned char * t2)37 void tn_func(struct session *ses, unsigned char *url, struct list_head *prog, unsigned char *t1, unsigned char *t2)
38 {
39 	unsigned char *m;
40 	unsigned char *h, *p;
41 	int hl, pl;
42 	unsigned char *hh, *pp;
43 	int f = 1;
44 	if (parse_url(url, NULL, NULL, NULL, NULL, NULL, &h, &hl, &p, &pl, NULL, NULL, NULL) || !hl) goto fail;
45 	hh = memacpy(h, hl);
46 	if (pl) pp = memacpy(p, pl);
47 	check_shell_security(&hh);
48 	if (pl) check_shell_security(&pp);
49 	m = mem_alloc(strlen(hh) + (pl ? strlen(pp) : 0) + 2);
50 	f = 0;
51 	strcpy(m, hh);
52 	if (pl) {
53 		strcat(m, " ");
54 		strcat(m, pp);
55 		m[hl + 1 + pl] = 0;
56 	}
57 	prog_func(ses->term, prog, m, t1);
58 	mem_free(m);
59 	if (pl) mem_free(pp);
60 	mem_free(hh);
61 	fail:
62 	if (f) msg_box(ses->term, NULL, TEXT_(T_BAD_URL_SYNTAX), AL_CENTER, t2, NULL, 1, TEXT_(T_CANCEL), NULL, B_ENTER | B_ESC);
63 }
64 
65 
telnet_func(struct session * ses,unsigned char * url)66 void telnet_func(struct session *ses, unsigned char *url)
67 {
68 	tn_func(ses, url, &telnet_prog, TEXT_(T_TELNET), TEXT_(T_BAD_TELNET_URL));
69 }
70 
tn3270_func(struct session * ses,unsigned char * url)71 void tn3270_func(struct session *ses, unsigned char *url)
72 {
73 	tn_func(ses, url, &tn3270_prog, TEXT_(T_TN3270), TEXT_(T_BAD_TN3270_URL));
74 }
75 
mms_func(struct session * ses,unsigned char * url)76 void mms_func(struct session *ses, unsigned char *url)
77 {
78 	if (check_shell_url(url)) {
79 		msg_box(ses->term, NULL, TEXT_(T_MMS_URL_CONTAINS_INACCEPTABLE_CHARACTERS), AL_CENTER, TEXT_(T_MMS), NULL, 1, TEXT_(T_CANCEL), NULL, B_ENTER | B_ESC);
80 		return;
81 	}
82 	prog_func(ses->term, &mms_prog, url, TEXT_(T_MMS));
83 }
84