mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-07-07 19:06:07 +02:00
* Fix HTTP protocol
This commit is contained in:
parent
176a8e84ef
commit
0656b7e4fe
@ -210,7 +210,7 @@ Function IDEInstantSearchManager : TIDEInstantSearchManager;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses TypInfo, Strutils, IDEExternToolIntf, MacroIntf, IDEOptionsIntf, instantsearchstrings;
|
uses TypInfo, DateUtils, Strutils, IDEExternToolIntf, MacroIntf, IDEOptionsIntf, instantsearchstrings;
|
||||||
|
|
||||||
function IDEInstantSearchManager: TIDEInstantSearchManager;
|
function IDEInstantSearchManager: TIDEInstantSearchManager;
|
||||||
begin
|
begin
|
||||||
@ -415,7 +415,7 @@ procedure TInstantSearchIndexTreeThread.Execute;
|
|||||||
var
|
var
|
||||||
I,aCount : Integer;
|
I,aCount : Integer;
|
||||||
aTree : TSourceTreeDefinition;
|
aTree : TSourceTreeDefinition;
|
||||||
|
aStart,aEnd : TDateTime;
|
||||||
begin
|
begin
|
||||||
For I:=0 to FTrees.Count-1 do
|
For I:=0 to FTrees.Count-1 do
|
||||||
try
|
try
|
||||||
@ -423,8 +423,10 @@ begin
|
|||||||
aTree:=FTrees[i];
|
aTree:=FTrees[i];
|
||||||
FCurrentTree:=aTree.Name;
|
FCurrentTree:=aTree.Name;
|
||||||
DoLog(mlkProgress,lrsStartIndexingTree,[FCurrentTree,aTree.BaseDir]);
|
DoLog(mlkProgress,lrsStartIndexingTree,[FCurrentTree,aTree.BaseDir]);
|
||||||
|
aStart:=Now;
|
||||||
aCount:=IndexTree(aTree);
|
aCount:=IndexTree(aTree);
|
||||||
DoLog(mlkProgress,lrsFinishedIndexingTree,[FCurrentTree,aCount]);
|
aEnd:=Now;
|
||||||
|
DoLog(mlkProgress,lrsFinishedIndexingTree,[FCurrentTree,aCount,MinutesBetween(aEnd,aStart)]);
|
||||||
if Terminated then
|
if Terminated then
|
||||||
Break;
|
Break;
|
||||||
except
|
except
|
||||||
|
@ -110,8 +110,8 @@ Type
|
|||||||
// For search
|
// For search
|
||||||
function DoMySQLResultCommand(const aCmd: String; aOnResult: TMCSearchResultCallBack; aData: Pointer) : Integer;
|
function DoMySQLResultCommand(const aCmd: String; aOnResult: TMCSearchResultCallBack; aData: Pointer) : Integer;
|
||||||
// HTTP-based commands
|
// HTTP-based commands
|
||||||
function CreateHTTPCmdURL(aCmd: String): string;
|
function CreateHTTPCmdURL(aCmd: String; IsSelect: Boolean): string;
|
||||||
function ExecuteHTTPCommand(const aCommand: String): String; virtual;
|
function ExecuteHTTPCommand(const aCommand: String; IsSelect: Boolean): String; virtual;
|
||||||
function ExecuteHTTPCommandResult(const aCmd: String): TJSONArray;
|
function ExecuteHTTPCommandResult(const aCmd: String): TJSONArray;
|
||||||
Procedure DoHTTPSingleColCommand(const aCmd: String; aList : TStrings);
|
Procedure DoHTTPSingleColCommand(const aCmd: String; aList : TStrings);
|
||||||
// For search
|
// For search
|
||||||
@ -152,7 +152,7 @@ Type
|
|||||||
// Delete the source tree in the index.
|
// Delete the source tree in the index.
|
||||||
Procedure DeleteTree(const aTree : String);
|
Procedure DeleteTree(const aTree : String);
|
||||||
// Execute an arbitrary ManticoreSearch command
|
// Execute an arbitrary ManticoreSearch command
|
||||||
procedure ExecuteCommand(const aCommand: String);
|
procedure ExecuteCommand(const aCommand: String; IsSelect: Boolean);
|
||||||
// See if extension is in list of extensions
|
// See if extension is in list of extensions
|
||||||
function AllowExtension(aExtension: String): Boolean;
|
function AllowExtension(aExtension: String): Boolean;
|
||||||
// Index a source file aFile in source tree aTree.
|
// Index a source file aFile in source tree aTree.
|
||||||
@ -203,7 +203,7 @@ Const
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses fphttpclient;
|
uses fphttpclient, httpprotocol;
|
||||||
|
|
||||||
{ TMCToArrayConverter }
|
{ TMCToArrayConverter }
|
||||||
|
|
||||||
@ -520,7 +520,7 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
aData:=Nil;
|
aData:=Nil;
|
||||||
lJSON:=ExecuteHTTPCommand(aCmd);
|
lJSON:=ExecuteHTTPCommand(aCmd,True);
|
||||||
try
|
try
|
||||||
aData:=GetJSON(lJSON);
|
aData:=GetJSON(lJSON);
|
||||||
if aData is TJSONArray then
|
if aData is TJSONArray then
|
||||||
@ -562,33 +562,37 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TManticoreSearchSources.CreateHTTPCmdURL(aCmd : String) : string;
|
function TManticoreSearchSources.CreateHTTPCmdURL(aCmd : String; IsSelect : Boolean) : string;
|
||||||
|
|
||||||
|
|
||||||
Function EscapeHTML(aCmd : string) : String;
|
Function EscapeHTML(aCmd : string) : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=StringReplace(aCmd,' ','%20',[rfReplaceAll]);
|
Result:=HTTPEncode(aCmd);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
Const
|
Const
|
||||||
// BaseURL = 'http://%s:%d/cli?%s';
|
|
||||||
// Use SQL query, to return JSON
|
// Use SQL query, to return JSON
|
||||||
BaseURL = 'http://%s:%d/sql?mode=raw&query=%s';
|
BaseSelectURL = 'http://%s:%d/sql?mode=raw&query=%s';
|
||||||
|
BaseCliURL = 'http://%s:%d/cli?%s';
|
||||||
|
|
||||||
Var
|
Var
|
||||||
lCmd,lHostName : String;
|
lBase,lCmd,lHostName : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
if IsSelect then
|
||||||
|
lBase:=BaseSelectURL
|
||||||
|
else
|
||||||
|
lBase:=BaseCliURL;
|
||||||
lHostName:=HostName;
|
lHostName:=HostName;
|
||||||
if lHostName='' then
|
if lHostName='' then
|
||||||
lHostName:='127.0.0.1';
|
lHostName:='127.0.0.1';
|
||||||
lCmd:=EscapeHTML(aCmd);
|
lCmd:=EscapeHTML(aCmd);
|
||||||
Result:=Format(BaseURL,[lHostName,GetTransportPort(mctHttp),lCmd]);
|
Result:=Format(lBase,[lHostName,GetTransportPort(mctHttp),lCmd]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TManticoreSearchSources.ExecuteHTTPCommand(
|
function TManticoreSearchSources.ExecuteHTTPCommand(const aCommand: String; IsSelect : Boolean) : String;
|
||||||
const aCommand: String) : String;
|
|
||||||
|
|
||||||
Var
|
Var
|
||||||
HTTP : TFPHTTPClient;
|
HTTP : TFPHTTPClient;
|
||||||
@ -599,7 +603,7 @@ begin
|
|||||||
EM:=nil;
|
EM:=nil;
|
||||||
HTTP:=TFPHTTPClient.Create(Self);
|
HTTP:=TFPHTTPClient.Create(Self);
|
||||||
try
|
try
|
||||||
aURL:=CreateHTTPCmdURL(aCommand);
|
aURL:=CreateHTTPCmdURL(aCommand,IsSelect);
|
||||||
DoLog(mlkDebug,'Getting URL: '+aURL);
|
DoLog(mlkDebug,'Getting URL: '+aURL);
|
||||||
Result:=HTTP.Get(aURL);
|
Result:=HTTP.Get(aURL);
|
||||||
except
|
except
|
||||||
@ -611,14 +615,14 @@ begin
|
|||||||
Raise EM;
|
Raise EM;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TManticoreSearchSources.ExecuteCommand(const aCommand: String);
|
procedure TManticoreSearchSources.ExecuteCommand(const aCommand: String; IsSelect : Boolean);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
DoLog(mlkDebug,'Executing command '+aCommand);
|
DoLog(mlkDebug,'Executing command '+aCommand);
|
||||||
if FProtocol=mctMysql then
|
if FProtocol=mctMysql then
|
||||||
ExecuteMySQLCommand(aCommand)
|
ExecuteMySQLCommand(aCommand)
|
||||||
else
|
else
|
||||||
ExecuteHTTPCommand(aCommand);
|
ExecuteHTTPCommand(aCommand, isSelect);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -685,7 +689,7 @@ begin
|
|||||||
Inc(aLineNo);
|
Inc(aLineNo);
|
||||||
ReadLn(F,aLine);
|
ReadLn(F,aLine);
|
||||||
lSQL:=Format(SQL,[IndexName,lTree,lFile,aLineNo,Escape(aLine)]);
|
lSQL:=Format(SQL,[IndexName,lTree,lFile,aLineNo,Escape(aLine)]);
|
||||||
ExecuteCommand(lsql);
|
ExecuteCommand(lsql,False);
|
||||||
end;
|
end;
|
||||||
CloseFile(F);
|
CloseFile(F);
|
||||||
if DoTrans then
|
if DoTrans then
|
||||||
@ -1002,12 +1006,12 @@ begin
|
|||||||
lIndex:=aIndexName;
|
lIndex:=aIndexName;
|
||||||
if lIndex='' then
|
if lIndex='' then
|
||||||
lIndex:=Self.IndexName;
|
lIndex:=Self.IndexName;
|
||||||
ExecuteCommand('CREATE TABLE '+lIndex+' '+GetIndexSQL);
|
ExecuteCommand('CREATE TABLE '+lIndex+' '+GetIndexSQL,False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TManticoreSearchSources.TruncateIndex;
|
procedure TManticoreSearchSources.TruncateIndex;
|
||||||
begin
|
begin
|
||||||
ExecuteCommand('TRUNCATE TABLE '+IndexName);
|
ExecuteCommand('TRUNCATE TABLE '+IndexName,False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TManticoreSearchSources.DeleteIndex;
|
procedure TManticoreSearchSources.DeleteIndex;
|
||||||
@ -1017,7 +1021,7 @@ end;
|
|||||||
|
|
||||||
procedure TManticoreSearchSources.DeleteIndex(const aIndexName : string);
|
procedure TManticoreSearchSources.DeleteIndex(const aIndexName : string);
|
||||||
begin
|
begin
|
||||||
ExecuteCommand('DROP TABLE '+aIndexName);
|
ExecuteCommand('DROP TABLE '+aIndexName,False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -1063,7 +1067,7 @@ end;
|
|||||||
|
|
||||||
procedure TManticoreSearchSources.DeleteTree(const aTree: String);
|
procedure TManticoreSearchSources.DeleteTree(const aTree: String);
|
||||||
begin
|
begin
|
||||||
ExecuteCommand('DELETE FROM '+IndexName+' where (tree='''+Escape(aTree)+''');');
|
ExecuteCommand('DELETE FROM '+IndexName+' where (tree='''+Escape(aTree)+''');',False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -107,7 +107,7 @@ Resourcestring
|
|||||||
lrsSave = 'Yes, save settings';
|
lrsSave = 'Yes, save settings';
|
||||||
lrsIndexOperationFailed = 'Failed to start index operation.';
|
lrsIndexOperationFailed = 'Failed to start index operation.';
|
||||||
lrsCannotIndexIndexInProgress = 'Cannot start an index operation while another one is in progress.';
|
lrsCannotIndexIndexInProgress = 'Cannot start an index operation while another one is in progress.';
|
||||||
lrsFinishedIndexingTree = 'Finished indexing tree "%s". Processed %d files.';
|
lrsFinishedIndexingTree = 'Finished indexing tree "%s". Processed %d files in %d minutes.';
|
||||||
lrsStartIndexingTree = 'Start indexing tree "%s", directory: "%s"';
|
lrsStartIndexingTree = 'Start indexing tree "%s", directory: "%s"';
|
||||||
lrsIndexingTreeFileCount = 'Tree "%s", indexed file count: %d';
|
lrsIndexingTreeFileCount = 'Tree "%s", indexed file count: %d';
|
||||||
lrsFinishedIndexingProject = 'Finished indexing project "%s". Processed %d files.';
|
lrsFinishedIndexingProject = 'Finished indexing project "%s". Processed %d files.';
|
||||||
|
@ -161,7 +161,7 @@ msgstr ""
|
|||||||
|
|
||||||
#: instantsearchstrings.lrsfinishedindexingtree
|
#: instantsearchstrings.lrsfinishedindexingtree
|
||||||
#, object-pascal-format
|
#, object-pascal-format
|
||||||
msgid "Finished indexing tree \"%s\". Processed %d files."
|
msgid "Finished indexing tree \"%s\". Processed %d files in %d minutes."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: instantsearchstrings.lrshost
|
#: instantsearchstrings.lrshost
|
||||||
|
@ -184,8 +184,9 @@ msgid "Finished indexing project \"%s\". Processed %d files."
|
|||||||
msgstr "Индексирование проекта \"%s\" завершено. Обработано файлов: %d."
|
msgstr "Индексирование проекта \"%s\" завершено. Обработано файлов: %d."
|
||||||
|
|
||||||
#: instantsearchstrings.lrsfinishedindexingtree
|
#: instantsearchstrings.lrsfinishedindexingtree
|
||||||
#, object-pascal-format
|
#, object-pascal-format, fuzzy, badformat
|
||||||
msgid "Finished indexing tree \"%s\". Processed %d files."
|
#| msgid "Finished indexing tree \"%s\". Processed %d files."
|
||||||
|
msgid "Finished indexing tree \"%s\". Processed %d files in %d minutes."
|
||||||
msgstr "Индексирование дерева \"%s\" завершено. Обработано файлов: %d."
|
msgstr "Индексирование дерева \"%s\" завершено. Обработано файлов: %d."
|
||||||
|
|
||||||
#: instantsearchstrings.lrshost
|
#: instantsearchstrings.lrshost
|
||||||
|
Loading…
Reference in New Issue
Block a user