Commit 5e81d130 authored by unknown's avatar unknown
Browse files

Merge romeo.(none):/home/bkroot/mysql-5.1-new-rpl

into  romeo.(none):/home/bk/b19459-mysql-5.1-new


client/mysqlbinlog.cc:
  Auto merged
include/my_sys.h:
  Auto merged
mysys/base64.c:
  Auto merged
sql/log_event.cc:
  Auto merged
sql/log_event.h:
  Auto merged
storage/ndb/src/mgmapi/mgmapi.cpp:
  Auto merged
sql/share/errmsg.txt:
  SCCS merged
parents cc4435ad d8be3113
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -476,6 +476,30 @@ static bool check_database(const char *log_dbname)
}



static int
write_event_header_and_base64(Log_event *ev, FILE *result_file,
                              PRINT_EVENT_INFO *print_event_info)
{
  DBUG_ENTER("write_event_header_and_base64");
  /* Write header and base64 output to cache */
  IO_CACHE result_cache;
  if (init_io_cache(&result_cache, -1, 0, WRITE_CACHE, 0L, FALSE,
                    MYF(MY_WME | MY_NABP)))
  {
    return 1;
  }

  ev->print_header(&result_cache, print_event_info, FALSE);
  ev->print_base64(&result_cache, print_event_info, FALSE);

  /* Read data from cache and write to result file */
  my_b_copy_to_file(&result_cache, result_file);
  end_io_cache(&result_cache);
  DBUG_RETURN(0);
}


/*
  Process an event

@@ -538,18 +562,18 @@ int process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,

    print_event_info->base64_output= opt_base64_output;

    DBUG_PRINT("debug", ("event_type: %s", ev->get_type_str()));

    switch (ev_type) {
    case QUERY_EVENT:
      if (check_database(((Query_log_event*)ev)->db))
        goto end;
      if (opt_base64_output)
      {
        ev->print_header(result_file, print_event_info);
        ev->print_base64(result_file, print_event_info);
      }
        write_event_header_and_base64(ev, result_file, print_event_info);
      else
        ev->print(result_file, print_event_info);
      break;

    case CREATE_FILE_EVENT:
    {
      Create_file_log_event* ce= (Create_file_log_event*)ev;
@@ -570,8 +594,7 @@ int process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev,
      */
      if (opt_base64_output)
      {
        ce->print_header(result_file, print_event_info);
        ce->print_base64(result_file, print_event_info);
        write_event_header_and_base64(ce, result_file, print_event_info);
      }
      else
        ce->print(result_file, print_event_info, TRUE);
+2 −1
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ int base64_encode(const void *src, size_t src_len, char *dst);
/*
  Decode a base64 string into data
*/
int base64_decode(const char *src, size_t src_len, void *dst);
int base64_decode(const char *src, size_t src_len,
                  void *dst, const char **end_ptr);


#ifdef __cplusplus
+1 −0
Original line number Diff line number Diff line
@@ -517,6 +517,7 @@ typedef int (*qsort2_cmp)(const void *, const void *, const void *);
			 (uint) (*(info)->current_pos - (info)->request_pos))

/* tell write offset in the SEQ_APPEND cache */
int      my_b_copy_to_file(IO_CACHE *cache, FILE *file);
my_off_t my_b_append_tell(IO_CACHE* info);
my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */

+47 −18
Original line number Diff line number Diff line
@@ -125,44 +125,69 @@ pos(unsigned char c)
/*
  Decode a base64 string

  Note: We require that dst is pre-allocated to correct size.
        See base64_needed_decoded_length().

  RETURN  Number of bytes produced in dst or -1 in case of failure
  SYNOPSIS
    base64_decode()
    src      Pointer to base64-encoded string
    len      Length of string at 'src'
    dst      Pointer to location where decoded data will be stored
    end_ptr  Pointer to variable that will refer to the character
             after the end of the encoded data that were decoded. Can
             be NULL.

  DESCRIPTION

    The base64-encoded data in the range ['src','*end_ptr') will be
    decoded and stored starting at 'dst'.  The decoding will stop
    after 'len' characters have been read from 'src', or when padding
    occurs in the base64-encoded data. In either case: if 'end_ptr' is
    non-null, '*end_ptr' will be set to point to the character after
    the last read character, even in the presence of error.

  NOTE
    We require that 'dst' is pre-allocated to correct size.

  SEE ALSO
    base64_needed_decoded_length().

  RETURN VALUE
    Number of bytes written at 'dst' or -1 in case of failure
*/
int
base64_decode(const char *src, size_t size, void *dst)
base64_decode(const char *const src_base, size_t const len,
              void *dst, const char **end_ptr)
{
  char b[3];
  size_t i= 0;
  char *dst_base= (char *)dst;
  char const *src= src_base;
  char *d= dst_base;
  size_t j;

  while (i < size)
  while (i < len)
  {
    unsigned c= 0;
    size_t mark= 0;

    SKIP_SPACE(src, i, size);
    SKIP_SPACE(src, i, len);

    c += pos(*src++);
    c <<= 6;
    i++;

    SKIP_SPACE(src, i, size);
    SKIP_SPACE(src, i, len);

    c += pos(*src++);
    c <<= 6;
    i++;

    SKIP_SPACE(src, i, size);
    SKIP_SPACE(src, i, len);

    if (*src != '=')
      c += pos(*src++);
    else
    {
      i= size;
      src += 2;                /* There should be two bytes padding */
      i= len;
      mark= 2;
      c <<= 6;
      goto end;
@@ -170,13 +195,14 @@ base64_decode(const char *src, size_t size, void *dst)
    c <<= 6;
    i++;

    SKIP_SPACE(src, i, size);
    SKIP_SPACE(src, i, len);

    if (*src != '=')
      c += pos(*src++);
    else
    {
      i= size;
      src += 1;                 /* There should be one byte padding */
      i= len;
      mark= 1;
      goto end;
    }
@@ -191,11 +217,14 @@ base64_decode(const char *src, size_t size, void *dst)
      *d++= b[j];
  }

  if (i != size)
  {
    return -1;
  }
  return d - dst_base;
  if (end_ptr != NULL)
    *end_ptr= src;

  /*
    The variable 'i' is set to 'len' when padding has been read, so it
    does not actually reflect the number of bytes read from 'src'.
   */
  return i != len ? -1 : d - dst_base;
}


+47 −0
Original line number Diff line number Diff line
@@ -24,6 +24,53 @@
#include <stdarg.h>
#include <m_ctype.h>

/*
  Copy contents of an IO_CACHE to a file.

  SYNOPSIS
    my_b_copy_to_file()
    cache  IO_CACHE to copy from
    file   File to copy to

  DESCRIPTION
    Copy the contents of the cache to the file. The cache will be
    re-inited to a read cache and will read from the beginning of the
    cache.

    If a failure to write fully occurs, the cache is only copied
    partially.

  TODO
    Make this function solid by handling partial reads from the cache
    in a correct manner: it should be atomic.

  RETURN VALUE
    0  All OK
    1  An error occured
*/
int
my_b_copy_to_file(IO_CACHE *cache, FILE *file)
{
  byte buf[IO_SIZE];
  DBUG_ENTER("my_b_copy_to_file");

  /* Reinit the cache to read from the beginning of the cache */
  if (reinit_io_cache(cache, READ_CACHE, 0L, FALSE, FALSE))
    DBUG_RETURN(1);
  uint bytes_in_cache= my_b_bytes_in_cache(cache);
  while (bytes_in_cache > 0) {
    uint const read_bytes= min(bytes_in_cache, sizeof(buf));
    DBUG_PRINT("debug", ("Remaining %u bytes - Reading %u bytes",
                         bytes_in_cache, read_bytes));
    if (my_b_read(cache, buf, read_bytes))
      DBUG_RETURN(1);
    if (my_fwrite(file, buf, read_bytes, MYF(MY_WME | MY_NABP)) == (uint) -1)
      DBUG_RETURN(1);
    bytes_in_cache -= read_bytes;
  }
  DBUG_RETURN(0);
}

my_off_t my_b_append_tell(IO_CACHE* info)
{
  /*
Loading