33 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
44 * obtain one at http://mozilla.org/MPL/2.0/
55 *
6- * Copyright (C) 2009-2014 , Peter Johnson (www.delphidabbler.com).
6+ * Copyright (C) 2009-2016 , Peter Johnson (www.delphidabbler.com).
77 *
88 * $Rev$
99 * $Date$
@@ -35,12 +35,13 @@ TWebServiceInfo = record
3535 // / <summary>MIME type of media used by web service.</summary>
3636 MediaType: string;
3737 // / <summary>Constructs a record with given field values.</summary>
38- // / <param name="AScriptURLTplt">string [in] Template for web service's
39- // / URI.</param>
40- // / <param name="AUserAgent">string [in] User agent to use when accessing
41- // / web service.</param>
42- // / <param name="AMediaType">string [in] Optional. Media type used by web
43- // / service.</param>
38+ // / <param name="AScriptURLTplt"><c>string</c> [in] Template for web
39+ // / service's URI. Must contain a single '%s' placeholder for web host.
40+ // / </param>
41+ // / <param name="AUserAgent"><c>string</c> [in] User agent to use when
42+ // / accessing web service.</param>
43+ // / <param name="AMediaType"><c>string</c> [in] Optional. Media type used
44+ // / by web service.</param>
4445 constructor Create(const AScriptURLTplt, AUserAgent: string;
4546 const AMediaType: string = ' text/*' );
4647 end ;
@@ -67,25 +68,31 @@ TWebProxyInfo = record
6768 TWebInfo = class (TNoConstructObject)
6869 strict private
6970 const
70- // / <summary>Remote DelphiDabbler web server.</summary>
71- RemoteHost = ' delphidabbler.com' ;
71+ // / <summary>Name of server that hosts tested and released web services
72+ // / that are used by CodeSnip.</summary>
73+ // / <remarks>There is also a test server that can be used by CodeSnip
74+ // / where new and updated web services are tested - see
75+ // / <c>TestServerHost</c> below.</remarks>
76+ ProductionServerHost = ' delphidabbler.com' ;
7277 // / <summary>URL of DelphiDabbler website.</summary>
73- WebsiteURL = ' http://' + RemoteHost ;
78+ WebsiteURL = ' http://' + ProductionServerHost ;
7479 // / <summary>Template for URL of Code Snippets news feed.</summary>
7580 // / <remarks>'%d' placeholder must be replaced by the required number of
76- // / days into the past the news feed should cover.</remarks>
81+ // / days into the past the news feed should cover. Passing <c>0</c> as
82+ // / the number of days results in all news items being returned.
83+ // / </remarks>
7784 NewsFeedTplt = WebSiteURL + ' /feeds/site-news-feed?id=codesnip&days=%d' ;
7885 strict private
79- // / <summary>Returns the name of the host server to be used.</summary>
80- // / <remarks>This is the remote web server unless the '-localhost# switch
81- // / was passed on the command line when localhost server is returned.
82- // / </remarks>
86+ // / <summary>Returns the name of the server that hosts web services that
87+ // / are used by CodeSnip.</summary>
88+ // / <remarks>By default is the production server (as specified by the
89+ // / <c>ProductionServerHost</c> constant). CodeSnip will instead use a
90+ // / test server (as returned by the <c>TestServerHost</c> method) if the
91+ // / name and port of the test server is passed on the command line via the
92+ // / <c>--test-server</c> command line option.</remarks>
8393 class function Host : string;
8494 public
8595 const
86- // / <summary>Local web server.</summary>
87- // / <remarks>Used for test purposes.</remarks>
88- LocalHost = ' localhost:8080' ;
8996 // / <summary>URL of home page on DelphiDabbler website.</summary>
9097 DelphiDabblerHomeURL = WebsiteURL + ' /' ;
9198 // / <summary>URL of home page of the CodeSnip project.</summary>
@@ -94,37 +101,59 @@ TWebInfo = class(TNoConstructObject)
94101 DatabaseURL = WebsiteURL + ' /url/csdb' ;
95102 // / <summary>URL used to make donations towards the CodeSnip project.
96103 // / </summary>
97- // / <summary >This URL redirects to the correct page on PayPal.</summary >
104+ // / <remarks >This URL redirects to the correct page on PayPal.</remarks >
98105 DonateURL = WebsiteURL + ' /url/donate-cs' ;
99106 // / <summary>URL used to view and report CodeSnip bugs.</summary>
107+ // / <remarks>This URL will redirect to the actual bug tracker which may
108+ // / be on an external site such as SourceForge or GitHub.</remarks>
100109 BugTrackerURL = WebsiteURL + ' /url/codesnip-bugs' ;
101110 // / <summary>URL of CodeSnip's FAQ web page.</summary>
111+ // / <remarks>This URL will redirect to the FAQ location which may be on
112+ // / an external site such as GitHub or SourceForge.</remarks>
102113 FAQsURL = WebsiteURL + ' /url/codesnip-faq' ;
103114 public
115+ // / <summary>Returns the name of the server that hosts web services used by
116+ // / CodeSnip when under testing. This server receives updated web services
117+ // / before they are released to the production server.</summary>
118+ // / <remarks>
119+ // / <para>The name of this server must be passed on the command line via
120+ // / the <c>--test-server</c> option. If this option is not specified then
121+ // / <c>TestServerHost</c> returns the empty string.</para>
122+ // / <para>The format of the command line switch is
123+ // / <c>--test-server=server-name</c> or
124+ // / <c>--test-server=server-name:port</c> where <c>server-name</c> is the
125+ // / name of the test server and <c>port</c> is the port number it is
126+ // / operating on, for example <c>--test-server=localhost:8080</c> or
127+ // / <c>--test-server=test.delphidabbler.com</c>. The
128+ // / port number and its preceding ':' character can be omitted if the
129+ // / server is on port 80.</para>
130+ // / <para>The server must be using the <c>http://</c> protocol.</para>
131+ // / </remarks>
132+ class function TestServerHost : string;
104133 // / <summary>Builds the URL of the CodeSnip news feed.</summary>
105- // / <param name="Age">Word [in] Maximum age, in days, of news items to be
106- // / included in the feed.</param>
107- // / <returns>string. Required URL.</returns>
134+ // / <param name="Age"><c> Word</c> [in] Maximum age, in days, of news items
135+ // / to be included in the feed.</param>
136+ // / <returns><c> string</c> . Required URL.</returns>
108137 class function NewsFeedURL (const Age: Word): string;
109138 // / <summary>Builds the URL of a web service.</summary>
110- // / <param name="URLTplt">string. [in] Template of URL of web service
111- // / script. Must contain a '%s' placeholder for host name.</param>
112- // / <returns>string. Required URL.</returns>
139+ // / <param name="URLTplt"><c> string</c> . [in] Template of URL of web
140+ // / service script. Must contain a '%s' placeholder for host name.</param>
141+ // / <returns><c> string</c> . Required URL.</returns>
113142 class function WebServiceURL (const URLTplt: string): string;
114143 // / <summary>Gets information about any required web proxy.</summary>
115144 // / <remarks>The web proxy information is read from settings.</remarks>
116145 class function WebProxyInfo : TWebProxyInfo;
117- // / <summary>Checks if the program is using the web server on localhost.
118- // / </summary>
119- // / <returns>Boolean. True if localhost is being used, False if the remote,
120- // / production, server is being used. </returns>
146+ // / <summary>Checks if the program is using a test web server.</summary>
147+ // / <returns><c>Boolean</c>. <c>True</c> if a test web server is being
148+ // / used, <c>False</c> if the production web server is being used.
149+ // / </returns>
121150 // / <remarks>
122- // / <para>True is returned iff the '-localhost' switch was passed on the
123- // / command line.</para>
124- // / <para>Localhost should only be used by developers with access to a
125- // / suitable test server running as 'locahost' .</para>
151+ // / <para><c> True</c> is returned iff a valid <c>--test-server</c> command
152+ // / line option was supplied .</para>
153+ // / <para><c>--test-server</c> should only be specified by developers with
154+ // / access to a suitable test server .</para>
126155 // / </remarks>
127- class function UsingLocalHost : Boolean;
156+ class function UsingTestServer : Boolean;
128157 end ;
129158
130159
@@ -142,20 +171,43 @@ implementation
142171
143172class function TWebInfo.Host : string;
144173begin
145- if UsingLocalHost then
146- Result := LocalHost
174+ if UsingTestServer then
175+ Result := TestServerHost
147176 else
148- Result := RemoteHost ;
177+ Result := ProductionServerHost ;
149178end ;
150179
151180class function TWebInfo.NewsFeedURL (const Age: Word): string;
152181begin
153182 Result := Format(NewsFeedTplt, [Age]);
154183end ;
155184
156- class function TWebInfo.UsingLocalHost : Boolean;
185+ class function TWebInfo.TestServerHost : string;
186+ const
187+ TestServerSwitch = ' --test-server' ;
188+ Separator = ' =' ;
189+ var
190+ Idx: Integer;
191+ ParamName: string;
192+ ParamValue: string;
193+ begin
194+ for Idx := 1 to ParamCount do
195+ begin
196+ if not StrContainsStr(Separator, ParamStr(Idx)) then
197+ Continue;
198+ StrSplit(ParamStr(Idx), Separator, ParamName, ParamValue);
199+ if not StrSameStr(TestServerSwitch, ParamName) then
200+ Continue;
201+ if ParamValue = EmptyStr then
202+ Continue;
203+ Exit(ParamValue);
204+ end ;
205+ Result := EmptyStr;
206+ end ;
207+
208+ class function TWebInfo.UsingTestServer : Boolean;
157209begin
158- Result := FindCmdLineSwitch( ' localhost ' , True) ;
210+ Result := TestServerHost <> EmptyStr ;
159211end ;
160212
161213class function TWebInfo.WebProxyInfo : TWebProxyInfo;
0 commit comments