aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/OpenJpeg/bio.cs138
-rw-r--r--OpenSim/Framework/OpenJpeg/fix.cs16
-rw-r--r--OpenSim/Framework/OpenJpeg/int_.cs58
-rw-r--r--OpenSim/Framework/OpenJpeg/j2k.cs158
-rw-r--r--OpenSim/Framework/OpenJpeg/openjpeg.cs358
-rw-r--r--OpenSim/Framework/OpenJpeg/pi.cs48
-rw-r--r--OpenSim/Grid/UserServer/Main.cs6
-rw-r--r--OpenSim/Grid/UserServer/OpenIdService.cs339
-rw-r--r--ThirdPartyLicenses/DotNetOpenid.txt10
-rw-r--r--bin/DotNetOpenId.dllbin0 -> 281088 bytes
-rw-r--r--prebuild.xml2
11 files changed, 1133 insertions, 0 deletions
diff --git a/OpenSim/Framework/OpenJpeg/bio.cs b/OpenSim/Framework/OpenJpeg/bio.cs
new file mode 100644
index 0000000..4f095ad
--- /dev/null
+++ b/OpenSim/Framework/OpenJpeg/bio.cs
@@ -0,0 +1,138 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework.OpenJpeg
6{
7 public static class bio
8 {
9
10 public static opj_bio bio_create()
11 {
12 opj_bio bio = new opj_bio();
13 return bio;
14 }
15
16 public static void bio_destroy(opj_bio bio)
17 {
18 // not needed on C#
19 }
20
21 public static int bio_numbytes(opj_bio bio)
22 {
23 return (bio.bp - bio.start);
24 }
25
26 public static void bio_init_enc(opj_bio bio, sbyte bp, int len)
27 {
28 bio.start = (byte)bp;
29 bio.end = (byte)(bp + (byte)len);
30 bio.bp = (byte)bp;
31 bio.buf = 0;
32 bio.ct = 8;
33 }
34
35 public static void bio_init_dec(opj_bio bio, sbyte bp, int len)
36 {
37 bio.start = (byte)bp;
38 bio.end = (byte)(bp + len);
39 bio.bp = (byte)bp;
40 bio.buf = 0;
41 bio.ct = 0;
42 }
43
44 public static void bio_write(opj_bio bio, int v, int n)
45 {
46 for (int i = n - 1; i >= 0; i--)
47 bio_putbit(bio, (v >> i) & 1);
48 }
49
50 public static int bio_read(opj_bio bio, int n)
51 {
52 int v = 0;
53 for (int i = n - 1; i >= 0; i--)
54 v += bio_getbit(bio) << i;
55
56 return v;
57 }
58
59 public static int bio_flush(opj_bio bio)
60 {
61 bio.ct = 0;
62 if (bio_byteout(bio) != 0)
63 return 1;
64
65 if (bio.ct == 7)
66 {
67 bio.ct = 0;
68 if (bio_byteout(bio) != 0)
69 return 1;
70 }
71 return 0;
72 }
73
74 public static int bio_inalign(opj_bio bio)
75 {
76 bio.ct = 0;
77 if ((bio.buf & 0xff) == 0xff)
78 {
79 if (bio_bytein(bio) != 0)
80 return 1;
81 bio.ct = 0;
82 }
83 return 0;
84 }
85
86 private static int bio_bytein(opj_bio bio)
87 {
88 bio.buf = (bio.buf << 8) & 0xffff;
89 bio.ct = bio.buf == 0xff00 ? 7 : 8;
90 if (bio.bp >= bio.end)
91 return 1;
92 bio.buf |= bio.bp++;
93
94 return 0;
95 }
96
97 private static int bio_byteout(opj_bio bio)
98 {
99 bio.buf = (bio.buf << 8) & 0xffff;
100 bio.ct = bio.buf == 0xff00 ? 7 : 8;
101 if (bio.bp >= bio.end)
102 return 1;
103
104 bio.bp = (byte)(bio.buf >> 8);
105 bio.bp++;
106 return 0;
107 }
108
109 private static void bio_putbit(opj_bio bio, int b)
110 {
111 if (bio.ct == 0)
112 bio_byteout(bio);
113
114 bio.ct--;
115 bio.buf |= (byte)(b << bio.ct);
116
117 }
118
119 private static int bio_getbit(opj_bio bio)
120 {
121 if (bio.ct == 0)
122 bio_bytein(bio);
123 bio.ct--;
124
125 return (int)((bio.buf >> bio.ct) & 1);
126 }
127
128 }
129
130 public struct opj_bio
131 {
132 public byte start;
133 public byte end;
134 public byte bp;
135 public uint buf;
136 public int ct;
137 }
138}
diff --git a/OpenSim/Framework/OpenJpeg/fix.cs b/OpenSim/Framework/OpenJpeg/fix.cs
new file mode 100644
index 0000000..76d3159
--- /dev/null
+++ b/OpenSim/Framework/OpenJpeg/fix.cs
@@ -0,0 +1,16 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework.OpenJpeg
6{
7 public static class fix
8 {
9 public static int fix_mul(int a, int b)
10 {
11 long temp = (long)a * (long)b;
12 temp += temp & 4096;
13 return (int)(temp >> 13);
14 }
15 }
16}
diff --git a/OpenSim/Framework/OpenJpeg/int_.cs b/OpenSim/Framework/OpenJpeg/int_.cs
new file mode 100644
index 0000000..dc71728
--- /dev/null
+++ b/OpenSim/Framework/OpenJpeg/int_.cs
@@ -0,0 +1,58 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework.OpenJpeg
6{
7 public static class int_
8 {
9 public static int int_min(int a, int b)
10 {
11 return a < b ? a : b;
12 }
13
14 public static int int_max(int a, int b)
15 {
16 return (a > b) ? a : b;
17 }
18
19 public static int int_clamp(int a, int min, int max)
20 {
21 if (a < min)
22 return min;
23 if (a > max)
24 return max;
25
26 return a;
27 }
28
29 public static int int_abs(int a)
30 {
31 return a < 0 ? -a : a;
32 }
33
34 public static int int_ceildiv(int a, int b)
35 {
36 return (a + b - 1) / b;
37 }
38
39 public static int int_ceildivpow2(int a, int b)
40 {
41 return (a + (1 << b) - 1) >> b;
42 }
43
44 public static int int_floordivpow2(int a, int b)
45 {
46 return a >> b;
47 }
48
49 public static int int_floorlog2(int a)
50 {
51 for (int l=0; a > 1; l++)
52 a >>= 1;
53
54 return 1;
55 }
56
57 }
58}
diff --git a/OpenSim/Framework/OpenJpeg/j2k.cs b/OpenSim/Framework/OpenJpeg/j2k.cs
new file mode 100644
index 0000000..f655364
--- /dev/null
+++ b/OpenSim/Framework/OpenJpeg/j2k.cs
@@ -0,0 +1,158 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework.OpenJpeg
6{
7
8 public static class j2k
9 {
10 }
11
12 public enum J2K_STATUS
13 {
14 J2K_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */
15 J2K_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */
16 J2K_STATE_MH = 0x0004, /**< the decoding process is in the main header */
17 J2K_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */
18 J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */
19 J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */
20 J2K_STATE_NEOC = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */
21 J2K_STATE_ERR = 0x0080 /**< the decoding process has encountered an error */
22 }
23
24 public enum J2K_T2_MODE
25 {
26 THRESH_CALC = 0, /** Function called in Rate allocation process*/
27 FINAL_PASS = 1 /** Function called in Tier 2 process*/
28 }
29
30 public struct opj_stepsize
31 {
32 public int expn;
33 public int mant;
34 }
35
36 public struct opj_tccp
37 {
38 public int csty;
39 public int numresolutions;
40 public int cblkw;
41 public int cblkh;
42 public int cblksty;
43 public int qmfbid;
44 public int qntsty;
45 /// <summary>
46 /// don't forget to initialize 97 elements
47 /// </summary>
48 public opj_stepsize[] stepsizes;
49 public int numgbits;
50 public int roishift;
51 /// <summary>
52 /// Don't forget to initialize 33 elements
53 /// </summary>
54 public int[] prcw;
55
56 }
57
58 public struct opj_tcp
59 {
60 public int first;
61 public int csty;
62 public PROG_ORDER prg;
63 public int numlayers;
64 public int mct;
65 /// <summary>
66 /// don't forget to initialize to 100
67 /// </summary>
68 public float[] rates;
69 public int numpocs;
70 public int POC;
71 /// <summary>
72 /// Don't forget to initialize to 32
73 /// </summary>
74 public opj_poc[] pocs;
75 public byte ppt_data;
76 public byte ppt_data_first;
77 public int ppt;
78 public int ppt_store;
79 public int ppt_len;
80 /// <summary>
81 /// Don't forget to initialize 100 elements
82 /// </summary>
83 public float[] distoratio;
84 public opj_tccp tccps;
85
86 }
87
88 public struct opj_cp
89 {
90 public CINEMA_MODE cinema;
91 public int max_comp_size;
92 public int img_size;
93 public RSIZ_CAPABILITIES rsiz;
94 public sbyte tp_on;
95 public sbyte tp_flag;
96 public int tp_pos;
97 public int distro_alloc;
98 public int fixed_alloc;
99 public int fixed_quality;
100 public int reduce;
101 public int layer;
102 public LIMIT_DECODING limit_decoding;
103 public int tx0;
104 public int ty0;
105 public int tdx;
106 public int tdy;
107 public sbyte? comment;
108 public int tw;
109 public int th;
110 public int? tileno;
111 public byte ppm_data;
112 public byte ppm_data_first;
113 public int ppm;
114 public int ppm_store;
115 public int ppm_previous;
116 public int ppm_len;
117 public opj_tcp tcps;
118 public int matrice;
119 }
120
121 public static class j2kdefines
122 {
123 public const uint J2K_CP_CSTY_PRT = 0x01;
124 public const uint J2K_CP_CSTY_SOP = 0x02;
125 public const uint J2K_CP_CSTY_EPH = 0x04;
126 public const uint J2K_CCP_CSTY_PRT = 0x01;
127 public const uint J2K_CCP_CBLKSTY_LAZY = 0x01;
128 public const uint J2K_CCP_CBLKSTY_RESET = 0x02;
129 public const uint J2K_CCP_CBLKSTY_TERMALL = 0x04;
130 public const uint J2K_CCP_CBLKSTY_VSC = 0x08;
131 public const uint J2K_CCP_CBLKSTY_PTERM =0x10;
132 public const uint J2K_CCP_CBLKSTY_SEGSYM = 0x20;
133 public const uint J2K_CCP_QNTSTY_NOQNT = 0;
134 public const uint J2K_CCP_QNTSTY_SIQNT = 1;
135 public const uint J2K_CCP_QNTSTY_SEQNT = 2;
136
137 public const uint J2K_MS_SOC = 0xff4f; /**< SOC marker value */
138 public const uint J2K_MS_SOT = 0xff90; /**< SOT marker value */
139 public const uint J2K_MS_SOD = 0xff93; /**< SOD marker value */
140 public const uint J2K_MS_EOC = 0xffd9; /**< EOC marker value */
141 public const uint J2K_MS_SIZ = 0xff51; /**< SIZ marker value */
142 public const uint J2K_MS_COD = 0xff52; /**< COD marker value */
143 public const uint J2K_MS_COC = 0xff53; /**< COC marker value */
144 public const uint J2K_MS_RGN = 0xff5e; /**< RGN marker value */
145 public const uint J2K_MS_QCD = 0xff5c; /**< QCD marker value */
146 public const uint J2K_MS_QCC = 0xff5d; /**< QCC marker value */
147 public const uint J2K_MS_POC = 0xff5f; /**< POC marker value */
148 public const uint J2K_MS_TLM = 0xff55; /**< TLM marker value */
149 public const uint J2K_MS_PLM = 0xff57; /**< PLM marker value */
150 public const uint J2K_MS_PLT = 0xff58; /**< PLT marker value */
151 public const uint J2K_MS_PPM = 0xff60; /**< PPM marker value */
152 public const uint J2K_MS_PPT = 0xff61; /**< PPT marker value */
153 public const uint J2K_MS_SOP = 0xff91; /**< SOP marker value */
154 public const uint J2K_MS_EPH = 0xff92; /**< EPH marker value */
155 public const uint J2K_MS_CRG = 0xff63; /**< CRG marker value */
156 public const uint J2K_MS_COM = 0xff64; /**< COM marker value */
157 }
158}
diff --git a/OpenSim/Framework/OpenJpeg/openjpeg.cs b/OpenSim/Framework/OpenJpeg/openjpeg.cs
new file mode 100644
index 0000000..2d5e4b5
--- /dev/null
+++ b/OpenSim/Framework/OpenJpeg/openjpeg.cs
@@ -0,0 +1,358 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework.OpenJpeg
6{
7 public class openjpeg
8 {
9 public openjpeg()
10 {
11
12
13 }
14 }
15
16 public enum PROG_ORDER
17 {
18 PROG_UNKNOWN = -1,
19 LRCP = 0,
20 RLCP = 1,
21 RPCL = 2,
22 PCRL = 3,
23 CPRL = 4
24 }
25
26 public enum RSIZ_CAPABILITIES
27 {
28 STD_RSIZ = 0,
29 CINEMA2K = 3,
30 CINEMA4K = 4
31 }
32
33 public enum CINEMA_MODE
34 {
35 OFF = 0,
36 CINEMA2K_24 = 1,
37 CINEMA2K_48 = 2,
38 CINEMA4K_24 = 3
39 }
40
41 public enum COLOR_SPACE
42 {
43 CLRSPC_UNKNOWN = -1,
44 CLRSPC_SRGB = 1,
45 CLRSPC_GRAY = 2,
46 CLRSPC_SYCC = 3
47 }
48
49 public enum CODEC_FORMAT
50 {
51 CODEC_UNKNOWN = -1,
52 CODEC_J2K = 0,
53 CODEC_JPT = 1,
54 CODEC_JP2 = 2
55 }
56
57 public enum LIMIT_DECODING
58 {
59 NO_LIMITATION = 0,
60 LIMIT_TO_MAIN_HEADER=1,
61 DECODE_ALL_BUT_PACKETS = 2
62 }
63
64 public struct opj_poc
65 {
66 public int resno0, compno0;
67 public int layno1, resno1, compno1;
68 public int layno0, precno0, precno1;
69 public PROG_ORDER prg1, prg;
70 /// <summary>
71 /// Don't forget to initialize with 5 elements
72 /// </summary>
73 public sbyte[] progorder;
74 public int tile;
75 public int tx0, tx1, ty0, ty1;
76 public int layS, resS, copmS, prcS;
77 public int layE, resE, compE, prcE;
78 public int txS, txE, tyS, tyE, dx, dy;
79 public int lay_t, res_t, comp_t, prc_t, tx0_t, ty0_t;
80 }
81
82 public struct opj_cparameters
83 {
84 public bool tile_size_on;
85 public int cp_tx0;
86 public int cp_ty0;
87 public int cp_tdx;
88 public int cp_tdy;
89 public int cp_disto_alloc;
90 public int cp_fixed_alloc;
91 public int cp_fixed_wuality;
92 public int cp_matrice;
93 public sbyte cp_comment;
94 public int csty;
95 public PROG_ORDER prog_order;
96
97 /// <summary>
98 /// Don't forget to initialize 32 elements
99 /// </summary>
100 public opj_poc[] POC;
101 public int numpocs;
102 public int tcp_numlayers;
103 /// <summary>
104 /// Don't forget to intitialize 100 elements
105 /// </summary>
106 public float[] tcp_rates;
107 /// <summary>
108 /// Don't forget to initialize 100 elements
109 /// </summary>
110 public float[] tcp_distoratio;
111 public int numresolution;
112 public int cblockw_init;
113 public int cblockh_init;
114 public int mode;
115 public int irreversible;
116 public int roi_compno;
117 public int roi_shift;
118 public int res_spec;
119
120 /// <summary>
121 /// Don't forget to initialize 33 elements
122 /// </summary>
123 public int[] prc_init;
124 /// <summary>
125 /// Don't forget to initialize 33 elements
126 /// </summary>
127 public int[] prch_init;
128
129 public string infile;
130 public string outfile;
131 public int index_on;
132 public string index;
133 public int image_offset_x0;
134 public int image_offset_y0;
135 public int subsampling_dx;
136 public int subsampling_dy;
137 public int decod_format;
138 public int cod_format;
139 public bool jpwl_epc_on;
140 public int jpwl_hprot_MH;
141 /// <summary>
142 /// Don't forget to initialize 16 elements
143 /// </summary>
144 public int[] jpwl_hprot_TPH_tileno;
145 /// <summary>
146 /// Don't forget to initialize 16 elements
147 /// </summary>
148 public int[] jpwl_hprot_TPH;
149
150 /// <summary>
151 /// Don't forget to initialize 16 elements
152 /// </summary>
153 public int[] jpwl_pprot_tileno;
154 public int[] jpwl_pprot_packno;
155 public int[] jpwl_pprot;
156 public int jpwl_sens_size;
157 public int jpwl_sense_addr;
158 public int jpwl_sens_range;
159 public int jpwl_sens_MH;
160
161 /// <summary>
162 /// Don't forget to initialize 16 elements
163 /// </summary>
164 public int[] jpwl_sens_TPH_tileno;
165
166 /// <summary>
167 /// Don't forget to initialize 16 elements
168 /// </summary>
169 public int[] jpwl_sens_TPH;
170 public CINEMA_MODE cp_cinema;
171 public int max_comp_size;
172 public sbyte tp_on;
173 public sbyte tp_flag;
174 public sbyte tcp_mct;
175 }
176
177 public struct opj_dparameters
178 {
179 public int cp_reduce;
180 public int cp_layer;
181 public string infile;
182 public string outfile;
183 public int decod_format;
184 public int cod_format;
185 public bool jpwl_correct;
186 public int jpwl_exp_comps;
187 public int jpwl_max_tiles;
188 public LIMIT_DECODING cp_limit_decoding;
189
190 }
191
192 public struct opj_common_fields
193 {
194 public bool is_decompressor;
195 public CODEC_FORMAT codec_format;
196 }
197
198 public struct opj_common_struct
199 {
200 public opj_common_fields flds;
201 }
202
203 public struct opj_cinfo
204 {
205 public opj_common_fields flds;
206 }
207 public struct opj_dinfo
208 {
209 public opj_common_fields flds;
210 }
211
212 public struct opj_cio
213 {
214 public opj_common_struct cinfo;
215 public int openmode;
216 public byte buffer;
217 public int length;
218 public byte start;
219 public byte end;
220 public byte bp;
221 }
222
223 public struct opj_image_comp
224 {
225 public int dx;
226 public int dy;
227 public int w;
228 public int h;
229 public int x0;
230 public int y0;
231 public int prec;
232 public int bpp;
233 public int sgnd;
234 public int resno_decoded;
235 public int factor;
236 public int data;
237 }
238
239 public struct opj_image
240 {
241 public int x0;
242 public int y0;
243 public int x1;
244 public int y1;
245 public int numcomps;
246 public COLOR_SPACE color_space;
247 public opj_image_comp comps;
248 }
249
250 public struct opj_image_comptparm
251 {
252 public int dx;
253 public int dy;
254 public int w;
255 public int h;
256 public int x0;
257 public int y0;
258 public int prec;
259 public int bpp;
260 public int sgnd;
261 }
262
263 public struct opj_packet_info
264 {
265 public int start_pos;
266 public int end_ph_pos;
267 public int end_pos;
268 public double disto;
269 }
270
271 public struct opj_tp_info
272 {
273 public int tp_start_pos;
274 public int tp_end_header;
275 public int tp_end_pos;
276 public int tp_start_pack;
277 public int tp_numpacks;
278 }
279
280 public struct opj_tile_info
281 {
282 public double thresh;
283 public int tileno;
284 public int start_pos;
285 public int end_header;
286 public int end_pos;
287 /// <summary>
288 /// Don't forget to initialize 33 elements
289 /// </summary>
290 public int[] pw;
291 /// <summary>
292 /// Don't forget to initialize 33 elements
293 /// </summary>
294 public int[] ph;
295 /// <summary>
296 /// Don't forget to initialize 33 elements
297 /// </summary>
298 public int[] pdx;
299 /// <summary>
300 /// Don't forget to initialize 33 elements
301 /// </summary>
302 public int[] pdy;
303
304 public opj_packet_info packet;
305 public int numpix;
306 public double distotile;
307 public int num_tps;
308 public opj_tp_info tp;
309 }
310
311 public struct opj_marker_info_t
312 {
313 public ushort type;
314 public int pos;
315 public int len;
316 }
317
318 public struct opj_codestream_info
319 {
320 public double D_max;
321 public int packno;
322 public int index_write;
323 public int image_w;
324 public int image_h;
325
326 public PROG_ORDER prog;
327
328 public int tile_x;
329 public int tile_y;
330 public int tile_Ox;
331 public int tile_Oy;
332 public int tw;
333 public int numcomps;
334 public int numlayers;
335 public int numdecompos;
336 public int marknum;
337 public opj_marker_info_t marker;
338 public int maxmarknum;
339 public int main_head_start;
340 public int main_head_end;
341 public int codestream_size;
342 public opj_tile_info tile;
343
344 }
345
346
347
348
349
350
351 public static class opj_defines
352 {
353 public const int OPJ_STREAM_READ = 0x0001;
354 public const int OPJ_STREAM_WRITE = 0x0002;
355
356 }
357
358}
diff --git a/OpenSim/Framework/OpenJpeg/pi.cs b/OpenSim/Framework/OpenJpeg/pi.cs
new file mode 100644
index 0000000..f7e211f
--- /dev/null
+++ b/OpenSim/Framework/OpenJpeg/pi.cs
@@ -0,0 +1,48 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Framework.OpenJpeg
6{
7 public static class pi
8 {
9 }
10
11 public struct opj_pi_resolution
12 {
13 public int pdx, pdy;
14 public int pw, ph;
15 }
16
17 public struct opj_pi_comp
18 {
19 public int dx, dy;
20 public int numresolutions;
21 public opj_pi_resolution resolutions;
22 }
23
24 public struct obj_pi_iterator
25 {
26 public sbyte tp_on;
27 public short include;
28 public int step_l;
29 public int step_r;
30 public int step_c;
31 public int step_p;
32 public int compno;
33 public int resno;
34 public int precno;
35 public int layno;
36 public int first;
37 public opj_poc poc;
38 public int numcomps;
39 public opj_pi_comp comps;
40
41 public int tx0, ty0, tx1, ty1;
42 public int x, y, dx, dy;
43 }
44
45
46
47
48}
diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs
index a001a6f..f688e4c 100644
--- a/OpenSim/Grid/UserServer/Main.cs
+++ b/OpenSim/Grid/UserServer/Main.cs
@@ -187,6 +187,12 @@ namespace OpenSim.Grid.UserServer
187 new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod)); 187 new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod));
188 188
189 m_httpServer.AddXmlRPCHandler("update_user_profile", m_userManager.XmlRpcResponseXmlRPCUpdateUserProfile); 189 m_httpServer.AddXmlRPCHandler("update_user_profile", m_userManager.XmlRpcResponseXmlRPCUpdateUserProfile);
190
191 // Handler for OpenID avatar identity pages
192 m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/users/", m_loginService));
193 // Handlers for the OpenID endpoint server
194 m_httpServer.AddStreamHandler(new OpenIdStreamHandler("POST", "/openid/server/", m_loginService));
195 m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", m_loginService));
190 } 196 }
191 197
192 public void do_create(string[] args) 198 public void do_create(string[] args)
diff --git a/OpenSim/Grid/UserServer/OpenIdService.cs b/OpenSim/Grid/UserServer/OpenIdService.cs
new file mode 100644
index 0000000..695968f
--- /dev/null
+++ b/OpenSim/Grid/UserServer/OpenIdService.cs
@@ -0,0 +1,339 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Collections.Specialized;
31using System.IO;
32using System.Net;
33using System.Web;
34using System.Text;
35using DotNetOpenId;
36using DotNetOpenId.Provider;
37using log4net;
38using OpenSim.Framework;
39using OpenSim.Framework.Servers;
40
41namespace OpenSim.Grid.UserServer
42{
43 /// <summary>
44 /// Temporary, in-memory store for OpenID associations
45 /// </summary>
46 public class ProviderMemoryStore : IAssociationStore<AssociationRelyingPartyType>
47 {
48 private class AssociationItem
49 {
50 public AssociationRelyingPartyType DistinguishingFactor;
51 public string Handle;
52 public DateTime Expires;
53 public byte[] PrivateData;
54 }
55
56 Dictionary<string, AssociationItem> m_store = new Dictionary<string, AssociationItem>();
57 SortedList<DateTime, AssociationItem> m_sortedStore = new SortedList<DateTime, AssociationItem>();
58 object m_syncRoot = new object();
59
60 #region IAssociationStore<AssociationRelyingPartyType> Members
61
62 public void StoreAssociation(AssociationRelyingPartyType distinguishingFactor, Association assoc)
63 {
64 AssociationItem item = new AssociationItem();
65 item.DistinguishingFactor = distinguishingFactor;
66 item.Handle = assoc.Handle;
67 item.Expires = assoc.Expires.ToLocalTime();
68 item.PrivateData = assoc.SerializePrivateData();
69
70 lock (m_syncRoot)
71 {
72 m_store[item.Handle] = item;
73 m_sortedStore[item.Expires] = item;
74 }
75 }
76
77 public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor)
78 {
79 lock (m_syncRoot)
80 {
81 if (m_sortedStore.Count > 0)
82 {
83 AssociationItem item = m_sortedStore.Values[m_sortedStore.Count - 1];
84 return Association.Deserialize(item.Handle, item.Expires.ToUniversalTime(), item.PrivateData);
85 }
86 else
87 {
88 return null;
89 }
90 }
91 }
92
93 public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor, string handle)
94 {
95 AssociationItem item;
96 bool success = false;
97 lock (m_syncRoot)
98 success = m_store.TryGetValue(handle, out item);
99
100 if (success)
101 return Association.Deserialize(item.Handle, item.Expires.ToUniversalTime(), item.PrivateData);
102 else
103 return null;
104 }
105
106 public bool RemoveAssociation(AssociationRelyingPartyType distinguishingFactor, string handle)
107 {
108 lock (m_syncRoot)
109 {
110 for (int i = 0; i < m_sortedStore.Values.Count; i++)
111 {
112 AssociationItem item = m_sortedStore.Values[i];
113 if (item.Handle == handle)
114 {
115 m_sortedStore.RemoveAt(i);
116 break;
117 }
118 }
119
120 return m_store.Remove(handle);
121 }
122 }
123
124 public void ClearExpiredAssociations()
125 {
126 lock (m_syncRoot)
127 {
128 List<AssociationItem> itemsCopy = new List<AssociationItem>(m_sortedStore.Values);
129 DateTime now = DateTime.Now;
130
131 for (int i = 0; i < itemsCopy.Count; i++)
132 {
133 AssociationItem item = itemsCopy[i];
134
135 if (item.Expires <= now)
136 {
137 m_sortedStore.RemoveAt(i);
138 m_store.Remove(item.Handle);
139 }
140 }
141 }
142 }
143
144 #endregion
145 }
146
147 public class OpenIdStreamHandler : IStreamHandler
148 {
149 #region HTML
150
151 /// <summary>Login form used to authenticate OpenID requests</summary>
152 const string LOGIN_PAGE =
153@"<html>
154<head><title>OpenSim OpenID Login</title></head>
155<body>
156<h3>OpenSim Login</h3>
157<form method=""post"">
158<label for=""first"">First Name:</label> <input readonly type=""text"" name=""first"" id=""first"" value=""{0}""/>
159<label for=""last"">Last Name:</label> <input readonly type=""text"" name=""last"" id=""last"" value=""{1}""/>
160<label for=""pass"">Password:</label> <input type=""password"" name=""pass"" id=""pass""/>
161<input type=""submit"" value=""Login"">
162</form>
163</body>
164</html>";
165
166 /// <summary>Page shown for a valid OpenID identity</summary>
167 const string OPENID_PAGE =
168@"<html>
169<head>
170<title>{2} {3}</title>
171<link rel=""openid2.provider openid.server"" href=""{0}://{1}/openid/server/""/>
172</head>
173<body>OpenID identifier for {2} {3}</body>
174</html>
175";
176
177 /// <summary>Page shown for an invalid OpenID identity</summary>
178 const string INVALID_OPENID_PAGE =
179@"<html><head><title>Identity not found</title></head>
180<body>Invalid OpenID identity</body></html>";
181
182 /// <summary>Page shown if the OpenID endpoint is requested directly</summary>
183 const string ENDPOINT_PAGE =
184@"<html><head><title>OpenID Endpoint</title></head><body>
185This is an OpenID server endpoint, not a human-readable resource.
186For more information, see <a href='http://openid.net/'>http://openid.net/</a>.
187</body></html>";
188
189 #endregion HTML
190
191 public string ContentType { get { return m_contentType; } }
192 public string HttpMethod { get { return m_httpMethod; } }
193 public string Path { get { return m_path; } }
194
195 string m_contentType;
196 string m_httpMethod;
197 string m_path;
198 UserLoginService m_loginService;
199 ProviderMemoryStore m_openidStore = new ProviderMemoryStore();
200
201 /// <summary>
202 /// Constructor
203 /// </summary>
204 public OpenIdStreamHandler(string httpMethod, string path, UserLoginService loginService)
205 {
206 m_loginService = loginService;
207 m_httpMethod = httpMethod;
208 m_path = path;
209
210 m_contentType = "text/html";
211 }
212
213 /// <summary>
214 /// Handles all GET and POST requests for OpenID identifier pages and endpoint
215 /// server communication
216 /// </summary>
217 public void Handle(string path, Stream request, Stream response, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
218 {
219 Uri providerEndpoint = new Uri(String.Format("{0}://{1}{2}", httpRequest.Url.Scheme, httpRequest.Url.Authority, httpRequest.Url.AbsolutePath));
220
221 // Defult to returning HTML content
222 m_contentType = "text/html";
223
224 try
225 {
226 NameValueCollection postQuery = HttpUtility.ParseQueryString(new StreamReader(httpRequest.InputStream).ReadToEnd());
227 NameValueCollection getQuery = HttpUtility.ParseQueryString(httpRequest.Url.Query);
228 NameValueCollection openIdQuery = (postQuery.GetValues("openid.mode") != null ? postQuery : getQuery);
229
230 OpenIdProvider provider = new OpenIdProvider(m_openidStore, providerEndpoint, httpRequest.Url, openIdQuery);
231
232 if (provider.Request != null)
233 {
234 if (!provider.Request.IsResponseReady && provider.Request is IAuthenticationRequest)
235 {
236 IAuthenticationRequest authRequest = (IAuthenticationRequest)provider.Request;
237 string[] passwordValues = postQuery.GetValues("pass");
238
239 UserProfileData profile;
240 if (TryGetProfile(new Uri(authRequest.ClaimedIdentifier.ToString()), out profile))
241 {
242 // Check for form POST data
243 if (passwordValues != null && passwordValues.Length == 1)
244 {
245 if (profile != null && m_loginService.AuthenticateUser(profile, passwordValues[0]))
246 authRequest.IsAuthenticated = true;
247 else
248 authRequest.IsAuthenticated = false;
249 }
250 else
251 {
252 // Authentication was requested, send the client a login form
253 using (StreamWriter writer = new StreamWriter(response))
254 writer.Write(String.Format(LOGIN_PAGE, profile.FirstName, profile.SurName));
255 return;
256 }
257 }
258 else
259 {
260 // Cannot find an avatar matching the claimed identifier
261 authRequest.IsAuthenticated = false;
262 }
263 }
264
265 // Add OpenID headers to the response
266 foreach (string key in provider.Request.Response.Headers.Keys)
267 httpResponse.AddHeader(key, provider.Request.Response.Headers[key]);
268
269 string[] contentTypeValues = provider.Request.Response.Headers.GetValues("Content-Type");
270 if (contentTypeValues != null && contentTypeValues.Length == 1)
271 m_contentType = contentTypeValues[0];
272
273 // Set the response code and document body based on the OpenID result
274 httpResponse.StatusCode = (int)provider.Request.Response.Code;
275 response.Write(provider.Request.Response.Body, 0, provider.Request.Response.Body.Length);
276 response.Close();
277 }
278 else if (httpRequest.Url.AbsolutePath.Contains("/openid/server"))
279 {
280 // Standard HTTP GET was made on the OpenID endpoint, send the client the default error page
281 using (StreamWriter writer = new StreamWriter(response))
282 writer.Write(ENDPOINT_PAGE);
283 }
284 else
285 {
286 // Try and lookup this avatar
287 UserProfileData profile;
288 if (TryGetProfile(httpRequest.Url, out profile))
289 {
290 using (StreamWriter writer = new StreamWriter(response))
291 {
292 // TODO: Print out a full profile page for this avatar
293 writer.Write(String.Format(OPENID_PAGE, httpRequest.Url.Scheme,
294 httpRequest.Url.Authority, profile.FirstName, profile.SurName));
295 }
296 }
297 else
298 {
299 // Couldn't parse an avatar name, or couldn't find the avatar in the user server
300 using (StreamWriter writer = new StreamWriter(response))
301 writer.Write(INVALID_OPENID_PAGE);
302 }
303 }
304 }
305 catch (Exception ex)
306 {
307 httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
308 using (StreamWriter writer = new StreamWriter(response))
309 writer.Write(ex.Message);
310 }
311 }
312
313 /// <summary>
314 /// Parse a URL with a relative path of the form /users/First_Last and try to
315 /// retrieve the profile matching that avatar name
316 /// </summary>
317 /// <param name="requestUrl">URL to parse for an avatar name</param>
318 /// <param name="profile">Profile data for the avatar</param>
319 /// <returns>True if the parse and lookup were successful, otherwise false</returns>
320 bool TryGetProfile(Uri requestUrl, out UserProfileData profile)
321 {
322 if (requestUrl.Segments.Length == 3 && requestUrl.Segments[1] == "users/")
323 {
324 // Parse the avatar name from the path
325 string username = requestUrl.Segments[requestUrl.Segments.Length - 1];
326 string[] name = username.Split('_');
327
328 if (name.Length == 2)
329 {
330 profile = m_loginService.GetTheUser(name[0], name[1]);
331 return (profile != null);
332 }
333 }
334
335 profile = null;
336 return false;
337 }
338 }
339}
diff --git a/ThirdPartyLicenses/DotNetOpenid.txt b/ThirdPartyLicenses/DotNetOpenid.txt
new file mode 100644
index 0000000..1b6f678
--- /dev/null
+++ b/ThirdPartyLicenses/DotNetOpenid.txt
@@ -0,0 +1,10 @@
1Copyright (c) 2008, Andrew Arnott, Scott Hanselman, Jason Alexander, et. al
2All rights reserved.
3
4Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8 * Neither the name of the DotNetOpenId nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
10THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file
diff --git a/bin/DotNetOpenId.dll b/bin/DotNetOpenId.dll
new file mode 100644
index 0000000..aa62790
--- /dev/null
+++ b/bin/DotNetOpenId.dll
Binary files differ
diff --git a/prebuild.xml b/prebuild.xml
index 006a063..91d3215 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -845,6 +845,7 @@
845 <Reference name="System" localCopy="false"/> 845 <Reference name="System" localCopy="false"/>
846 <Reference name="System.Data" localCopy="false"/> 846 <Reference name="System.Data" localCopy="false"/>
847 <Reference name="System.Xml" localCopy="false"/> 847 <Reference name="System.Xml" localCopy="false"/>
848 <Reference name="System.Web" localCopy="false"/>
848 <Reference name="OpenSim.Framework"/> 849 <Reference name="OpenSim.Framework"/>
849 <Reference name="OpenSim.Framework.Console"/> 850 <Reference name="OpenSim.Framework.Console"/>
850 <Reference name="OpenSim.Framework.Communications"/> 851 <Reference name="OpenSim.Framework.Communications"/>
@@ -856,6 +857,7 @@
856 <Reference name="OpenMetaverse.StructuredData.dll"/> 857 <Reference name="OpenMetaverse.StructuredData.dll"/>
857 <Reference name="XMLRPC.dll"/> 858 <Reference name="XMLRPC.dll"/>
858 <Reference name="log4net.dll"/> 859 <Reference name="log4net.dll"/>
860 <Reference name="DotNetOpenId"/>
859 861
860 <Files> 862 <Files>
861 <Match pattern="*.cs" recurse="true"/> 863 <Match pattern="*.cs" recurse="true"/>