| 65 |
function GetErrorMsg: string; |
function GetErrorMsg: string; |
| 66 |
procedure MakeError(Session: TDolibSession; Error: DWORD); |
procedure MakeError(Session: TDolibSession; Error: DWORD); |
| 67 |
procedure DOLIB_LOGIN(Proxy: string; Port: Integer; ID: string; Pass: string); |
procedure DOLIB_LOGIN(Proxy: string; Port: Integer; ID: string; Pass: string); |
| 68 |
|
procedure ForcedDOLIB_LOGIN(Proxy: string; Port: Integer; ID: string; Pass: string); |
| 69 |
public |
public |
| 70 |
constructor Create; |
constructor Create; |
| 71 |
destructor Destroy; override; |
destructor Destroy; override; |
| 72 |
function Connect: boolean; |
function Connect: boolean; |
| 73 |
|
function ForcedConnect: boolean; //2003/12/20までのSSL障害用強制ログイン(12/21以降なら通常ログイン) |
| 74 |
function Disconnect: boolean; |
function Disconnect: boolean; |
| 75 |
property ProxyAddress: string read FProxyAddress write FProxyAddress; |
property ProxyAddress: string read FProxyAddress write FProxyAddress; |
| 76 |
property ProxyPort: integer read FProxyPort write FProxyPort; |
property ProxyPort: integer read FProxyPort write FProxyPort; |
| 129 |
end; |
end; |
| 130 |
end; |
end; |
| 131 |
end; |
end; |
| 132 |
|
function TDolib.ForcedConnect: boolean; //2003/12/20までのSSL障害用強制ログイン(12/21以降なら通常ログイン) |
| 133 |
|
begin |
| 134 |
|
Result := False; |
| 135 |
|
if not Connected then begin |
| 136 |
|
ForcedDOLIB_LOGIN(FProxyAddress, FProxyPort, FUserName, FPassword); |
| 137 |
|
Result := True; |
| 138 |
|
end; |
| 139 |
|
end; |
| 140 |
|
|
| 141 |
function TDolib.Disconnect: boolean; |
function TDolib.Disconnect: boolean; |
| 142 |
begin |
begin |
| 286 |
InternetCloseHandle(hSession); |
InternetCloseHandle(hSession); |
| 287 |
end; |
end; |
| 288 |
end; |
end; |
| 289 |
|
//2003/12/20までのSSL障害用強制ログイン(12/21以降なら通常ログイン) |
| 290 |
|
procedure TDolib.ForcedDOLIB_LOGIN(Proxy: string; Port: Integer; ID: string; Pass: string); |
| 291 |
|
var |
| 292 |
|
hSession: HINTERNET; |
| 293 |
|
hConnect: HINTERNET; |
| 294 |
|
hRequest: HINTERNET; |
| 295 |
|
ProxyHostPort: string; |
| 296 |
|
Buf: array[0..4096] of Char; |
| 297 |
|
UserInfo: string; |
| 298 |
|
UserAgent: string; |
| 299 |
|
cb: DWORD; |
| 300 |
|
Delim: Integer; |
| 301 |
|
begin |
| 302 |
|
FSession := TDolibSession.Create; |
| 303 |
|
|
| 304 |
|
if Proxy <> '' then begin |
| 305 |
|
ProxyHostPort := Format('%s:%d', [Proxy, Port]); |
| 306 |
|
hSession := InternetOpen(DOLIB_LOGIN_UA, INTERNET_OPEN_TYPE_PROXY, PChar(ProxyHostPort), '', 0); |
| 307 |
|
end else begin |
| 308 |
|
hSession := InternetOpen(DOLIB_LOGIN_UA, INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0); |
| 309 |
|
end; |
| 310 |
|
|
| 311 |
|
if not Assigned(hSession) then |
| 312 |
|
MakeError(FSession, GetLastError()) |
| 313 |
|
else begin |
| 314 |
|
hConnect := InternetConnect(hSession, DOLIB_LOGIN_HOST, |
| 315 |
|
INTERNET_DEFAULT_HTTPS_PORT, nil, nil, |
| 316 |
|
INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0); |
| 317 |
|
if not Assigned(hConnect) then |
| 318 |
|
MakeError(FSession, GetLastError()) |
| 319 |
|
else begin |
| 320 |
|
hRequest := HttpOpenRequest(hConnect, 'POST', DOLIB_LOGIN_URL, |
| 321 |
|
nil, nil, nil, |
| 322 |
|
INTERNET_FLAG_NO_CACHE_WRITE or INTERNET_FLAG_NO_COOKIES or |
| 323 |
|
INTERNET_FLAG_NO_UI or INTERNET_FLAG_SECURE, 0); |
| 324 |
|
if not Assigned(hRequest) then |
| 325 |
|
MakeError(FSession, GetLastError()) |
| 326 |
|
else begin |
| 327 |
|
UserInfo := Format('ID=%s&PW=%s', [ID, Pass]); |
| 328 |
|
UserAgent := Format('%s %s', [DOLIB_2CH_UA, ClientUA]) + #13#10; |
| 329 |
|
HttpSendRequest(hRequest, PChar(UserAgent), DWORD(-1), PChar(UserInfo), Length(UserInfo)); |
| 330 |
|
if not InternetReadFile(hRequest, @Buf, SizeOf(Buf), cb) then |
| 331 |
|
MakeError(FSession, GetLastError()) |
| 332 |
|
else if (cb < 11) or (Pos('SESSION-ID=', Buf) <> 1) then |
| 333 |
|
MakeError(FSession, ERROR_INVALID_DATA) |
| 334 |
|
else begin |
| 335 |
|
if Buf[cb - 1] = #10 then |
| 336 |
|
Buf[cb - 1] := #0; |
| 337 |
|
FSession.SessionID := Copy(Buf, 12, cb); |
| 338 |
|
if FSession.SessionID = '' then |
| 339 |
|
MakeError(FSession, ERROR_NOT_ENOUGH_MEMORY); |
| 340 |
|
Delim := Pos(':', Buf); |
| 341 |
|
if Delim = 0 then |
| 342 |
|
MakeError(FSession, ERROR_INVALID_DATA) |
| 343 |
|
else begin |
| 344 |
|
FSession.UserAgent := Copy(Buf, 12, Delim - 12); |
| 345 |
|
if FSession.UserAgent = '' then |
| 346 |
|
MakeError(FSession, ERROR_NOT_ENOUGH_MEMORY); |
| 347 |
|
end; |
| 348 |
|
end; |
| 349 |
|
InternetCloseHandle(hRequest); |
| 350 |
|
end; |
| 351 |
|
InternetCloseHandle(hConnect); |
| 352 |
|
end; |
| 353 |
|
InternetCloseHandle(hSession); |
| 354 |
|
end; |
| 355 |
|
end; |
| 356 |
end. |
end. |
| 357 |
|
|