Re: [AOLSERVER] problem getting binary data from C to a tcl object to an aolserver connection
Hi Stephen, What does ns_conn write_encoded false do (although it is somewhat self explanatory)? Also ns_startcontent is neat - saves me manually fudging the header with ns_write. On Fri, Aug 29, 2008 at 5:52 AM, Stephen Deasey <[EMAIL PROTECTED]> wrote: > On Thu, Aug 28, 2008 at 9:50 AM, Mark Aufflick > <[EMAIL PROTECTED]> wrote: >> Hi all, >> >> If I Ns_Log() the data in a (char *) I can clearly see that it >> contains newlines, and I can also verify that it contains nulls with >> memchr. >> >> I have tried any number of ways to turn it into a tcl object, eg: >> >>objPtr = Tcl_NewByteArrayObj(str, length); > > > This is the right way to do it. > > >> Whether the tcl code then does an ns_log, ns_return (which I >> know isn't supposed to be binary safe) or ns_write, i get all the >> newlines converted into \n (ie. two characters \ then n) and chunks of >> binary get converted to unicode characters. > > > In AOLserver 4.5, ns_write is the only command that accepts a binary data. > > You also need to be careful you don't accidentally change it's type > once you've created it. > >set blob [myblobcmd] >set length [string length $blob] ># blob now garbled utf8 :-( > > >> I can see from Tcl_AppendToObj that that is supposed to happen there, >> but how can I output a byte array object without it being converted to >> utf8? > > > Something like... > >ns_startcontent -type application/octet-stream >ns_conn write_encoded false >ns_write $blob > > > -- > AOLserver - http://www.aolserver.com/ > > To Remove yourself from this list, simply send an email to <[EMAIL > PROTECTED]> with the > body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: > field of your email blank. > -- Mark Aufflick contact info at http://mark.aufflick.com/about/contact -- AOLserver - http://www.aolserver.com/ To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.
Re: [AOLSERVER] problem getting binary data from C to a tcl object to an aolserver connection
On Fri, Aug 29, 2008 at 3:18 AM, Mark Aufflick <[EMAIL PROTECTED]> wrote: > Hi Stephen, > > What does ns_conn write_encoded false do (although it is somewhat self > explanatory)? With the write_encoded flag set (which ns_startcontent sets) ns_write will assume you're sending character data and will want to encode it into iso-8859-1, or whatever is configured. With the write_encoded flag off, ns_write will use Tcl_GetByteArrayFromObj() rather than Tcl_GetStringFromObj(), and because you used Tcl_NewByteArrayObj() in your C code, your bytes will pass through unmolested. -- AOLserver - http://www.aolserver.com/ To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.
Re: [AOLSERVER] problem getting binary data from C to a tcl object to an aolserver connection
On Thu, Aug 28, 2008 at 9:50 AM, Mark Aufflick <[EMAIL PROTECTED]> wrote: > Hi all, > > If I Ns_Log() the data in a (char *) I can clearly see that it > contains newlines, and I can also verify that it contains nulls with > memchr. > > I have tried any number of ways to turn it into a tcl object, eg: > >objPtr = Tcl_NewByteArrayObj(str, length); This is the right way to do it. > Whether the tcl code then does an ns_log, ns_return (which I > know isn't supposed to be binary safe) or ns_write, i get all the > newlines converted into \n (ie. two characters \ then n) and chunks of > binary get converted to unicode characters. In AOLserver 4.5, ns_write is the only command that accepts a binary data. You also need to be careful you don't accidentally change it's type once you've created it. set blob [myblobcmd] set length [string length $blob] # blob now garbled utf8 :-( > I can see from Tcl_AppendToObj that that is supposed to happen there, > but how can I output a byte array object without it being converted to > utf8? Something like... ns_startcontent -type application/octet-stream ns_conn write_encoded false ns_write $blob -- AOLserver - http://www.aolserver.com/ To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.
Re: [AOLSERVER] problem getting binary data from C to a tcl object to an aolserver connection
Mark, Hard to say what you are actually trying to do, but UTF-8 is a byte array, if you want to call it that. The problem you are seeing may be in displaying what the bytes are (which might not work for binary data, try cat'ing a binary file and watch the fireworks.) tom jackson On Thu, 2008-08-28 at 18:50 +1000, Mark Aufflick wrote: > Hi all, > > If I Ns_Log() the data in a (char *) I can clearly see that it > contains newlines, and I can also verify that it contains nulls with > memchr. > > I have tried any number of ways to turn it into a tcl object, eg: > > objPtr = Tcl_NewByteArrayObj(str, length); > > or > > objPtr = Tcl_NewObj(); > Tcl_AppendToObj(objPtr, str, length); > > or > > objPtr = Tcl_NewStringObj(str, length); > > etc. > > this is then set as the result object, and control returns to the tcl > code. Whether the tcl code then does an ns_log, ns_return (which I > know isn't supposed to be binary safe) or ns_write, i get all the > newlines converted into \n (ie. two characters \ then n) and chunks of > binary get converted to unicode characters. > > I can see from Tcl_AppendToObj that that is supposed to happen there, > but how can I output a byte array object without it being converted to > utf8? > > Any help appreciated - this is driving me nuts :) > > -- AOLserver - http://www.aolserver.com/ To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.
[AOLSERVER] problem getting binary data from C to a tcl object to an aolserver connection
Hi all, If I Ns_Log() the data in a (char *) I can clearly see that it contains newlines, and I can also verify that it contains nulls with memchr. I have tried any number of ways to turn it into a tcl object, eg: objPtr = Tcl_NewByteArrayObj(str, length); or objPtr = Tcl_NewObj(); Tcl_AppendToObj(objPtr, str, length); or objPtr = Tcl_NewStringObj(str, length); etc. this is then set as the result object, and control returns to the tcl code. Whether the tcl code then does an ns_log, ns_return (which I know isn't supposed to be binary safe) or ns_write, i get all the newlines converted into \n (ie. two characters \ then n) and chunks of binary get converted to unicode characters. I can see from Tcl_AppendToObj that that is supposed to happen there, but how can I output a byte array object without it being converted to utf8? Any help appreciated - this is driving me nuts :) -- Mark Aufflick contact info at http://mark.aufflick.com/about/contact -- AOLserver - http://www.aolserver.com/ To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of your email blank.