mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Code:
on *:SOCKREAD:membership: {
  if ($sockerr) halt
  else {
    while ($sock($sockname).rq) {
      sockread &binvar
      bwrite membership.xml -1 -1 &binvar
    }
  }
}


Problem is that membership.xml also contains the reply headers

Quote:

HTTP/1.1 200 OK
Date: Fri, 11 Sep 2009 17:54:29 GMT
Server: Microsoft-IIS/6.0
P3P:CP="BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo"
X-Powered-By: ASP.NET
X-MSNSERVER: BY2ABCHWB212
X-AspNet-Version: 2.0.50727
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 1340027
crlf here


how do i stop that from being written to the xml file?

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
According to the HTTP RFC (you read the protocol specs, didn't you?) the headers end (and the body begins) after two consecutive newlines are read-- which basically means at some point you'll be /sockreading an empty line. Is that hint enough?


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Set a variable when you read the CRLF...

Code:
on *:SOCKREAD:membership: {
  if ($sockerr) halt
  else {
    while ($sock($sockname).rq) {
      sockread &binvar
      if (%now) bwrite membership.xml -1 -1 &binvar
      elseif ($bvar(&binvar,1-) == 13 10) set %now $true
    }
  }
}


You need to make sure you unset the %now variable later though... your best bet is probably to do it in the sockclose event, or whenever you close the socket.

Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Thanks hixxy. I tried that code but it isn't writing anything or creating the xml file now

Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
I do as hixxy suggests.

I look for something that will tell me the next bit is the part I want to save, then I set a vriable.

Then I say, if (%variable) save this bit of the string.

Then I unset the variable. I may have to set a couple diff variables for different parts.

Or I can use $bfind and grab the bits of the string I want and save them as local variables or in a hash table depending on length.

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Code:
on *:SOCKREAD:sock: {
  if ($sock($sockname).mark) {
    sockread &bvar
    if ($sockbr == 0) return
    ; do stuff with &bvar
  }
  else {
    var %line
    sockread %line
    if (%line == $null) sockmark $sockname $true
  }
}


Unless you specifically need binary support (why you'd need it for XML I'm not too sure), you should probably be reading with regular vars though.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Code:
on *:SOCKREAD:membership: {
  sockread %sock
  if ($sockbr == 0) return
  if ($sock($sockname).mark) {
    write membership.xml %sock
  }
  elseif (%sock == $null) {
    sockmark $sockname $true
  }
}


That works but problem now is when i try to view the xml in the i.e browser i get the error

Quote:

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Whitespace is not allowed at this location. Error processing resource 'file:///C:/Documents and Settings/admin/My Documents...

<JoinedDate>0001-01-01T00:00:00-08:00</JoinedDate><ExpirationDate>0001-01-01T00:00:00</ExpirationDate&g...



Previously i used to remove the header stuff from the file manually and then open it in the browser and it used to work fine..

Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
"Whitespace is not allowed at this location" is the error. Figure out where that whitespace is and why you're writing one.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Code:
on *:SOCKREAD:membership: {
  if ($sockerr) halt
  else {
    while ($sock($sockname).rq) {
      sockread &binvar
      bwrite membership.xml -1 -1 &binvar
    }
  }
}


How would i edit that to halt on crlfs?

Joined: Jul 2008
Posts: 236
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Jul 2008
Posts: 236
you could try reading...

As specifically stated, you don't need to work with binary variables here. I agree with argv, mostly. As usual his code could enjoy a few touches, though:

Code:
on *:SOCKREAD:sock: {
  if ($sockerr > 0) { return }
  while ($parseline > 0) {
    noop
  }
}

alias parseline {
  sockread %line
  if ($sockbr == 0) return 0

  if ($sock($sockname).mark) {
    write file.xml $1-
  }
  else if (%line == $null) sockmark $sockname $true

  return $sockbr
}


The error as you pasted it shows the problem already:
Quote:
<JoinedDate>0001-01-01T00:00:00-08:00</JoinedDate><ExpirationDate>0001-01-01T00:00:00</ExpirationDate&g...


... What's that &g... in there? wink I'm guessing &gt; you're going to need to unescape things like that, of course.

Last edited by s00p; 22/09/09 05:40 PM.

Link Copied to Clipboard