simpler clistr interface which handles individual packets having
authorAndrew Tridgell <tridge@samba.org>
Wed, 14 Mar 2001 12:42:43 +0000 (12:42 +0000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 14 Mar 2001 12:42:43 +0000 (12:42 +0000)
unicode bit set differently to capabilities

source/include/proto.h
source/libsmb/clifile.c
source/libsmb/clilist.c
source/libsmb/clistr.c
source/libsmb/clitrans.c

index 79235bbae0a6c244f9ab68d7df5e250551a63d38..e666f23ece33fd0c9824a8ccda544306c0370f6d 100644 (file)
@@ -401,10 +401,8 @@ uint32 cli_spoolss_getprinter(struct cli_state *cli, POLICY_HND *pol,
 /*The following definitions come from  libsmb/clistr.c  */
 
 int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len, int flags);
-int clistr_push_size(struct cli_state *cli, const void *dest, const char *src, int dest_len, int flags);
 int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len, int flags);
-int clistr_pull_size(struct cli_state *cli, const void *src, int src_len);
-int clistr_align(struct cli_state *cli, int offset);
+int clistr_align(const void *buf, const void *p);
 
 /*The following definitions come from  libsmb/clitrans.c  */
 
index 8742a576cf38f7053e3d926a63bb787e1f682458..79a168121b7dcdaf85513b9cf89922dea92ef6d7 100644 (file)
@@ -198,7 +198,7 @@ int cli_nt_create(struct cli_state *cli, char *fname, uint32 DesiredAccess)
 
        p = smb_buf(cli->outbuf);
        /* this alignment and termination is critical for netapp filers. Don't change */
-       p += clistr_align(cli, PTR_DIFF(p, cli->outbuf));
+       p += clistr_align(cli->outbuf, p);
        len = clistr_push(cli, p, fname, -1, STR_CONVERT);
        p += len;
        SSVAL(cli->outbuf,smb_ntcreate_NameLength, len);
index f0ca0d5f5487619ecf3b68119727f7e02a9f59ed..0033f0594255fc934867141fd0fcaf08ad51dc36 100644 (file)
@@ -194,10 +194,6 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
                        break;
                }
 
-               param_len = 12+clistr_push_size(cli, NULL, mask, -1, 
-                                               STR_TERMINATE |
-                                               STR_CONVERT);
-
                if (First) {
                        setup = TRANSACT2_FINDFIRST;
                        SSVAL(param,0,attribute); /* attribute */
@@ -205,8 +201,9 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
                        SSVAL(param,4,4+2);     /* resume required + close on end */
                        SSVAL(param,6,info_level); 
                        SIVAL(param,8,0);
-                       clistr_push(cli, param+12, mask, -1, 
-                                   STR_TERMINATE | STR_CONVERT);
+                       p = param+12;
+                       p += clistr_push(cli, param+12, mask, -1, 
+                                        STR_TERMINATE | STR_CONVERT);
                } else {
                        setup = TRANSACT2_FINDNEXT;
                        SSVAL(param,0,ff_dir_handle);
@@ -214,10 +211,13 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
                        SSVAL(param,4,info_level); 
                        SIVAL(param,6,0); /* ff_resume_key */
                        SSVAL(param,10,8+4+2);  /* continue + resume required + close on end */
-                       clistr_push(cli, param+12, mask, -1, 
-                                   STR_TERMINATE | STR_CONVERT);
+                       p = param+12;
+                       p += clistr_push(cli, param+12, mask, -1, 
+                                        STR_TERMINATE | STR_CONVERT);
                }
 
+               param_len = PTR_DIFF(p, param);
+
                if (!cli_send_trans(cli, SMBtrans2, 
                                    NULL,                   /* Name */
                                    -1, 0,                  /* fid, flags */
index c0e7231d7a79ef25698e8f97884d660e5a4f77fa..feed10fa4ea026f089e6a43d150f933c61f9a527 100644 (file)
@@ -45,14 +45,14 @@ int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len
                dest_len = sizeof(pstring);
        }
 
-       if (!(flags & STR_ASCII) && clistr_align(cli, PTR_DIFF(dest, cli->outbuf))) {
+       if (!(flags & STR_ASCII) && clistr_align(cli->outbuf, dest)) {
                *(char *)dest = 0;
                dest++;
                dest_len--;
                len++;
        }
 
-       if ((flags & STR_ASCII) || !(cli->capabilities & CAP_UNICODE)) {
+       if ((flags & STR_ASCII) || !(SVAL(cli->outbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS)) {
                /* the server doesn't want unicode */
                safe_strcpy(dest, src, dest_len);
                len = strlen(dest);
@@ -76,27 +76,6 @@ int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len
        return len;
 }
 
-
-/****************************************************************************
-return the length that a string would occupy when copied with clistr_push()
-  STR_TERMINATE means include the null termination
-  STR_CONVERT   means convert from unix to dos codepage
-  STR_UPPER     means uppercase in the destination
-note that dest is only used for alignment purposes. No data is written.
-****************************************************************************/
-int clistr_push_size(struct cli_state *cli, const void *dest, const char *src, int dest_len, int flags)
-{
-       int len = strlen(src);
-       if (flags & STR_TERMINATE) len++;
-       if (!(flags & STR_ASCII) && (cli->capabilities & CAP_UNICODE)) len *= 2;
-
-       if (!(flags & STR_ASCII) && dest && clistr_align(cli, PTR_DIFF(cli->outbuf, dest))) {
-               len++;
-       }
-
-       return len;
-}
-
 /****************************************************************************
 copy a string from a unicode or ascii source (depending on
 cli->capabilities) to a char* destination
@@ -116,12 +95,12 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len
                dest_len = sizeof(pstring);
        }
 
-       if (clistr_align(cli, PTR_DIFF(src, cli->inbuf))) {
+       if (clistr_align(cli->inbuf, src)) {
                src++;
                if (src_len > 0) src_len--;
        }
 
-       if (!(flags & STR_UNICODE) && !(cli->capabilities & CAP_UNICODE)) {
+       if (!(flags & STR_UNICODE) && !(SVAL(cli->inbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS)) {
                /* the server doesn't want unicode */
                if (flags & STR_TERMINATE) {
                        safe_strcpy(dest, src, dest_len);
@@ -153,31 +132,14 @@ int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len
        return len;
 }
 
-/****************************************************************************
-return the length that a string would occupy (not including the null)
-when copied with clistr_pull()
-if src_len is -1 then assume the source is null terminated
-****************************************************************************/
-int clistr_pull_size(struct cli_state *cli, const void *src, int src_len)
-{
-       if (clistr_align(cli, PTR_DIFF(src, cli->inbuf))) {
-               src++;
-               if (src_len > 0) src_len--;
-       }
-
-       if (!(cli->capabilities & CAP_UNICODE)) {
-               return strlen(src);
-       }       
-       return strlen_w(src);
-}
 
 /****************************************************************************
 return an alignment of either 0 or 1
 if unicode is not negotiated then return 0
 otherwise return 1 if offset is off
 ****************************************************************************/
-int clistr_align(struct cli_state *cli, int offset)
+int clistr_align(const void *buf, const void *p)
 {
-       if (!(cli->capabilities & CAP_UNICODE)) return 0;
-       return offset & 1;
+       if (!(SVAL(buf, smb_flg2) & FLAGS2_UNICODE_STRINGS)) return 0;
+       return PTR_DIFF(p, buf) & 1;
 }
index 0bbe7c6dae80936b90261224b91d06e52e7fd1e0..d21d179126a13308e9840402935011c5938ff49c 100644 (file)
@@ -51,9 +51,7 @@ BOOL cli_send_trans(struct cli_state *cli, int trans,
        cli_setup_packet(cli);
 
        if (pipe_name) {
-               pipe_name_len = clistr_push_size(cli, smb_buf(cli->outbuf), 
-                                                pipe_name, -1, 
-                                                STR_TERMINATE);
+               pipe_name_len = clistr_push(cli, smb_buf(cli->outbuf), pipe_name, -1, STR_TERMINATE);
        }
 
        outparam = smb_buf(cli->outbuf)+(trans==SMBtrans ? pipe_name_len : 3);
@@ -75,9 +73,7 @@ BOOL cli_send_trans(struct cli_state *cli, int trans,
        for (i=0;i<lsetup;i++)          /* setup[] */
                SSVAL(cli->outbuf,smb_setup+i*2,setup[i]);
        p = smb_buf(cli->outbuf);
-       if (trans==SMBtrans) {
-               clistr_push(cli, p, pipe_name, -1, STR_TERMINATE);
-       } else {
+       if (trans != SMBtrans) {
                *p++ = 0;  /* put in a null smb_name */
                *p++ = 'D'; *p++ = ' '; /* observed in OS/2 */
        }