From: Stephen D. <sd...@us...> - 2007-07-10 13:03:32
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv27102/nsd Modified Files: conn.c tclresp.c Log Message: * nsd/conn.c: * nsd/tclresp.c: Move ns_startcontent to tclresp.c. Command isn't documented in ns_return.man -- doesn't this overlap with ns_headers and ns_conn encoding? Index: conn.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/conn.c,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** conn.c 10 Jul 2007 11:53:40 -0000 1.40 --- conn.c 10 Jul 2007 13:03:29 -0000 1.41 *************** *** 1598,1684 **** *---------------------------------------------------------------------- * - * NsTclStartContentObjCmd -- - * - * Set connPtr->sendState to "Content" and set the charset/encoding - * to use for further data. - * - * Results: - * NS_OK/NS_ERROR - * - * Side effects: - * connPtr->sendState and connPtr->encoding may be set. - * - *---------------------------------------------------------------------- - */ - - int - NsTclStartContentObjCmd(ClientData arg, Tcl_Interp *interp, int objc, - Tcl_Obj **objv) - { - NsInterp *itPtr = arg; - Tcl_Encoding encoding = NULL; - char *opt; - int i, status = TCL_OK; - - if (itPtr->conn == NULL) { - Tcl_SetResult(interp, "no current connection", TCL_STATIC); - return TCL_ERROR; - } - - for (i = 1; i < objc && status == TCL_OK; i++) { - opt = Tcl_GetString(objv[i]); - if (STREQ(opt, "-charset")) { - if (encoding != NULL) { - Tcl_AppendResult(interp, Tcl_GetString(objv[0]), - ": charset may only be specified by one flag", - NULL); - status = TCL_ERROR; - } - if (++i >= objc) { - Tcl_AppendResult(interp, Tcl_GetString(objv[0]), - ": missing argument for -charset flag", - NULL); - status = TCL_ERROR; - } - - encoding = Ns_GetCharsetEncoding(Tcl_GetString(objv[i])); - if (encoding == NULL) { - Tcl_AppendResult(interp, Tcl_GetString(objv[0]), - ": could not find an encoding for charset ", - Tcl_GetString(objv[i]), NULL); - status = TCL_ERROR; - } - } else if (STREQ(opt, "-type")) { - if (encoding != NULL) { - Tcl_AppendResult(interp, Tcl_GetString(objv[0]), - ": charset may only be specified by one flag", - NULL); - status = TCL_ERROR; - } - if (++i >= objc) { - Tcl_AppendResult(interp, Tcl_GetString(objv[0]), - ": missing argument for -type flag", NULL); - status = TCL_ERROR; - } - encoding = Ns_GetTypeEncoding(Tcl_GetString(objv[i])); - } else { - Tcl_AppendResult(interp, "usage: ", Tcl_GetString(objv[0]), - " ?-charset charsetname? ?-type content-type?", - NULL); - status = TCL_ERROR; - } - } - - if (status == TCL_OK) { - Ns_ConnSetEncoding(itPtr->conn, encoding); - } - - return status; - } - - - /* - *---------------------------------------------------------------------- - * * NsTclConnLocation -- * --- 1598,1601 ---- Index: tclresp.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/tclresp.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tclresp.c 10 Jul 2007 11:53:40 -0000 1.13 --- tclresp.c 10 Jul 2007 13:03:29 -0000 1.14 *************** *** 103,106 **** --- 103,169 ---- *---------------------------------------------------------------------- * + * NsTclStartContentObjCmd -- + * + * Implements ns_startcontent. Set the connection ready to send + * body data in an appropriate encoding. + * + * Results: + * Standard Tcl result. + * + * Side effects: + * The connections current encoding may be changed. + * See Ns_ConnSetEncoding() for details. + * + *---------------------------------------------------------------------- + */ + + int + NsTclStartContentObjCmd(ClientData arg, Tcl_Interp *interp, int objc, + Tcl_Obj **objv) + { + Ns_Conn *conn; + Tcl_Encoding encoding = NULL; + char *charset = NULL, *type = NULL; + + Ns_ObjvSpec opts[] = { + {"-charset", Ns_ObjvString, &charset, NULL}, + {"-type", Ns_ObjvString, &type, NULL}, + {"--", Ns_ObjvBreak, NULL, NULL}, + {NULL, NULL, NULL, NULL} + }; + if (GetConn(arg, interp, &conn) != TCL_OK + || Ns_ParseObjv(opts, NULL, interp, 1, objc, objv) != NS_OK) { + return TCL_ERROR; + } + + if (charset != NULL && type != NULL) { + Tcl_SetResult(interp, "only one of -charset or -type may be specified", + TCL_STATIC); + return TCL_ERROR; + } + + if (charset != NULL) { + encoding = Ns_GetCharsetEncoding(charset); + if (encoding == NULL) { + Tcl_AppendResult(interp, "no encoding for charset: ", charset, NULL); + return TCL_ERROR; + } + } + if (type != NULL) { + encoding = Ns_GetTypeEncoding(type); + } + + if (encoding != NULL) { + Ns_ConnSetEncoding(conn, encoding); + } + conn->flags |= NS_CONN_SENTHDRS; + + return TCL_OK; + } + + + /* + *---------------------------------------------------------------------- + * * NsTclWriteObjCmd -- * |