Fix suggestion madExcept.pas method HttpUpload

delphi package - automated exception handling
Post Reply
wpostma
Posts: 23
Joined: Fri Oct 12, 2012 4:09 pm

Fix suggestion madExcept.pas method HttpUpload

Post by wpostma »

The function HttpUpload has what seems to me a mistake. Hard coded string '' (empty string) is used instead of settings.

Comment below marked FIX shows where empty string is changed to use the appropriate Setting value.

The line here in HttpUpload is the one I've modified:

Code: Select all

  with TWinHttp.Create(httpUrl, ssl, port, false, '', '', userName, password, proxyServer, proxyBypass, proxyUserName, proxyPassword, stngs, pa) do begin
Modified function, formatted so you can read it:

Code: Select all

function HttpUpload(const httpUrl       : AnsiString;
                          ssl           : boolean;
                          port          : dword;
                    const userName      : UnicodeString;
                    const password      : UnicodeString;
                    const attachments   : IMEAttachments;
                    const fields        : IMEFields      = nil;
                    const mailFrom      : UnicodeString  = '';
                          parentWindow  : HWND           = 0;
                          hidden        : boolean        = false;
                          background    : boolean        = false;
                    const settings      : IMESettings    = nil  ) : boolean;
var attachFiles                : TDAUnicodeString;
    attachSendAs, attachFields : TDAUnicodeString;
    pa                         : IProgressAlert;
    stngs                      : IMESettings;
begin
  if settings <> nil then
    stngs := settings
  else
    stngs := {$ifdef xe2} MESettings(ReturnAddress); {$else} MESettingsEx(1); {$endif}
  attachSendAs := nil;
  attachFields := nil;
  pa := PrepareAttachments(stngs, attachments, attachFiles, attachSendAs, attachFields, parentwindow, hidden, background);
  with TWinHttp.Create(httpUrl, ssl, port, false,
              {FIX: why hard code an empty string? }stngs.HttpAccount,
              {FIX: why hard code an empty string? }stngs.HttpPassword,
              userName,
              password,
              proxyServer, proxyBypass, proxyUserName, proxyPassword, stngs, pa) do begin
    result := Post(mailFrom, fields, attachFiles, attachSendAs, attachFields);
    Free;
  end;
end;
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Fix suggestion madExcept.pas method HttpUpload

Post by madshi »

Hi Warren,

hmmmm... You have a point there. There is a small conflict of interest there, though: Basically the HttpUpload() function already has a userName and password parameter, too. I believe they're passed to TWinHttp.Create() at the wrong position, though. The empty strings are definitely wrong. But shouldn't we use the userName and password parameters there instead of stngs.HttpAccount/Password? It's a bit complex, allowing parameters which are also already part of the settings interface...
wpostma
Posts: 23
Joined: Fri Oct 12, 2012 4:09 pm

Re: Fix suggestion madExcept.pas method HttpUpload

Post by wpostma »

There are TWO user and passwords. One is for HTTP Auth, and one is for BUG System Logins. This is the source of Your (and my) confusion.

Warren
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Fix suggestion madExcept.pas method HttpUpload

Post by madshi »

Yes, but even after having cleared that confusion, there's still a user/password in the HttpUpload function parameters, and another one in the IMESettings interface. So which one should I use?
Post Reply