Changeset 3 for iTunes Web Control

Show
Ignore:
Timestamp:
07/29/07 04:16:08 (18 months ago)
Author:
mayuki
Message:
 
Location:
iTunes Web Control/iTunesWebControl
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • iTunes Web Control/iTunesWebControl/Program.cs

    r1 r3  
    1919        static List<WaitHandle> _waitHandles = new List<WaitHandle>(); 
    2020 
     21        static Dictionary<String, String> ParseCommandLine() 
     22        { 
     23            Dictionary<String, String> argsDict = new Dictionary<string,string>(); 
     24 
     25            String[] args = Environment.GetCommandLineArgs(); 
     26            for (Int32 i = 0; i < args.Length; i++) 
     27            { 
     28                String arg = args[i]; 
     29                if (arg.StartsWith("--")) 
     30                { 
     31                    Int32 eqPos = arg.IndexOf("="); 
     32                    if (eqPos > 0) 
     33                    { 
     34                        String argName = arg.Substring(2, eqPos - 2).ToLowerInvariant(); 
     35                        String argValue = arg.Substring(eqPos + 1); 
     36                        argsDict[argName] = argValue; 
     37                    } 
     38                    else 
     39                    { 
     40                        argsDict[arg.Substring(2).ToLowerInvariant()] = "true"; 
     41                    } 
     42                } 
     43                else 
     44                { 
     45                    argsDict[i.ToString()] = arg; 
     46                } 
     47            } 
     48 
     49            return argsDict; 
     50        } 
     51 
    2152        static void Main(string[] args) 
    2253        { 
    23             endPoint = new IPEndPoint(IPAddress.Any, 18081); 
     54            Dictionary<String, String> argsDict = ParseCommandLine(); 
     55            Int32 port = 18081; 
     56            if (argsDict.ContainsKey("port") && !String.IsNullOrEmpty(argsDict["port"])) 
     57            { 
     58                if (!Int32.TryParse(argsDict["port"], out port)) 
     59                { 
     60                    Console.Error.WriteLine("�G���[: �|�[�g�ԍ��̎w�肪��������������); 
     61                    return; 
     62                } 
     63            } 
     64 
     65            endPoint = new IPEndPoint(IPAddress.Any, port); 
    2466 
    2567            try 
  • iTunes Web Control/iTunesWebControl/SimpleHttpServer.cs

    r2 r3  
     1// $Id$ 
     2#region LICENSE 
     3/* 
     4 * The MIT License 
     5 *  
     6 * Copyright © 2007 Mayuki Sawatari <mayuki@misuzilla.org> 
     7 *  
     8 * Permission is hereby granted, free of charge, to any person obtaining a copy 
     9 * of this software and associated documentation files (the "Software"), to deal 
     10 * in the Software without restriction, including without limitation the rights 
     11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
     12 * copies of the Software, and to permit persons to whom the Software is 
     13 * furnished to do so, subject to the following conditions: 
     14 *  
     15 * The above copyright notice and this permission notice shall be included in 
     16 * all copies or substantial portions of the Software. 
     17 *  
     18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
     19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
     20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
     21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
     22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
     23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
     24 * THE SOFTWARE. 
     25 */ 
     26#endregion 
    127using System; 
    228using System.Collections.Generic; 
     
    94120                else 
    95121                { 
    96                     // XXX: �܂������ 
     122                    // XXX: 折り返し非対応 
    97123                    String[] headerField = line.Split(new Char[] { ':' }, 2); 
    98124                    if (headerField.Length != 2) 
     
    120146 
    121147 
    122         #region IDisposable �����o 
     148        #region IDisposable メンバ 
    123149 
    124150        public void Dispose() 
     
    230256        } 
    231257 
    232         #region IDisposable �����o 
     258        #region IDisposable メンバ 
    233259 
    234260        public void Dispose() 
     
    243269    } 
    244270 
    245     #region HTTP �T�[�o�N���X 
     271    #region HTTP サーバクラス 
    246272    public delegate void RequestEventHandler(Context ctx); 
    247273    public class SimpleHttpServer 
     
    332358                    if (IPAddress.IsLoopback(((IPEndPoint)Context.Current.TcpClient.Client.RemoteEndPoint).Address)) 
    333359                    { 
    334                         sw.WriteLine("<h2>��</h2>"); 
     360                        sw.WriteLine("<h2>例外</h2>"); 
    335361                        sw.WriteLine("<pre>{0}</pre>", HttpUtility.HtmlEncode(he.ToString())); 
    336362                    } 
     
    378404                    sw.WriteLine("<title>500 Internal Server Error</title>"); 
    379405                    sw.WriteLine("<h1>500 Internal Server Error</h1>"); 
    380                     sw.WriteLine("<p>�T�[�o�ŏ�����s���ɃG���[���������܂����B</p>"); 
     406                    sw.WriteLine("<p>サーバで処理を実行中にエラーが発生しました。</p>"); 
    381407                    if (IPAddress.IsLoopback(((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address)) 
    382408                    { 
    383                         sw.WriteLine("<h2>��</h2>"); 
     409                        sw.WriteLine("<h2>例外</h2>"); 
    384410                        sw.WriteLine("<pre>{0}</pre>", HttpUtility.HtmlEncode(e.ToString())); 
    385411                    } 
     
    478504    #endregion 
    479505 
    480     #region HttpStream �N���X 
     506    #region HttpStream クラス 
    481507    public class HttpStream : Stream 
    482508    {