How about this, i tested it :

int
NsTclReturnObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
    Ns_Conn *conn;
    unsigned char *data = 0, *type = 0;
    int i, result, status = 0, len = 0, binary = 0;

    for (i = 1;i < objc;i++) {
      if (!strcmp(Tcl_GetString(objv[i]),"-binary")) {
          binary = 1;

      } else if (status == 0) {
          if (Tcl_GetIntFromObj(interp, objv[i], &status) != TCL_OK) {
              return TCL_ERROR;
          }

      } else if (type == NULL) {
          type = Tcl_GetString(objv[i]);

      } else if (data == NULL) {
          if (binary != 0) {
              data = Tcl_GetByteArrayFromObj(objv[i], &len);
          } else {
              data = Tcl_GetStringFromObj(objv[i], &len);
          }
      }
    }
    if (data == NULL || type == NULL || status == 0) {
        Tcl_WrongNumArgs(interp, 1, objv, "?-binary? status type string");
        return TCL_ERROR;
    }
    if (GetConn(arg, interp, &conn) != TCL_OK) {
        return TCL_ERROR;
    }
    if(binary != 0) {
       result = Ns_ConnReturnData(conn, status, data, len, type);
    } else {
       result = Ns_ConnReturnCharData(conn, status, data, len, type);
    }
    return Result(interp, result);
}


Vlad Seryakov wrote:
I thought about ns_return -binary as well. first -binary flag is optional so it will be compatible with the old API. Let me try this.

Zoran Vasiljevic wrote:


Am 10.06.2005 um 15:41 schrieb Vlad Seryakov:

* Tcl_GetByteArrayFromObj --
*
*      Attempt to get the array of bytes from the Tcl object.  If the
*      object is not already a ByteArray object, an attempt will be
*      made to convert it to one.

So, if i call ns_return from Tcl and pass data parameter, it will be always type of String. ByteArrays are created from Tcl by binary command only, other commands work with String types, so i need to tell ns_return to treat data as bytearray. Tcl string can contain binary data but it is still String and that check will never work for binary data.


I'm afraid you are right. I also have my own (binary-aware) ns_return somewhere
in my toolbox but never thought it would be of general interest.

OTOH, the "ns_return -binary" would look nicer but I do not
know if we'd be backwardly-compatible (guess not).

Zoran



-------------------------------------------------------
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=20
_______________________________________________
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