Skip to content
TG007 community snippet #164

Download methods by xorc

v2 Signal polling microsoft.xmlhttp (COM): Calls microsoft.xmlhttp comobject asynchronous and dispatches a signal to check the result, which if isn't done yet signals itself again until the response is received, then calls the provided

By Snippets Added Dec 7, 2023
General IRC All snippets
mIRC script 61 lines
About this snippet

Overview

v2 Signal polling microsoft.xmlhttp (COM):
Calls microsoft.xmlhttp comobject asynchronous and dispatches a signal to check the result, which if isn't done yet signals itself again until the response is received, then calls the provided callback when the contents is written to disk.

Performance / Example:
//echo ticks: $ticks | /XMLHTTPRequest "echo ticks: $($ticks,0) result:" http://www.google.com/ google.html
time: 12:57:24 ticks: 51840640
time: 12:57:24 ticks: 51840687 result: XMLHTTPRequest1393273344 $true http://www.google.com/ google.html
Elapsed 47 ticks
Source code

mIRC script

61 lines · 1,409 characters
alias XMLHTTPRequest {

  var %callback = $1
  var %URI = $2
  var %path = $3

  if (" isin $1) {
    var %callback = $mid($1-,1,$pos($1-,",2))
    var %args = $replace($1-,%callback,)
    tokenize 32 %args
    unset %args

    var %callback = $noqt(%callback)
    var %URI = $1
    var %path = $2
  }

  var %comid = $+(XMLHTTPRequest,$hash($nopath(%path),32))

  if ($com(%comid)) .comclose %comid
  .comopen %comid microsoft.xmlhttp

  noop $com(%comid,Open,4,bstr,GET,bstr,%URI,bool,1)
  noop $com(%comid,Send,1)

  $+(.,timer,%comid) 1 0 .signal -n %comid $qt(%callback) %URI %path
  $+(.,timer,%comid,timeout,timer) 1 10 .timer $+ %comid off 
  $+(.,timer,%comid,timeout,com) 1 10 .comclose %comid
}

on *:SIGNAL:XMLHTTPRequest*: {

  var %comid = $signal
  var %callback = $1
  var %URI = $2
  var %path = $3

  if (" isin $1) {
    var %callback = $mid($1-,1,$pos($1-,",2))
    var %args = $replace($1-,%callback,)
    tokenize 32 %args
    unset %args

    var %callback = $noqt(%callback)
    var %URI = $1
    var %path = $2
  }

  goto $com(%comid,responseText,2)

  :-1 | %callback %comid $false %URI %path | halt
  :0 | $+(.,timer,%comid) 1 0 .signal -n %comid $qt(%callback) %URI %path | halt
  :1
  $+(.,timer,%comid,*) off

  bwrite $5 0 $com(%comid,&binvar).result &binvar

  .comclose %comid

  %callback %comid $true %URI %path
}
Community

Comments

Want to join the discussion? Sign in to TG007.
No comments yet. Start the discussion.