* ReCommit the OpenID patch with a few less dependencies.

* Removes all references to ASP.NET (System.Web.UI,*)
* Removes all references to System.Web.Mobile
0.6.1-post-fixes
Teravus Ovares 2008-12-20 01:20:40 +00:00
parent 098b5d953d
commit 4d26da545d
11 changed files with 1133 additions and 0 deletions

View File

@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Framework.OpenJpeg
{
public static class bio
{
public static opj_bio bio_create()
{
opj_bio bio = new opj_bio();
return bio;
}
public static void bio_destroy(opj_bio bio)
{
// not needed on C#
}
public static int bio_numbytes(opj_bio bio)
{
return (bio.bp - bio.start);
}
public static void bio_init_enc(opj_bio bio, sbyte bp, int len)
{
bio.start = (byte)bp;
bio.end = (byte)(bp + (byte)len);
bio.bp = (byte)bp;
bio.buf = 0;
bio.ct = 8;
}
public static void bio_init_dec(opj_bio bio, sbyte bp, int len)
{
bio.start = (byte)bp;
bio.end = (byte)(bp + len);
bio.bp = (byte)bp;
bio.buf = 0;
bio.ct = 0;
}
public static void bio_write(opj_bio bio, int v, int n)
{
for (int i = n - 1; i >= 0; i--)
bio_putbit(bio, (v >> i) & 1);
}
public static int bio_read(opj_bio bio, int n)
{
int v = 0;
for (int i = n - 1; i >= 0; i--)
v += bio_getbit(bio) << i;
return v;
}
public static int bio_flush(opj_bio bio)
{
bio.ct = 0;
if (bio_byteout(bio) != 0)
return 1;
if (bio.ct == 7)
{
bio.ct = 0;
if (bio_byteout(bio) != 0)
return 1;
}
return 0;
}
public static int bio_inalign(opj_bio bio)
{
bio.ct = 0;
if ((bio.buf & 0xff) == 0xff)
{
if (bio_bytein(bio) != 0)
return 1;
bio.ct = 0;
}
return 0;
}
private static int bio_bytein(opj_bio bio)
{
bio.buf = (bio.buf << 8) & 0xffff;
bio.ct = bio.buf == 0xff00 ? 7 : 8;
if (bio.bp >= bio.end)
return 1;
bio.buf |= bio.bp++;
return 0;
}
private static int bio_byteout(opj_bio bio)
{
bio.buf = (bio.buf << 8) & 0xffff;
bio.ct = bio.buf == 0xff00 ? 7 : 8;
if (bio.bp >= bio.end)
return 1;
bio.bp = (byte)(bio.buf >> 8);
bio.bp++;
return 0;
}
private static void bio_putbit(opj_bio bio, int b)
{
if (bio.ct == 0)
bio_byteout(bio);
bio.ct--;
bio.buf |= (byte)(b << bio.ct);
}
private static int bio_getbit(opj_bio bio)
{
if (bio.ct == 0)
bio_bytein(bio);
bio.ct--;
return (int)((bio.buf >> bio.ct) & 1);
}
}
public struct opj_bio
{
public byte start;
public byte end;
public byte bp;
public uint buf;
public int ct;
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Framework.OpenJpeg
{
public static class fix
{
public static int fix_mul(int a, int b)
{
long temp = (long)a * (long)b;
temp += temp & 4096;
return (int)(temp >> 13);
}
}
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Framework.OpenJpeg
{
public static class int_
{
public static int int_min(int a, int b)
{
return a < b ? a : b;
}
public static int int_max(int a, int b)
{
return (a > b) ? a : b;
}
public static int int_clamp(int a, int min, int max)
{
if (a < min)
return min;
if (a > max)
return max;
return a;
}
public static int int_abs(int a)
{
return a < 0 ? -a : a;
}
public static int int_ceildiv(int a, int b)
{
return (a + b - 1) / b;
}
public static int int_ceildivpow2(int a, int b)
{
return (a + (1 << b) - 1) >> b;
}
public static int int_floordivpow2(int a, int b)
{
return a >> b;
}
public static int int_floorlog2(int a)
{
for (int l=0; a > 1; l++)
a >>= 1;
return 1;
}
}
}

View File

@ -0,0 +1,158 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Framework.OpenJpeg
{
public static class j2k
{
}
public enum J2K_STATUS
{
J2K_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */
J2K_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */
J2K_STATE_MH = 0x0004, /**< the decoding process is in the main header */
J2K_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */
J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */
J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */
J2K_STATE_NEOC = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */
J2K_STATE_ERR = 0x0080 /**< the decoding process has encountered an error */
}
public enum J2K_T2_MODE
{
THRESH_CALC = 0, /** Function called in Rate allocation process*/
FINAL_PASS = 1 /** Function called in Tier 2 process*/
}
public struct opj_stepsize
{
public int expn;
public int mant;
}
public struct opj_tccp
{
public int csty;
public int numresolutions;
public int cblkw;
public int cblkh;
public int cblksty;
public int qmfbid;
public int qntsty;
/// <summary>
/// don't forget to initialize 97 elements
/// </summary>
public opj_stepsize[] stepsizes;
public int numgbits;
public int roishift;
/// <summary>
/// Don't forget to initialize 33 elements
/// </summary>
public int[] prcw;
}
public struct opj_tcp
{
public int first;
public int csty;
public PROG_ORDER prg;
public int numlayers;
public int mct;
/// <summary>
/// don't forget to initialize to 100
/// </summary>
public float[] rates;
public int numpocs;
public int POC;
/// <summary>
/// Don't forget to initialize to 32
/// </summary>
public opj_poc[] pocs;
public byte ppt_data;
public byte ppt_data_first;
public int ppt;
public int ppt_store;
public int ppt_len;
/// <summary>
/// Don't forget to initialize 100 elements
/// </summary>
public float[] distoratio;
public opj_tccp tccps;
}
public struct opj_cp
{
public CINEMA_MODE cinema;
public int max_comp_size;
public int img_size;
public RSIZ_CAPABILITIES rsiz;
public sbyte tp_on;
public sbyte tp_flag;
public int tp_pos;
public int distro_alloc;
public int fixed_alloc;
public int fixed_quality;
public int reduce;
public int layer;
public LIMIT_DECODING limit_decoding;
public int tx0;
public int ty0;
public int tdx;
public int tdy;
public sbyte? comment;
public int tw;
public int th;
public int? tileno;
public byte ppm_data;
public byte ppm_data_first;
public int ppm;
public int ppm_store;
public int ppm_previous;
public int ppm_len;
public opj_tcp tcps;
public int matrice;
}
public static class j2kdefines
{
public const uint J2K_CP_CSTY_PRT = 0x01;
public const uint J2K_CP_CSTY_SOP = 0x02;
public const uint J2K_CP_CSTY_EPH = 0x04;
public const uint J2K_CCP_CSTY_PRT = 0x01;
public const uint J2K_CCP_CBLKSTY_LAZY = 0x01;
public const uint J2K_CCP_CBLKSTY_RESET = 0x02;
public const uint J2K_CCP_CBLKSTY_TERMALL = 0x04;
public const uint J2K_CCP_CBLKSTY_VSC = 0x08;
public const uint J2K_CCP_CBLKSTY_PTERM =0x10;
public const uint J2K_CCP_CBLKSTY_SEGSYM = 0x20;
public const uint J2K_CCP_QNTSTY_NOQNT = 0;
public const uint J2K_CCP_QNTSTY_SIQNT = 1;
public const uint J2K_CCP_QNTSTY_SEQNT = 2;
public const uint J2K_MS_SOC = 0xff4f; /**< SOC marker value */
public const uint J2K_MS_SOT = 0xff90; /**< SOT marker value */
public const uint J2K_MS_SOD = 0xff93; /**< SOD marker value */
public const uint J2K_MS_EOC = 0xffd9; /**< EOC marker value */
public const uint J2K_MS_SIZ = 0xff51; /**< SIZ marker value */
public const uint J2K_MS_COD = 0xff52; /**< COD marker value */
public const uint J2K_MS_COC = 0xff53; /**< COC marker value */
public const uint J2K_MS_RGN = 0xff5e; /**< RGN marker value */
public const uint J2K_MS_QCD = 0xff5c; /**< QCD marker value */
public const uint J2K_MS_QCC = 0xff5d; /**< QCC marker value */
public const uint J2K_MS_POC = 0xff5f; /**< POC marker value */
public const uint J2K_MS_TLM = 0xff55; /**< TLM marker value */
public const uint J2K_MS_PLM = 0xff57; /**< PLM marker value */
public const uint J2K_MS_PLT = 0xff58; /**< PLT marker value */
public const uint J2K_MS_PPM = 0xff60; /**< PPM marker value */
public const uint J2K_MS_PPT = 0xff61; /**< PPT marker value */
public const uint J2K_MS_SOP = 0xff91; /**< SOP marker value */
public const uint J2K_MS_EPH = 0xff92; /**< EPH marker value */
public const uint J2K_MS_CRG = 0xff63; /**< CRG marker value */
public const uint J2K_MS_COM = 0xff64; /**< COM marker value */
}
}

View File

@ -0,0 +1,358 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Framework.OpenJpeg
{
public class openjpeg
{
public openjpeg()
{
}
}
public enum PROG_ORDER
{
PROG_UNKNOWN = -1,
LRCP = 0,
RLCP = 1,
RPCL = 2,
PCRL = 3,
CPRL = 4
}
public enum RSIZ_CAPABILITIES
{
STD_RSIZ = 0,
CINEMA2K = 3,
CINEMA4K = 4
}
public enum CINEMA_MODE
{
OFF = 0,
CINEMA2K_24 = 1,
CINEMA2K_48 = 2,
CINEMA4K_24 = 3
}
public enum COLOR_SPACE
{
CLRSPC_UNKNOWN = -1,
CLRSPC_SRGB = 1,
CLRSPC_GRAY = 2,
CLRSPC_SYCC = 3
}
public enum CODEC_FORMAT
{
CODEC_UNKNOWN = -1,
CODEC_J2K = 0,
CODEC_JPT = 1,
CODEC_JP2 = 2
}
public enum LIMIT_DECODING
{
NO_LIMITATION = 0,
LIMIT_TO_MAIN_HEADER=1,
DECODE_ALL_BUT_PACKETS = 2
}
public struct opj_poc
{
public int resno0, compno0;
public int layno1, resno1, compno1;
public int layno0, precno0, precno1;
public PROG_ORDER prg1, prg;
/// <summary>
/// Don't forget to initialize with 5 elements
/// </summary>
public sbyte[] progorder;
public int tile;
public int tx0, tx1, ty0, ty1;
public int layS, resS, copmS, prcS;
public int layE, resE, compE, prcE;
public int txS, txE, tyS, tyE, dx, dy;
public int lay_t, res_t, comp_t, prc_t, tx0_t, ty0_t;
}
public struct opj_cparameters
{
public bool tile_size_on;
public int cp_tx0;
public int cp_ty0;
public int cp_tdx;
public int cp_tdy;
public int cp_disto_alloc;
public int cp_fixed_alloc;
public int cp_fixed_wuality;
public int cp_matrice;
public sbyte cp_comment;
public int csty;
public PROG_ORDER prog_order;
/// <summary>
/// Don't forget to initialize 32 elements
/// </summary>
public opj_poc[] POC;
public int numpocs;
public int tcp_numlayers;
/// <summary>
/// Don't forget to intitialize 100 elements
/// </summary>
public float[] tcp_rates;
/// <summary>
/// Don't forget to initialize 100 elements
/// </summary>
public float[] tcp_distoratio;
public int numresolution;
public int cblockw_init;
public int cblockh_init;
public int mode;
public int irreversible;
public int roi_compno;
public int roi_shift;
public int res_spec;
/// <summary>
/// Don't forget to initialize 33 elements
/// </summary>
public int[] prc_init;
/// <summary>
/// Don't forget to initialize 33 elements
/// </summary>
public int[] prch_init;
public string infile;
public string outfile;
public int index_on;
public string index;
public int image_offset_x0;
public int image_offset_y0;
public int subsampling_dx;
public int subsampling_dy;
public int decod_format;
public int cod_format;
public bool jpwl_epc_on;
public int jpwl_hprot_MH;
/// <summary>
/// Don't forget to initialize 16 elements
/// </summary>
public int[] jpwl_hprot_TPH_tileno;
/// <summary>
/// Don't forget to initialize 16 elements
/// </summary>
public int[] jpwl_hprot_TPH;
/// <summary>
/// Don't forget to initialize 16 elements
/// </summary>
public int[] jpwl_pprot_tileno;
public int[] jpwl_pprot_packno;
public int[] jpwl_pprot;
public int jpwl_sens_size;
public int jpwl_sense_addr;
public int jpwl_sens_range;
public int jpwl_sens_MH;
/// <summary>
/// Don't forget to initialize 16 elements
/// </summary>
public int[] jpwl_sens_TPH_tileno;
/// <summary>
/// Don't forget to initialize 16 elements
/// </summary>
public int[] jpwl_sens_TPH;
public CINEMA_MODE cp_cinema;
public int max_comp_size;
public sbyte tp_on;
public sbyte tp_flag;
public sbyte tcp_mct;
}
public struct opj_dparameters
{
public int cp_reduce;
public int cp_layer;
public string infile;
public string outfile;
public int decod_format;
public int cod_format;
public bool jpwl_correct;
public int jpwl_exp_comps;
public int jpwl_max_tiles;
public LIMIT_DECODING cp_limit_decoding;
}
public struct opj_common_fields
{
public bool is_decompressor;
public CODEC_FORMAT codec_format;
}
public struct opj_common_struct
{
public opj_common_fields flds;
}
public struct opj_cinfo
{
public opj_common_fields flds;
}
public struct opj_dinfo
{
public opj_common_fields flds;
}
public struct opj_cio
{
public opj_common_struct cinfo;
public int openmode;
public byte buffer;
public int length;
public byte start;
public byte end;
public byte bp;
}
public struct opj_image_comp
{
public int dx;
public int dy;
public int w;
public int h;
public int x0;
public int y0;
public int prec;
public int bpp;
public int sgnd;
public int resno_decoded;
public int factor;
public int data;
}
public struct opj_image
{
public int x0;
public int y0;
public int x1;
public int y1;
public int numcomps;
public COLOR_SPACE color_space;
public opj_image_comp comps;
}
public struct opj_image_comptparm
{
public int dx;
public int dy;
public int w;
public int h;
public int x0;
public int y0;
public int prec;
public int bpp;
public int sgnd;
}
public struct opj_packet_info
{
public int start_pos;
public int end_ph_pos;
public int end_pos;
public double disto;
}
public struct opj_tp_info
{
public int tp_start_pos;
public int tp_end_header;
public int tp_end_pos;
public int tp_start_pack;
public int tp_numpacks;
}
public struct opj_tile_info
{
public double thresh;
public int tileno;
public int start_pos;
public int end_header;
public int end_pos;
/// <summary>
/// Don't forget to initialize 33 elements
/// </summary>
public int[] pw;
/// <summary>
/// Don't forget to initialize 33 elements
/// </summary>
public int[] ph;
/// <summary>
/// Don't forget to initialize 33 elements
/// </summary>
public int[] pdx;
/// <summary>
/// Don't forget to initialize 33 elements
/// </summary>
public int[] pdy;
public opj_packet_info packet;
public int numpix;
public double distotile;
public int num_tps;
public opj_tp_info tp;
}
public struct opj_marker_info_t
{
public ushort type;
public int pos;
public int len;
}
public struct opj_codestream_info
{
public double D_max;
public int packno;
public int index_write;
public int image_w;
public int image_h;
public PROG_ORDER prog;
public int tile_x;
public int tile_y;
public int tile_Ox;
public int tile_Oy;
public int tw;
public int numcomps;
public int numlayers;
public int numdecompos;
public int marknum;
public opj_marker_info_t marker;
public int maxmarknum;
public int main_head_start;
public int main_head_end;
public int codestream_size;
public opj_tile_info tile;
}
public static class opj_defines
{
public const int OPJ_STREAM_READ = 0x0001;
public const int OPJ_STREAM_WRITE = 0x0002;
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Framework.OpenJpeg
{
public static class pi
{
}
public struct opj_pi_resolution
{
public int pdx, pdy;
public int pw, ph;
}
public struct opj_pi_comp
{
public int dx, dy;
public int numresolutions;
public opj_pi_resolution resolutions;
}
public struct obj_pi_iterator
{
public sbyte tp_on;
public short include;
public int step_l;
public int step_r;
public int step_c;
public int step_p;
public int compno;
public int resno;
public int precno;
public int layno;
public int first;
public opj_poc poc;
public int numcomps;
public opj_pi_comp comps;
public int tx0, ty0, tx1, ty1;
public int x, y, dx, dy;
}
}

View File

@ -187,6 +187,12 @@ namespace OpenSim.Grid.UserServer
new RestStreamHandler("DELETE", "/usersessions/", m_userManager.RestDeleteUserSessionMethod));
m_httpServer.AddXmlRPCHandler("update_user_profile", m_userManager.XmlRpcResponseXmlRPCUpdateUserProfile);
// Handler for OpenID avatar identity pages
m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/users/", m_loginService));
// Handlers for the OpenID endpoint server
m_httpServer.AddStreamHandler(new OpenIdStreamHandler("POST", "/openid/server/", m_loginService));
m_httpServer.AddStreamHandler(new OpenIdStreamHandler("GET", "/openid/server/", m_loginService));
}
public void do_create(string[] args)

View File

@ -0,0 +1,339 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``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 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.
*/
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Web;
using System.Text;
using DotNetOpenId;
using DotNetOpenId.Provider;
using log4net;
using OpenSim.Framework;
using OpenSim.Framework.Servers;
namespace OpenSim.Grid.UserServer
{
/// <summary>
/// Temporary, in-memory store for OpenID associations
/// </summary>
public class ProviderMemoryStore : IAssociationStore<AssociationRelyingPartyType>
{
private class AssociationItem
{
public AssociationRelyingPartyType DistinguishingFactor;
public string Handle;
public DateTime Expires;
public byte[] PrivateData;
}
Dictionary<string, AssociationItem> m_store = new Dictionary<string, AssociationItem>();
SortedList<DateTime, AssociationItem> m_sortedStore = new SortedList<DateTime, AssociationItem>();
object m_syncRoot = new object();
#region IAssociationStore<AssociationRelyingPartyType> Members
public void StoreAssociation(AssociationRelyingPartyType distinguishingFactor, Association assoc)
{
AssociationItem item = new AssociationItem();
item.DistinguishingFactor = distinguishingFactor;
item.Handle = assoc.Handle;
item.Expires = assoc.Expires.ToLocalTime();
item.PrivateData = assoc.SerializePrivateData();
lock (m_syncRoot)
{
m_store[item.Handle] = item;
m_sortedStore[item.Expires] = item;
}
}
public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor)
{
lock (m_syncRoot)
{
if (m_sortedStore.Count > 0)
{
AssociationItem item = m_sortedStore.Values[m_sortedStore.Count - 1];
return Association.Deserialize(item.Handle, item.Expires.ToUniversalTime(), item.PrivateData);
}
else
{
return null;
}
}
}
public Association GetAssociation(AssociationRelyingPartyType distinguishingFactor, string handle)
{
AssociationItem item;
bool success = false;
lock (m_syncRoot)
success = m_store.TryGetValue(handle, out item);
if (success)
return Association.Deserialize(item.Handle, item.Expires.ToUniversalTime(), item.PrivateData);
else
return null;
}
public bool RemoveAssociation(AssociationRelyingPartyType distinguishingFactor, string handle)
{
lock (m_syncRoot)
{
for (int i = 0; i < m_sortedStore.Values.Count; i++)
{
AssociationItem item = m_sortedStore.Values[i];
if (item.Handle == handle)
{
m_sortedStore.RemoveAt(i);
break;
}
}
return m_store.Remove(handle);
}
}
public void ClearExpiredAssociations()
{
lock (m_syncRoot)
{
List<AssociationItem> itemsCopy = new List<AssociationItem>(m_sortedStore.Values);
DateTime now = DateTime.Now;
for (int i = 0; i < itemsCopy.Count; i++)
{
AssociationItem item = itemsCopy[i];
if (item.Expires <= now)
{
m_sortedStore.RemoveAt(i);
m_store.Remove(item.Handle);
}
}
}
}
#endregion
}
public class OpenIdStreamHandler : IStreamHandler
{
#region HTML
/// <summary>Login form used to authenticate OpenID requests</summary>
const string LOGIN_PAGE =
@"<html>
<head><title>OpenSim OpenID Login</title></head>
<body>
<h3>OpenSim Login</h3>
<form method=""post"">
<label for=""first"">First Name:</label> <input readonly type=""text"" name=""first"" id=""first"" value=""{0}""/>
<label for=""last"">Last Name:</label> <input readonly type=""text"" name=""last"" id=""last"" value=""{1}""/>
<label for=""pass"">Password:</label> <input type=""password"" name=""pass"" id=""pass""/>
<input type=""submit"" value=""Login"">
</form>
</body>
</html>";
/// <summary>Page shown for a valid OpenID identity</summary>
const string OPENID_PAGE =
@"<html>
<head>
<title>{2} {3}</title>
<link rel=""openid2.provider openid.server"" href=""{0}://{1}/openid/server/""/>
</head>
<body>OpenID identifier for {2} {3}</body>
</html>
";
/// <summary>Page shown for an invalid OpenID identity</summary>
const string INVALID_OPENID_PAGE =
@"<html><head><title>Identity not found</title></head>
<body>Invalid OpenID identity</body></html>";
/// <summary>Page shown if the OpenID endpoint is requested directly</summary>
const string ENDPOINT_PAGE =
@"<html><head><title>OpenID Endpoint</title></head><body>
This is an OpenID server endpoint, not a human-readable resource.
For more information, see <a href='http://openid.net/'>http://openid.net/</a>.
</body></html>";
#endregion HTML
public string ContentType { get { return m_contentType; } }
public string HttpMethod { get { return m_httpMethod; } }
public string Path { get { return m_path; } }
string m_contentType;
string m_httpMethod;
string m_path;
UserLoginService m_loginService;
ProviderMemoryStore m_openidStore = new ProviderMemoryStore();
/// <summary>
/// Constructor
/// </summary>
public OpenIdStreamHandler(string httpMethod, string path, UserLoginService loginService)
{
m_loginService = loginService;
m_httpMethod = httpMethod;
m_path = path;
m_contentType = "text/html";
}
/// <summary>
/// Handles all GET and POST requests for OpenID identifier pages and endpoint
/// server communication
/// </summary>
public void Handle(string path, Stream request, Stream response, OSHttpRequest httpRequest, OSHttpResponse httpResponse)
{
Uri providerEndpoint = new Uri(String.Format("{0}://{1}{2}", httpRequest.Url.Scheme, httpRequest.Url.Authority, httpRequest.Url.AbsolutePath));
// Defult to returning HTML content
m_contentType = "text/html";
try
{
NameValueCollection postQuery = HttpUtility.ParseQueryString(new StreamReader(httpRequest.InputStream).ReadToEnd());
NameValueCollection getQuery = HttpUtility.ParseQueryString(httpRequest.Url.Query);
NameValueCollection openIdQuery = (postQuery.GetValues("openid.mode") != null ? postQuery : getQuery);
OpenIdProvider provider = new OpenIdProvider(m_openidStore, providerEndpoint, httpRequest.Url, openIdQuery);
if (provider.Request != null)
{
if (!provider.Request.IsResponseReady && provider.Request is IAuthenticationRequest)
{
IAuthenticationRequest authRequest = (IAuthenticationRequest)provider.Request;
string[] passwordValues = postQuery.GetValues("pass");
UserProfileData profile;
if (TryGetProfile(new Uri(authRequest.ClaimedIdentifier.ToString()), out profile))
{
// Check for form POST data
if (passwordValues != null && passwordValues.Length == 1)
{
if (profile != null && m_loginService.AuthenticateUser(profile, passwordValues[0]))
authRequest.IsAuthenticated = true;
else
authRequest.IsAuthenticated = false;
}
else
{
// Authentication was requested, send the client a login form
using (StreamWriter writer = new StreamWriter(response))
writer.Write(String.Format(LOGIN_PAGE, profile.FirstName, profile.SurName));
return;
}
}
else
{
// Cannot find an avatar matching the claimed identifier
authRequest.IsAuthenticated = false;
}
}
// Add OpenID headers to the response
foreach (string key in provider.Request.Response.Headers.Keys)
httpResponse.AddHeader(key, provider.Request.Response.Headers[key]);
string[] contentTypeValues = provider.Request.Response.Headers.GetValues("Content-Type");
if (contentTypeValues != null && contentTypeValues.Length == 1)
m_contentType = contentTypeValues[0];
// Set the response code and document body based on the OpenID result
httpResponse.StatusCode = (int)provider.Request.Response.Code;
response.Write(provider.Request.Response.Body, 0, provider.Request.Response.Body.Length);
response.Close();
}
else if (httpRequest.Url.AbsolutePath.Contains("/openid/server"))
{
// Standard HTTP GET was made on the OpenID endpoint, send the client the default error page
using (StreamWriter writer = new StreamWriter(response))
writer.Write(ENDPOINT_PAGE);
}
else
{
// Try and lookup this avatar
UserProfileData profile;
if (TryGetProfile(httpRequest.Url, out profile))
{
using (StreamWriter writer = new StreamWriter(response))
{
// TODO: Print out a full profile page for this avatar
writer.Write(String.Format(OPENID_PAGE, httpRequest.Url.Scheme,
httpRequest.Url.Authority, profile.FirstName, profile.SurName));
}
}
else
{
// Couldn't parse an avatar name, or couldn't find the avatar in the user server
using (StreamWriter writer = new StreamWriter(response))
writer.Write(INVALID_OPENID_PAGE);
}
}
}
catch (Exception ex)
{
httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
using (StreamWriter writer = new StreamWriter(response))
writer.Write(ex.Message);
}
}
/// <summary>
/// Parse a URL with a relative path of the form /users/First_Last and try to
/// retrieve the profile matching that avatar name
/// </summary>
/// <param name="requestUrl">URL to parse for an avatar name</param>
/// <param name="profile">Profile data for the avatar</param>
/// <returns>True if the parse and lookup were successful, otherwise false</returns>
bool TryGetProfile(Uri requestUrl, out UserProfileData profile)
{
if (requestUrl.Segments.Length == 3 && requestUrl.Segments[1] == "users/")
{
// Parse the avatar name from the path
string username = requestUrl.Segments[requestUrl.Segments.Length - 1];
string[] name = username.Split('_');
if (name.Length == 2)
{
profile = m_loginService.GetTheUser(name[0], name[1]);
return (profile != null);
}
}
profile = null;
return false;
}
}
}

View File

@ -0,0 +1,10 @@
Copyright (c) 2008, Andrew Arnott, Scott Hanselman, Jason Alexander, et. al
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 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.
* 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.
THIS 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.

BIN
bin/DotNetOpenId.dll Normal file

Binary file not shown.

View File

@ -845,6 +845,7 @@
<Reference name="System" localCopy="false"/>
<Reference name="System.Data" localCopy="false"/>
<Reference name="System.Xml" localCopy="false"/>
<Reference name="System.Web" localCopy="false"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="OpenSim.Framework.Communications"/>
@ -856,6 +857,7 @@
<Reference name="OpenMetaverse.StructuredData.dll"/>
<Reference name="XMLRPC.dll"/>
<Reference name="log4net.dll"/>
<Reference name="DotNetOpenId"/>
<Files>
<Match pattern="*.cs" recurse="true"/>