[Home] [Help]
PACKAGE BODY: OWAPUB.OWA_COOKIE
Source
1 package body OWA_COOKIE is
2
3 cookie_names vc_arr;
4 cookie_vals vc_arr;
5 cookie_num_vals integer;
6
7 cookies_parsed boolean;
8
9 function IFNOTNULL(val1 in varchar2,
10 val2 in varchar2) return varchar2 is
11 begin
12 if (val1 is not null)
13 then
14 return val2;
15 else
16 return NULL;
17 end if;
18 end;
19
20 procedure http_cookie2array(names out vc_arr,
21 vals out vc_arr,
22 num_vals out integer) is
23 http_cookie varchar2(32767);
24
25 start_loc integer;
26 end_loc integer;
27 equal_sign integer;
28
29 val_counter integer;
30 begin
31 http_cookie := owa_util.get_cgi_env('HTTP_COOKIE');
32
33 val_counter := 0;
34
35 /* If the last character is a ';', trim it out */
36 if (substr(http_cookie, -1) = ';')
37 then
38 http_cookie := substr(http_cookie, 1, length(http_cookie)-1);
39 end if;
40
41 if (http_cookie is not NULL)
42 then
43 start_loc := 1;
44 end_loc := instr(http_cookie, ';', start_loc);
45 while (end_loc != 0)
46 loop
47 val_counter := val_counter+1;
48 equal_sign := instr(http_cookie, '=', start_loc);
49 names(val_counter) := ltrim(substr(http_cookie, start_loc,
50 equal_sign-start_loc));
51 vals(val_counter) := substr(http_cookie, equal_sign+1,
52 end_loc - equal_sign - 1);
53
54 start_loc := end_loc + 1;
55 end_loc := instr(http_cookie, ';', start_loc);
56 end loop;
57
58 val_counter := val_counter + 1;
59 equal_sign := instr(http_cookie, '=', start_loc);
60 names(val_counter) := ltrim(substr(http_cookie, start_loc,
61 equal_sign-start_loc));
62 vals(val_counter) := substr(http_cookie, equal_sign+1);
63 end if;
64
65 num_vals := val_counter;
66 end;
67
68 procedure send(name in varchar2,
69 value in varchar2,
70 expires in date DEFAULT NULL,
71 path in varchar2 DEFAULT NULL,
72 domain in varchar2 DEFAULT NULL,
73 secure in varchar2 DEFAULT NULL) is
74 expires_gmt date;
75 begin
76 if (OWA_CUSTOM.DBMS_SERVER_GMTDIFF is not NULL)
77 then
78 expires_gmt := expires-(OWA_CUSTOM.DBMS_SERVER_GMTDIFF/24);
79 else
80 expires_gmt := new_time(expires,OWA_CUSTOM.DBMS_SERVER_TIMEZONE,'GMT');
81 end if;
82
83 htp.print('Set-Cookie: '||name||'='||value||';'||
84 IFNOTNULL(expires_gmt, ' expires='||
85 rtrim(to_char(expires_gmt,'Day'))||
86 to_char(expires_gmt,', DD-Mon-YYYY HH24:MI:SS')||' GMT;')||
87 IFNOTNULL(path, ' path='||path||';')||
88 IFNOTNULL(domain, ' domain='||domain||';')||
89 IFNOTNULL(secure, ' secure'));
90 end;
91
92 function make_cookie(name in varchar2 DEFAULT NULL) return cookie is
93 choc_chip cookie;
94 begin
95 choc_chip.num_vals := 0;
96 choc_chip.name := name;
97
98 return choc_chip;
99 end;
100
101 function get(name in varchar2) return cookie is
102 choc_chip cookie;
103 begin
104 if (NOT cookies_parsed)
105 then
106 http_cookie2array(cookie_names, cookie_vals, cookie_num_vals);
107 cookies_parsed := TRUE;
108 end if;
109
110 choc_chip := make_cookie(name);
111
112 /* This is not the most efficient thing to do. */
113 /* should probably have cookie2array sort */
114 /* then we could do binary search here. */
115 for i in 1..cookie_num_vals
116 loop
117 if (cookie_names(i) = name)
118 then
119 choc_chip.num_vals := choc_chip.num_vals + 1;
120 choc_chip.vals(choc_chip.num_vals) := cookie_vals(i);
121 end if;
122 end loop;
123
124 return choc_chip;
125 end;
126
127 procedure remove(name in varchar2,
128 val in varchar2,
129 path in varchar2 DEFAULT NULL) is
130 begin
131 send(name, val, to_date('01-JAN-1990','DD-MON-YYYY'));
132 end;
133
134 procedure get_all(names out vc_arr,
135 vals out vc_arr,
136 num_vals out integer) is
137 begin
138 if (NOT cookies_parsed)
139 then
140 http_cookie2array(cookie_names, cookie_vals, cookie_num_vals);
141 cookies_parsed := TRUE;
142 end if;
143 names := cookie_names;
144 vals := cookie_vals;
145 num_vals := cookie_num_vals;
146 end;
147 begin
148 cookies_parsed := FALSE;
149 end;