modules/developer.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    Samba module with developer tools
00004    Copyright (C) Andrew Tridgell 2001
00005    Copyright (C) Jelmer Vernooij 2002
00006    
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011    
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016    
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020 */
00021 
00022 #include "includes.h"
00023 
00024 static struct {
00025         char from;
00026         char *to;
00027         int len;
00028 } weird_table[] = {
00029         {'q', "^q^", 3},
00030         {'Q', "^Q^", 3},
00031         {0, NULL}
00032 };
00033 
00034 static size_t weird_pull(void *cd, char **inbuf, size_t *inbytesleft,
00035                          char **outbuf, size_t *outbytesleft)
00036 {
00037         while (*inbytesleft >= 1 && *outbytesleft >= 2) {
00038                 int i;
00039                 int done = 0;
00040                 for (i=0;weird_table[i].from;i++) {
00041                         if (strncmp((*inbuf), 
00042                                     weird_table[i].to, 
00043                                     weird_table[i].len) == 0) {
00044                                 if (*inbytesleft < weird_table[i].len) {
00045                                         DEBUG(0,("ERROR: truncated weird string\n"));
00046                                         /* smb_panic("weird_pull"); */
00047 
00048                                 } else {
00049                                         (*outbuf)[0] = weird_table[i].from;
00050                                         (*outbuf)[1] = 0;
00051                                         (*inbytesleft)  -= weird_table[i].len;
00052                                         (*outbytesleft) -= 2;
00053                                         (*inbuf)  += weird_table[i].len;
00054                                         (*outbuf) += 2;
00055                                         done = 1;
00056                                         break;
00057                                 }
00058                         }
00059                 }
00060                 if (done) continue;
00061                 (*outbuf)[0] = (*inbuf)[0];
00062                 (*outbuf)[1] = 0;
00063                 (*inbytesleft)  -= 1;
00064                 (*outbytesleft) -= 2;
00065                 (*inbuf)  += 1;
00066                 (*outbuf) += 2;
00067         }
00068 
00069         if (*inbytesleft > 0) {
00070                 errno = E2BIG;
00071                 return -1;
00072         }
00073         
00074         return 0;
00075 }
00076 
00077 static size_t weird_push(void *cd, char **inbuf, size_t *inbytesleft,
00078                          char **outbuf, size_t *outbytesleft)
00079 {
00080         int ir_count=0;
00081 
00082         while (*inbytesleft >= 2 && *outbytesleft >= 1) {
00083                 int i;
00084                 int done=0;
00085                 for (i=0;weird_table[i].from;i++) {
00086                         if ((*inbuf)[0] == weird_table[i].from &&
00087                             (*inbuf)[1] == 0) {
00088                                 if (*outbytesleft < weird_table[i].len) {
00089                                         DEBUG(0,("No room for weird character\n"));
00090                                         /* smb_panic("weird_push"); */
00091                                 } else {
00092                                         memcpy(*outbuf, weird_table[i].to, 
00093                                                weird_table[i].len);
00094                                         (*inbytesleft)  -= 2;
00095                                         (*outbytesleft) -= weird_table[i].len;
00096                                         (*inbuf)  += 2;
00097                                         (*outbuf) += weird_table[i].len;
00098                                         done = 1;
00099                                         break;
00100                                 }
00101                         }
00102                 }
00103                 if (done) continue;
00104 
00105                 (*outbuf)[0] = (*inbuf)[0];
00106                 if ((*inbuf)[1]) ir_count++;
00107                 (*inbytesleft)  -= 2;
00108                 (*outbytesleft) -= 1;
00109                 (*inbuf)  += 2;
00110                 (*outbuf) += 1;
00111         }
00112 
00113         if (*inbytesleft == 1) {
00114                 errno = EINVAL;
00115                 return -1;
00116         }
00117 
00118         if (*inbytesleft > 1) {
00119                 errno = E2BIG;
00120                 return -1;
00121         }
00122         
00123         return ir_count;
00124 }
00125 
00126 struct charset_functions weird_functions = {"WEIRD", weird_pull, weird_push};
00127 
00128 int charset_weird_init(void)
00129 {
00130         smb_register_charset(&weird_functions);
00131         return True;
00132 }

Sambaに対してSat Aug 29 21:23:06 2009に生成されました。  doxygen 1.4.7