~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/transaction_log/print_transaction_message.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "drizzled/charset.h"
38
38
 
39
39
#include <fcntl.h>
 
40
#include <errno.h>
40
41
 
41
42
#include "transaction_log.h"
42
43
#include "print_transaction_message.h"
43
44
 
44
45
#include <drizzled/message/transaction.pb.h>
 
46
#include <drizzled/replication_services.h>
45
47
#include <google/protobuf/io/zero_copy_stream.h>
46
48
#include <google/protobuf/io/zero_copy_stream_impl.h>
47
49
#include <google/protobuf/io/coded_stream.h>
99
101
  int log_file= open(filename.c_str(), O_RDONLY);
100
102
  if (log_file == -1)
101
103
  {
 
104
    char errmsg[STRERROR_MAX];
 
105
    strerror_r(errno, errmsg, sizeof(errmsg));
102
106
    errmsg_printf(ERRMSG_LVL_ERROR, _("Failed to open transaction log file %s.  Got error: %s\n"), 
103
107
                  filename.c_str(), 
104
 
                  strerror(errno));
 
108
                  errmsg);
105
109
    null_value= true;
106
110
    return NULL;
107
111
  }
117
121
  uint32_t message_type;
118
122
  if (! coded_input->ReadLittleEndian32(&message_type))
119
123
  {
 
124
    delete coded_input;
120
125
    delete file_input;
121
126
 
122
127
    /** @todo Error message for this... */
124
129
    return NULL;
125
130
  }
126
131
 
 
132
  /* Validate message type */
 
133
  if (message_type != ReplicationServices::TRANSACTION)
 
134
  {
 
135
    fprintf(stderr, _("GPB message is not a valid type.\n"));
 
136
    delete coded_input;
 
137
    delete file_input;
 
138
    null_value= true;
 
139
    return NULL;
 
140
  }
 
141
 
127
142
  uint32_t message_size;
128
143
  if (! coded_input->ReadLittleEndian32(&message_size))
129
144
  {
 
145
    delete coded_input;
130
146
    delete file_input;
131
147
 
132
148
    /** @todo Error message for this... */
134
150
    return NULL;
135
151
  }
136
152
 
 
153
  if (message_size > INT_MAX)
 
154
  {
 
155
    fprintf(stderr, _("GPB message is not a valid size.\n"));
 
156
    delete coded_input;
 
157
    delete file_input;
 
158
    null_value= true;
 
159
    return NULL;
 
160
  }
 
161
 
137
162
  uint8_t *buffer= (uint8_t *) malloc(message_size);
138
163
 
139
164
  bool result= coded_input->ReadRaw(buffer, message_size);
140
165
  if (result == false)
141
166
  {
 
167
    char errmsg[STRERROR_MAX];
 
168
    strerror_r(errno, errmsg, sizeof(errmsg));
142
169
    fprintf(stderr, _("Could not read transaction message.\n"));
143
 
    fprintf(stderr, _("GPB ERROR: %s.\n"), strerror(errno));
 
170
    fprintf(stderr, _("GPB ERROR: %s.\n"), errmsg);
144
171
    fprintf(stderr, _("Raw buffer read: %s.\n"), buffer);
145
172
  }
146
173
 
159
186
 
160
187
  if (str->alloc(transaction_text.length()))
161
188
  {
 
189
    delete coded_input;
 
190
    delete file_input;
162
191
    null_value= true;
163
192
    return NULL;
164
193
  }