aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGrid.Framework.Data.MySQL
diff options
context:
space:
mode:
Diffstat (limited to 'OpenGrid.Framework.Data.MySQL')
-rw-r--r--OpenGrid.Framework.Data.MySQL/MySQLGridData.cs51
-rw-r--r--OpenGrid.Framework.Data.MySQL/MySQLManager.cs84
-rw-r--r--OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj62
-rw-r--r--OpenGrid.Framework.Data.MySQL/Properties/AssemblyInfo.cs35
4 files changed, 232 insertions, 0 deletions
diff --git a/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
new file mode 100644
index 0000000..65a0fff
--- /dev/null
+++ b/OpenGrid.Framework.Data.MySQL/MySQLGridData.cs
@@ -0,0 +1,51 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenGrid.Framework.Data;
5
6namespace OpenGrid.Framework.Data.MySQL
7{
8 public class MySQLGridData : IGridData
9 {
10 MySQLManager database;
11
12 public void Initialise()
13 {
14 database = new MySQLManager("localhost", "db", "user", "password", "false");
15 }
16 public SimProfileData GetProfileByHandle(ulong handle)
17 {
18 return new SimProfileData();
19 }
20 public SimProfileData GetProfileByLLUUID(libsecondlife.LLUUID uuid)
21 {
22 return new SimProfileData();
23 }
24 public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authkey)
25 {
26 throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
27 }
28
29 /// <summary>
30 /// Provides a cryptographic authentication of a region
31 /// </summary>
32 /// <remarks>This requires a security audit.</remarks>
33 /// <param name="uuid"></param>
34 /// <param name="handle"></param>
35 /// <param name="authhash"></param>
36 /// <param name="challenge"></param>
37 /// <returns></returns>
38 public bool AuthenticateSim(libsecondlife.LLUUID uuid, ulong handle, string authhash, string challenge)
39 {
40 System.Security.Cryptography.SHA512Managed HashProvider = new System.Security.Cryptography.SHA512Managed();
41 System.Text.ASCIIEncoding TextProvider = new ASCIIEncoding();
42
43 byte[] stream = TextProvider.GetBytes(uuid.ToStringHyphenated() + ":" + handle.ToString() + ":" + challenge);
44 byte[] hash = HashProvider.ComputeHash(stream);
45
46 return false;
47 }
48 }
49
50
51}
diff --git a/OpenGrid.Framework.Data.MySQL/MySQLManager.cs b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
new file mode 100644
index 0000000..30ad314
--- /dev/null
+++ b/OpenGrid.Framework.Data.MySQL/MySQLManager.cs
@@ -0,0 +1,84 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Data;
5
6// MySQL Native
7using MySql;
8using MySql.Data;
9using MySql.Data.Types;
10using MySql.Data.MySqlClient;
11
12namespace OpenGrid.Framework.Data.MySQL
13{
14 class MySQLManager
15 {
16 IDbConnection dbcon;
17
18 /// <summary>
19 /// Initialises and creates a new MySQL connection and maintains it.
20 /// </summary>
21 /// <param name="hostname">The MySQL server being connected to</param>
22 /// <param name="database">The name of the MySQL database being used</param>
23 /// <param name="username">The username logging into the database</param>
24 /// <param name="password">The password for the user logging in</param>
25 /// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param>
26 public MySQLManager(string hostname, string database, string username, string password, string cpooling)
27 {
28 try
29 {
30 string connectionString = "Server=" + hostname + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";";
31 dbcon = new MySqlConnection(connectionString);
32
33 dbcon.Open();
34 }
35 catch (Exception e)
36 {
37 throw new Exception("Error initialising MySql Database: " + e.ToString());
38 }
39 }
40
41 /// <summary>
42 /// Shuts down the database connection
43 /// </summary>
44 public void Close()
45 {
46 dbcon.Close();
47 dbcon = null;
48 }
49
50 /// <summary>
51 /// Runs a query with protection against SQL Injection by using parameterised input.
52 /// </summary>
53 /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
54 /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param>
55 /// <returns>A MySQL DB Command</returns>
56 public IDbCommand Query(string sql, Dictionary<string, string> parameters)
57 {
58 MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
59 dbcommand.CommandText = sql;
60 foreach (KeyValuePair<string, string> param in parameters)
61 {
62 dbcommand.Parameters.Add(param.Key, param.Value);
63 }
64
65 return (IDbCommand)dbcommand;
66 }
67
68 public SimProfileData getRow(IDataReader reader)
69 {
70 SimProfileData retval = new SimProfileData();
71
72 if (reader.Read())
73 {
74 //retval.regionDataURI = reader["regionDataURI"];
75
76 }
77 else
78 {
79 return null;
80 }
81 return retval;
82 }
83 }
84}
diff --git a/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj b/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj
new file mode 100644
index 0000000..dfb6e48
--- /dev/null
+++ b/OpenGrid.Framework.Data.MySQL/OpenGrid.Framework.Data.MySQL.csproj
@@ -0,0 +1,62 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
5 <ProductVersion>8.0.50727</ProductVersion>
6 <SchemaVersion>2.0</SchemaVersion>
7 <ProjectGuid>{66164B45-4821-48E4-9399-14FE2D92D854}</ProjectGuid>
8 <OutputType>Library</OutputType>
9 <AppDesignerFolder>Properties</AppDesignerFolder>
10 <RootNamespace>OpenGrid.Framework.Data.MySQL</RootNamespace>
11 <AssemblyName>OpenGrid.Framework.Data.MySQL</AssemblyName>
12 </PropertyGroup>
13 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14 <DebugSymbols>true</DebugSymbols>
15 <DebugType>full</DebugType>
16 <Optimize>false</Optimize>
17 <OutputPath>bin\Debug\</OutputPath>
18 <DefineConstants>DEBUG;TRACE</DefineConstants>
19 <ErrorReport>prompt</ErrorReport>
20 <WarningLevel>4</WarningLevel>
21 </PropertyGroup>
22 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23 <DebugType>pdbonly</DebugType>
24 <Optimize>true</Optimize>
25 <OutputPath>bin\Release\</OutputPath>
26 <DefineConstants>TRACE</DefineConstants>
27 <ErrorReport>prompt</ErrorReport>
28 <WarningLevel>4</WarningLevel>
29 </PropertyGroup>
30 <ItemGroup>
31 <Reference Include="libsecondlife, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
32 <SpecificVersion>False</SpecificVersion>
33 <HintPath>..\bin\libsecondlife.dll</HintPath>
34 </Reference>
35 <Reference Include="MySql.Data, Version=1.0.7.30072, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
36 <SpecificVersion>False</SpecificVersion>
37 <HintPath>..\bin\MySql.Data.dll</HintPath>
38 </Reference>
39 <Reference Include="System" />
40 <Reference Include="System.Data" />
41 <Reference Include="System.Xml" />
42 </ItemGroup>
43 <ItemGroup>
44 <Compile Include="MySQLGridData.cs" />
45 <Compile Include="MySQLManager.cs" />
46 <Compile Include="Properties\AssemblyInfo.cs" />
47 </ItemGroup>
48 <ItemGroup>
49 <ProjectReference Include="..\OpenGrid.Framework.Data\OpenGrid.Framework.Data.csproj">
50 <Project>{70E6CBC5-2DD0-44F1-87B8-2CFB2458EDE9}</Project>
51 <Name>OpenGrid.Framework.Data</Name>
52 </ProjectReference>
53 </ItemGroup>
54 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
55 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
56 Other similar extension points exist, see Microsoft.Common.targets.
57 <Target Name="BeforeBuild">
58 </Target>
59 <Target Name="AfterBuild">
60 </Target>
61 -->
62</Project> \ No newline at end of file
diff --git a/OpenGrid.Framework.Data.MySQL/Properties/AssemblyInfo.cs b/OpenGrid.Framework.Data.MySQL/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..0bfd1d6
--- /dev/null
+++ b/OpenGrid.Framework.Data.MySQL/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("OpenGrid.Framework.Data.MySQL")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("")]
12[assembly: AssemblyProduct("OpenGrid.Framework.Data.MySQL")]
13[assembly: AssemblyCopyright("Copyright © 2007")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("e49826b2-dcef-41be-a5bd-596733fa3304")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32// You can specify all the values or you can default the Revision and Build Numbers
33// by using the '*' as shown below:
34[assembly: AssemblyVersion("1.0.0.0")]
35[assembly: AssemblyFileVersion("1.0.0.0")]