ns_respond now supports binary so ns_returnbinary is redundant, but i think Tcl_GetByteArray works with string and byte array, just Tcl_GetByteArray does not do eny encoding/converting to/From utf.

Stephen Deasey wrote:
Before you cvs commit, you must make test. Two tests are broken... We're strugeling for tests, but tclresp.c is one file that does have a reasonably complete set. Can you add some for the new commands? Also, the cut 'n paste comment for Ns_ObjvByteArray is no longer
correct.

I was wondering, is ns_returnbinary necessary?  What if ns_return was
modified to check the type of it's data arg, and if it's byterray,
send using Ns_ConnReturnData.  Would this work?




On 6/8/05, Vlad Seryakov <[EMAIL PROTECTED]> wrote:

Update of /cvsroot/naviserver/naviserver/nsd
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15813/nsd

Modified Files:
       tclobjv.c tclresp.c
Log Message:
Added -binary flag to ns_respond to return binary data without encoding 
conversion


Index: tclobjv.c
===================================================================
RCS file: /cvsroot/naviserver/naviserver/nsd/tclobjv.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** tclobjv.c   15 May 2005 07:47:21 -0000      1.7
--- tclobjv.c   8 Jun 2005 20:27:12 -0000       1.8
***************
*** 310,313 ****
--- 310,352 ----
  *----------------------------------------------------------------------
  *
+  * Ns_ObjvByteArray --
+  *
+  *      Consume exactly one argument, returning a pointer to it's
+  *      cstring into *spec->dest.
+  *
+  *      If spec->arg is != NULL it is assumed to be a pointer to an
+  *      int and the returned string length will be left in it.
+  *
+  * Results:
+  *      TCL_OK or TCL_ERROR.
+  *
+  * Side effects:
+  *        None.
+  *
+  *----------------------------------------------------------------------
+  */
+
+ int
+ Ns_ObjvByteArray(Ns_ObjvSpec *spec, Tcl_Interp *interp, int *objcPtr,
+               Tcl_Obj *CONST objv[])
+ {
+     unsigned char **dest = spec->dest;
+
+     if (*objcPtr > 0) {
+         if (spec->arg == NULL) {
+             *dest = Tcl_GetByteArrayFromObj(objv[0],0);
+         } else {
+             *dest = Tcl_GetByteArrayFromObj(objv[0], (int *) spec->arg);
+         }
+         *objcPtr -= 1;
+         return TCL_OK;
+     }
+     return TCL_ERROR;
+ }
+
+
+ /*
+  *----------------------------------------------------------------------
+  *
  * Ns_ObjvObj --
  *

Index: tclresp.c
===================================================================
RCS file: /cvsroot/naviserver/naviserver/nsd/tclresp.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** tclresp.c   8 Jun 2005 20:13:12 -0000       1.4
--- tclresp.c   8 Jun 2005 20:27:12 -0000       1.5
***************
*** 252,256 ****
     Ns_Conn     *conn;
     int          status = 200, length = -1;
!     char        *type = "*/*", *setid = NULL;
     char        *string = NULL, *filename = NULL, *chanid = NULL;
     Ns_Set      *set = NULL;
--- 252,256 ----
     Ns_Conn     *conn;
     int          status = 200, length = -1;
!     char        *type = "*/*", *setid = NULL, *binary = NULL;
     char        *string = NULL, *filename = NULL, *chanid = NULL;
     Ns_Set      *set = NULL;
***************
*** 259,269 ****

     Ns_ObjvSpec opts[] = {
!         {"-status",   Ns_ObjvInt,    &status,   NULL},
!         {"-type",     Ns_ObjvString, &type,     NULL},
!         {"-length",   Ns_ObjvInt,    &length,   NULL},
!         {"-headers",  Ns_ObjvString, &setid,    NULL},
!         {"-string",   Ns_ObjvString, &string,   NULL},
!         {"-file",     Ns_ObjvString, &filename, NULL},
!         {"-fileid",   Ns_ObjvString, &chanid,   NULL},
         {NULL, NULL, NULL, NULL}
     };
--- 259,270 ----

     Ns_ObjvSpec opts[] = {
!         {"-status",   Ns_ObjvInt,       &status,   NULL},
!         {"-type",     Ns_ObjvString,    &type,     NULL},
!         {"-length",   Ns_ObjvInt,       &length,   NULL},
!         {"-headers",  Ns_ObjvString,    &setid,    NULL},
!         {"-string",   Ns_ObjvString,    &string,   NULL},
!         {"-file",     Ns_ObjvString,    &filename, NULL},
!         {"-fileid",   Ns_ObjvString,    &chanid,   NULL},
!         {"-binary",   Ns_ObjvByteArray, &binary,   &length},
         {NULL, NULL, NULL, NULL}
     };
***************
*** 277,282 ****
         return TCL_ERROR;
     }
!     if ((string != NULL) + (filename != NULL) + (chanid != NULL) != 1) {
!         Tcl_SetResult(interp, "must specify only one of -string, -file "
                       "or -fileid", TCL_STATIC);
         return TCL_ERROR;
--- 278,283 ----
         return TCL_ERROR;
     }
!     if ((binary != NULL) + (string != NULL) + (filename != NULL) + (chanid != 
NULL) != 1) {
!         Tcl_SetResult(interp, "must specify only one of -string, -file, -binary 
"
                       "or -fileid", TCL_STATIC);
         return TCL_ERROR;
***************
*** 313,316 ****
--- 314,324 ----
         retval = Ns_ConnReturnFile(conn, status, type, filename);

+     } else if (binary != NULL) {
+         /*
+          * We'll be returning a binary data
+          */
+
+         retval = Ns_ConnReturnData(conn, status, binary, length, type);
+
     } else {
         /*



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy. Play to win an NEC 61" plasma display: http://www.necitguy.com/?r _______________________________________________
naviserver-devel mailing list
naviserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/naviserver-devel

--
Vlad Seryakov
571 262-8608 office
[EMAIL PROTECTED]
http://www.crystalballinc.com/vlad/

Reply via email to