~mathiaz/ubuntu/lucid/mysql-dfsg-5.1/zap-bug-552053

« back to all changes in this revision

Viewing changes to sql/strfunc.cc

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-06-25 12:55:45 UTC
  • mfrom: (1.1.2 upstream) (0.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20090625125545-m8ogs96zzsri74xe
Tags: 5.1.34-1ubuntu1
* Merge from debian experimental (and 5.0 from main), remaining changes:
  - debian/mysql-server-5.1.config:
    + ask for MySQL root password at priority high instead of medium so
      that the password prompt is seen on a default install. (LP: #319843)
    + don't ask for root password when upgrading from a 5.0 install.
  - debian/control:
    + Make libmysqlclient16-dev a transitional package depending on
      libmysqlclient-dev.
    + Make libmysqlclient-dev conflict with libmysqlclient15-dev.
    + Don't build mysql-server, mysql-client, mysql-common and
      libmysqlclient15-dev binary packages since they're still provided
      by mysql-dfsg-5.0.
    + Make mysql-{client,server}-5.1 packages conflict and
      replace mysql-{client,server}-5.0, but not provide
      mysql-{client,server}.
    + Depend on a specific version of mysql-common rather than the src
      version of mysql-dfsg-5.1 since mysql-common is currently part of
      mysql-dfsg-5.0.
    + Lower mailx from a Recommends to a Suggests to avoid pulling in
      a full MTA on all installs of mysql-server. (LP: #259477)
  - debian/rules:
    + added -fno-strict-aliasing to CFLAGS to get around mysql testsuite
      build failures.
    + install mysql-test and sql-bench to /usr/share/mysql/ rather than
      /usr/.
  - debian/additions/debian-start.inc.sh: support ANSI mode (LP: #310211)
  - Add AppArmor profile:
    - debian/apparmor-profile: apparmor profile.
    - debian/rules, debian/mysql-server-5.0.files: install apparmor profile.
    - debian/mysql-server-5.0.dirs: add etc/apparmor.d/force-complain
    - debian/mysql-server-5.0.postrm: remove symlink in force-complain/ on
      purge.
    - debian/mysql-server-5.1.README.Debian: add apparmor documentation.
    - debian/additions/my.cnf: Add warning about apparmor. (LP: #201799)
    - debian/mysql-server-5.1.postinst: reload apparmor profiles.
  - debian/additions/my.cnf: remove language option. Error message files are
    located in a different directory in MySQL 5.0. Setting the language
    option to use /usr/share/mysql/english breaks 5.0. Both 5.0 and 5.1
    use a default value that works. (LP: #316974)
  - debian/mysql-server-5.1.mysql.init:
    + Clearly indicate that we do not support running multiple instances
      of mysqld by duplicating the init script.
      (closes: #314785, #324834, #435165, #444216)
    + Properly parameterize all existing references to the mysql config
      file (/etc/mysql/my.cnf).
  - debian/mysql-server-5.0.postinst: Clear out the second password
    when setting up mysql. (LP: #344816)
  - mysql-server-core-5.1 package for files needed by Akonadi:
    + debian/control: create mysql-server-core-5.1 package.
    + debian/mysql-server-core-5.1.files, debian/mysql-server-5.1.files:
      move core mysqld files to mysql-server-core-5.1 package.
  - Don't package sql-bench and mysql-test file.
* Dropped changes:
  - debian/patches/92_ssl_test_cert.dpatch: certificate expiration in
    test suite (LP: #323755). Included upstream.
* Dropped from 5.0:
  - apparmor profile:
    - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6. All version
      of apparmor-profile (>hardy) are higher than this version.
    - debian/mysql-server-5.0.preinst: create symlink for force-complain/
      on pre-feisty upgrades, upgrades where apparmor-profiles profile is
      unchanged (ie non-enforcing) and upgrades where the profile
      doesn't exist. Support for pre-hardy upgrades is no longer needed.
* debian/mysql-server-5.1.postinst: fix debian-sys-maint user creation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
}
89
89
 
90
90
 
 
91
static const char *on_off_default_names[]=
 
92
{
 
93
  "off","on","default", NullS
 
94
};
 
95
 
 
96
static const unsigned int on_off_default_names_len[]=
 
97
{
 
98
  sizeof("off") - 1,
 
99
  sizeof("on") - 1,
 
100
  sizeof("default") - 1
 
101
};
 
102
 
 
103
static TYPELIB on_off_default_typelib= {array_elements(on_off_default_names)-1,
 
104
                                        "", on_off_default_names,
 
105
                                        (unsigned int *)on_off_default_names_len};
 
106
 
 
107
 
 
108
/*
 
109
  Parse a TYPELIB name from the buffer
 
110
 
 
111
  SYNOPSIS
 
112
    parse_name()
 
113
      lib          Set of names to scan for.
 
114
      strpos INOUT Start of the buffer (updated to point to the next
 
115
                   character after the name)
 
116
      end          End of the buffer
 
117
      cs           Charset used in the buffer
 
118
 
 
119
  DESCRIPTION
 
120
    Parse a TYPELIB name from the buffer. The buffer is assumed to contain
 
121
    one of the names specified in the TYPELIB, followed by comma, '=', or
 
122
    end of the buffer.
 
123
 
 
124
  RETURN
 
125
    0   No matching name
 
126
    >0  Offset+1 in typelib for matched name
 
127
*/
 
128
 
 
129
static uint parse_name(TYPELIB *lib, const char **strpos, const char *end, 
 
130
                       CHARSET_INFO *cs)
 
131
{
 
132
  const char *pos= *strpos;
 
133
  const char *start= pos;
 
134
 
 
135
  /* Find the length */
 
136
  if (cs && cs->mbminlen > 1)
 
137
  {
 
138
    int mblen= 0;
 
139
    for ( ; pos < end; pos+= mblen)
 
140
    {
 
141
      my_wc_t wc;
 
142
      if ((mblen= cs->cset->mb_wc(cs, &wc, (const uchar *) pos,
 
143
                                           (const uchar *) end)) < 1)
 
144
        mblen= 1; // Not to hang on a wrong multibyte sequence
 
145
      if (wc == (my_wc_t) '=' || wc == (my_wc_t) ',')
 
146
        break;
 
147
    }
 
148
  }
 
149
  else
 
150
    for (; pos != end && *pos != '=' && *pos !=',' ; pos++);
 
151
 
 
152
  uint var_len= (uint) (pos - start);
 
153
  /* Determine which flag it is */
 
154
  uint find= cs ? find_type2(lib, start, var_len, cs) :
 
155
                  find_type(lib, start, var_len, (bool) 0);
 
156
  *strpos= pos;
 
157
  return find;
 
158
}
 
159
 
 
160
 
 
161
/* Read next character from the buffer in a charset-aware way */
 
162
 
 
163
static my_wc_t get_next_char(const char **pos, const char *end, CHARSET_INFO *cs)
 
164
{
 
165
  my_wc_t wc;
 
166
  if (*pos == end)
 
167
      return (my_wc_t)-1;
 
168
 
 
169
  if (cs && cs->mbminlen > 1)
 
170
  {
 
171
    int mblen;
 
172
    if ((mblen= cs->cset->mb_wc(cs, &wc, (const uchar *) *pos,
 
173
                                         (const uchar *) end)) < 1)
 
174
      mblen= 1; // Not to hang on a wrong multibyte sequence
 
175
    *pos += mblen;
 
176
    return wc;
 
177
  }
 
178
  else
 
179
    return *((*pos)++);
 
180
}
 
181
 
 
182
 
 
183
/*
 
184
  Parse and apply a set of flag assingments
 
185
 
 
186
  SYNOPSIS
 
187
    find_set_from_flags()
 
188
      lib               Flag names
 
189
      default_name      Number of "default" in the typelib
 
190
      cur_set           Current set of flags (start from this state)
 
191
      default_set       Default set of flags (use this for assign-default
 
192
                        keyword and flag=default assignments)
 
193
      str               String to be parsed
 
194
      length            Length of the string
 
195
      cs                String charset
 
196
      err_pos      OUT  If error, set to point to start of wrong set string
 
197
                        NULL on success
 
198
      err_len      OUT  If error, set to the length of wrong set string
 
199
      set_warning  OUT  TRUE <=> Some string in set couldn't be used
 
200
 
 
201
  DESCRIPTION
 
202
    Parse a set of flag assignments, that is, parse a string in form:
 
203
 
 
204
      param_name1=value1,param_name2=value2,... 
 
205
    
 
206
    where the names are specified in the TYPELIB, and each value can be
 
207
    either 'on','off', or 'default'. Setting the same name twice is not 
 
208
    allowed.
 
209
    
 
210
    Besides param=val assignments, we support the "default" keyword (keyword 
 
211
    #default_name in the typelib). It can be used one time, if specified it 
 
212
    causes us to build the new set over the default_set rather than cur_set
 
213
    value.
 
214
    
 
215
  RETURN
 
216
    Parsed set value if (*errpos == NULL)
 
217
    Otherwise undefined
 
218
*/
 
219
 
 
220
ulonglong find_set_from_flags(TYPELIB *lib, uint default_name,
 
221
                              ulonglong cur_set, ulonglong default_set,
 
222
                              const char *str, uint length, CHARSET_INFO *cs,
 
223
                              char **err_pos, uint *err_len, bool *set_warning)
 
224
{
 
225
  CHARSET_INFO *strip= cs ? cs : &my_charset_latin1;
 
226
  const char *end= str + strip->cset->lengthsp(strip, str, length);
 
227
  ulonglong flags_to_set= 0, flags_to_clear= 0;
 
228
  bool set_defaults= 0;
 
229
  *err_pos= 0;                  // No error yet
 
230
  if (str != end)
 
231
  {
 
232
    const char *start= str;    
 
233
    for (;;)
 
234
    {
 
235
      const char *pos= start;
 
236
      uint flag_no, value;
 
237
 
 
238
      if (!(flag_no= parse_name(lib, &pos, end, cs)))
 
239
        goto err;
 
240
 
 
241
      if (flag_no == default_name)
 
242
      {
 
243
        /* Using 'default' twice isn't allowed. */
 
244
        if (set_defaults)
 
245
          goto err;
 
246
        set_defaults= TRUE;
 
247
      }
 
248
      else
 
249
      {
 
250
        ulonglong bit=  ((longlong) 1 << (flag_no - 1));
 
251
        /* parse the '=on|off|default' */
 
252
        if ((flags_to_clear | flags_to_set) & bit ||
 
253
            get_next_char(&pos, end, cs) != '=' ||
 
254
            !(value= parse_name(&on_off_default_typelib, &pos, end, cs)))
 
255
        {
 
256
          goto err;
 
257
        }
 
258
        
 
259
        if (value == 1) // this is '=off'
 
260
          flags_to_clear|= bit;
 
261
        else if (value == 2) // this is '=on'
 
262
          flags_to_set|= bit;
 
263
        else // this is '=default' 
 
264
        {
 
265
          if (default_set & bit)
 
266
            flags_to_set|= bit;
 
267
          else
 
268
            flags_to_clear|= bit;
 
269
        }
 
270
      }
 
271
      if (pos >= end)
 
272
        break;
 
273
 
 
274
      if (get_next_char(&pos, end, cs) != ',')
 
275
        goto err;
 
276
 
 
277
      start=pos;
 
278
      continue;
 
279
   err:
 
280
      *err_pos= (char*)start;
 
281
      *err_len= end - start;
 
282
      *set_warning= TRUE;
 
283
      break;
 
284
    }
 
285
  }
 
286
  ulonglong res= set_defaults? default_set : cur_set;
 
287
  res|= flags_to_set;
 
288
  res&= ~flags_to_clear;
 
289
  return res;
 
290
}
 
291
 
 
292
 
91
293
/*
92
294
  Function to find a string in a TYPELIB
93
295
  (Same format as mysys/typelib.c)