aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ThirdParty/3Di/RegionMonitor/MonitorGUI/htdocs/MyCGI.pm
blob: 1f232aa392917f149e47a858e2735a2e0fcfd076 (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
package MyCGI;

use strict;
use CGI;

sub getParam {
	my $cgi;
	if ($ARGV[0]) {
		$cgi = new CGI($ARGV[0]);
	} else {
		$cgi = new CGI;
	}
	my @param_names = $cgi->param();
	my %param = ();
	foreach (@param_names) {
		$param{$_} = $cgi->param($_);
	}
	return \%param;
}

sub getCookie {
	my $name = shift;
	my $cookie_value = &CGI::cookie($name);
	return &_parse($cookie_value);
}

sub outputHtml {
	my ($charset, $html) = @_;
	print &CGI::header(-charset => $charset);
	print $html;
}

sub outputXml {
	my ($charset, $xml) = @_;
	print &CGI::header( -type => 'text/xml', -charset => $charset );
	print $xml;
}

sub makeCookieValue {
	my $param = shift;
	my @data = ();
	foreach(keys %$param) {
		push(@data, $_ . "=" . $param->{$_});
	}
	return join("&", @data);
}

sub setCookie {
	my $param = shift;
	my $cookie = &CGI::cookie(
		-name => $param->{name} || return,
		-value => $param->{value},
		-domain => $param->{domain},
		-path => $param->{path},
		-expires => $param->{expires},
	);
	return &CGI::header(-cookie => $cookie);
}

sub redirect {
	my $dest = shift;
	&CGI::redirect($dest);
}

sub urlEncode {
	my $str = shift;
	$str =~ s/([^\w ])/'%'.unpack('H2', $1)/eg;
	$str =~ tr/ /+/;
	return $str;
}

sub urlDecode {
  my $str = shift;
  $str =~ tr/+/ /;
  $str =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('H2', $1)/eg;
  return $str;
}

sub _parse {
	my $value = shift;
	my @pair = split(/&/, $value);
	my %data = ();
	foreach(@pair) {
		my ($name, $value) = split(/=/, $_);
		$data{$name} = $value;
	}
	return \%data;
}

1;