2009-03-04 04:32:55 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
2012-02-28 16:21:08 +01:00
|
|
|
* the documentation and/or other materials provided with the
|
2009-03-04 04:32:55 +01:00
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
2012-02-28 16:21:08 +01:00
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
2009-03-04 04:32:55 +01:00
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
|
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
2018-06-26 22:38:35 +02:00
|
|
|
#include "engine.h"
|
2011-12-16 02:50:18 +01:00
|
|
|
|
2013-01-24 04:13:43 +01:00
|
|
|
#include <errno.h>
|
2015-08-26 04:34:13 +02:00
|
|
|
#include <stdarg.h>
|
2014-04-30 23:05:28 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <string.h>
|
2011-12-16 02:50:18 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2011-12-16 02:50:18 +01:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
#include <android-base/stringprintf.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2018-05-16 02:02:50 +02:00
|
|
|
#include "constants.h"
|
2018-04-09 22:58:41 +02:00
|
|
|
#include "transport.h"
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
enum Op {
|
|
|
|
OP_DOWNLOAD,
|
|
|
|
OP_COMMAND,
|
|
|
|
OP_QUERY,
|
|
|
|
OP_NOTICE,
|
|
|
|
OP_DOWNLOAD_SPARSE,
|
|
|
|
OP_WAIT_FOR_DISCONNECT,
|
|
|
|
OP_DOWNLOAD_FD,
|
|
|
|
OP_UPLOAD,
|
|
|
|
};
|
2011-12-16 02:50:18 +01:00
|
|
|
|
2015-04-08 05:12:50 +02:00
|
|
|
struct Action {
|
2018-03-28 17:20:00 +02:00
|
|
|
Action(Op op, const std::string& cmd) : op(op), cmd(cmd) {}
|
2015-04-08 05:12:50 +02:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
Op op;
|
|
|
|
std::string cmd;
|
|
|
|
std::string msg;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
std::string product;
|
2010-02-25 20:05:33 +01:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void* data = nullptr;
|
|
|
|
// The protocol only supports 32-bit sizes, so you'll have to break
|
|
|
|
// anything larger into multiple chunks.
|
|
|
|
uint32_t size = 0;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
int fd = -1;
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
int (*func)(Action& a, int status, const char* resp) = nullptr;
|
2011-12-16 02:50:18 +01:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
double start = -1;
|
|
|
|
};
|
2011-12-16 02:50:18 +01:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
static std::vector<std::unique_ptr<Action>> action_list;
|
2018-06-26 22:38:35 +02:00
|
|
|
static fastboot::FastBootDriver* fb = nullptr;
|
2011-12-16 02:50:18 +01:00
|
|
|
|
2018-06-26 22:38:35 +02:00
|
|
|
void fb_init(fastboot::FastBootDriver& fbi) {
|
|
|
|
fb = &fbi;
|
|
|
|
auto cb = [](std::string& info) { fprintf(stderr, "(bootloader) %s\n", info.c_str()); };
|
|
|
|
fb->SetInfoCallback(cb);
|
|
|
|
}
|
2015-10-30 19:49:47 +01:00
|
|
|
|
2018-06-26 22:38:35 +02:00
|
|
|
const std::string fb_get_error() {
|
|
|
|
return fb->Error();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool fb_getvar(const std::string& key, std::string* value) {
|
|
|
|
return !fb->GetVar(key, value);
|
2012-05-25 03:24:53 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
static int cb_default(Action& a, int status, const char* resp) {
|
2009-03-04 04:32:55 +01:00
|
|
|
if (status) {
|
|
|
|
fprintf(stderr,"FAILED (%s)\n", resp);
|
|
|
|
} else {
|
2010-02-25 20:05:33 +01:00
|
|
|
double split = now();
|
2018-03-28 17:20:00 +02:00
|
|
|
fprintf(stderr, "OKAY [%7.3fs]\n", (split - a.start));
|
|
|
|
a.start = split;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
static Action& queue_action(Op op, const std::string& cmd) {
|
|
|
|
std::unique_ptr<Action> a{new Action(op, cmd)};
|
2009-03-04 04:32:55 +01:00
|
|
|
a->func = cb_default;
|
2010-02-25 20:05:33 +01:00
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
action_list.push_back(std::move(a));
|
|
|
|
return *action_list.back();
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_set_active(const std::string& slot) {
|
2018-05-16 02:02:50 +02:00
|
|
|
Action& a = queue_action(OP_COMMAND, FB_CMD_SET_ACTIVE ":" + slot);
|
2018-03-29 23:46:29 +02:00
|
|
|
a.msg = "Setting current slot to '" + slot + "'";
|
2015-09-15 06:05:41 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_erase(const std::string& partition) {
|
2018-05-16 02:02:50 +02:00
|
|
|
Action& a = queue_action(OP_COMMAND, FB_CMD_ERASE ":" + partition);
|
2018-03-29 23:46:29 +02:00
|
|
|
a.msg = "Erasing '" + partition + "'";
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_flash_fd(const std::string& partition, int fd, uint32_t sz) {
|
|
|
|
Action& a = queue_action(OP_DOWNLOAD_FD, "");
|
|
|
|
a.fd = fd;
|
|
|
|
a.size = sz;
|
2018-03-29 23:46:29 +02:00
|
|
|
a.msg = android::base::StringPrintf("Sending '%s' (%u KB)", partition.c_str(), sz / 1024);
|
2017-04-12 17:25:57 +02:00
|
|
|
|
2018-05-16 02:02:50 +02:00
|
|
|
Action& b = queue_action(OP_COMMAND, FB_CMD_FLASH ":" + partition);
|
2018-03-29 23:46:29 +02:00
|
|
|
b.msg = "Writing '" + partition + "'";
|
2017-04-12 17:25:57 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_flash(const std::string& partition, void* data, uint32_t sz) {
|
|
|
|
Action& a = queue_action(OP_DOWNLOAD, "");
|
|
|
|
a.data = data;
|
|
|
|
a.size = sz;
|
2018-03-29 23:46:29 +02:00
|
|
|
a.msg = android::base::StringPrintf("Sending '%s' (%u KB)", partition.c_str(), sz / 1024);
|
2009-03-04 04:32:55 +01:00
|
|
|
|
2018-05-16 02:02:50 +02:00
|
|
|
Action& b = queue_action(OP_COMMAND, FB_CMD_FLASH ":" + partition);
|
2018-03-29 23:46:29 +02:00
|
|
|
b.msg = "Writing '" + partition + "'";
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_flash_sparse(const std::string& partition, struct sparse_file* s, uint32_t sz,
|
|
|
|
size_t current, size_t total) {
|
|
|
|
Action& a = queue_action(OP_DOWNLOAD_SPARSE, "");
|
|
|
|
a.data = s;
|
|
|
|
a.size = 0;
|
2018-03-29 23:46:29 +02:00
|
|
|
a.msg = android::base::StringPrintf("Sending sparse '%s' %zu/%zu (%u KB)", partition.c_str(),
|
2018-03-28 17:20:00 +02:00
|
|
|
current, total, sz / 1024);
|
|
|
|
|
2018-05-16 02:02:50 +02:00
|
|
|
Action& b = queue_action(OP_COMMAND, FB_CMD_FLASH ":" + partition);
|
2018-03-29 23:46:29 +02:00
|
|
|
b.msg = android::base::StringPrintf("Writing sparse '%s' %zu/%zu", partition.c_str(), current,
|
|
|
|
total);
|
2012-05-25 02:18:41 +02:00
|
|
|
}
|
|
|
|
|
2015-06-24 05:27:58 +02:00
|
|
|
static int match(const char* str, const char** value, unsigned count) {
|
2009-03-04 04:32:55 +01:00
|
|
|
unsigned n;
|
|
|
|
|
|
|
|
for (n = 0; n < count; n++) {
|
|
|
|
const char *val = value[n];
|
|
|
|
int len = strlen(val);
|
|
|
|
int match;
|
|
|
|
|
|
|
|
if ((len > 1) && (val[len-1] == '*')) {
|
|
|
|
len--;
|
|
|
|
match = !strncmp(val, str, len);
|
|
|
|
} else {
|
|
|
|
match = !strcmp(val, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match) return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
static int cb_check(Action& a, int status, const char* resp, int invert) {
|
|
|
|
const char** value = reinterpret_cast<const char**>(a.data);
|
|
|
|
unsigned count = a.size;
|
2009-03-04 04:32:55 +01:00
|
|
|
unsigned n;
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
fprintf(stderr,"FAILED (%s)\n", resp);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
if (!a.product.empty()) {
|
|
|
|
if (a.product != cur_product) {
|
2011-04-05 02:54:59 +02:00
|
|
|
double split = now();
|
2018-03-28 17:20:00 +02:00
|
|
|
fprintf(stderr, "IGNORE, product is %s required only for %s [%7.3fs]\n", cur_product,
|
|
|
|
a.product.c_str(), (split - a.start));
|
|
|
|
a.start = split;
|
2011-04-05 02:54:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
int yes = match(resp, value, count);
|
2009-03-04 04:32:55 +01:00
|
|
|
if (invert) yes = !yes;
|
|
|
|
|
|
|
|
if (yes) {
|
2010-02-25 20:05:33 +01:00
|
|
|
double split = now();
|
2018-03-28 17:20:00 +02:00
|
|
|
fprintf(stderr, "OKAY [%7.3fs]\n", (split - a.start));
|
|
|
|
a.start = split;
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
fprintf(stderr, "FAILED\n\n");
|
|
|
|
fprintf(stderr, "Device %s is '%s'.\n", a.cmd.c_str() + 7, resp);
|
|
|
|
fprintf(stderr, "Update %s '%s'", invert ? "rejects" : "requires", value[0]);
|
2009-03-04 04:32:55 +01:00
|
|
|
for (n = 1; n < count; n++) {
|
2018-03-28 17:20:00 +02:00
|
|
|
fprintf(stderr, " or '%s'", value[n]);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
2018-03-28 17:20:00 +02:00
|
|
|
fprintf(stderr, ".\n\n");
|
2009-03-04 04:32:55 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
static int cb_require(Action& a, int status, const char* resp) {
|
2009-03-04 04:32:55 +01:00
|
|
|
return cb_check(a, status, resp, 0);
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
static int cb_reject(Action& a, int status, const char* resp) {
|
2009-03-04 04:32:55 +01:00
|
|
|
return cb_check(a, status, resp, 1);
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_require(const std::string& product, const std::string& var, bool invert,
|
|
|
|
size_t nvalues, const char** values) {
|
2018-05-16 02:02:50 +02:00
|
|
|
Action& a = queue_action(OP_QUERY, FB_CMD_GETVAR ":" + var);
|
2018-03-28 17:20:00 +02:00
|
|
|
a.product = product;
|
|
|
|
a.data = values;
|
|
|
|
a.size = nvalues;
|
|
|
|
a.msg = "Checking " + var;
|
|
|
|
a.func = invert ? cb_reject : cb_require;
|
|
|
|
if (a.data == nullptr) die("out of memory");
|
2017-05-09 03:04:49 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
static int cb_display(Action& a, int status, const char* resp) {
|
2009-03-04 04:32:55 +01:00
|
|
|
if (status) {
|
2018-03-28 17:20:00 +02:00
|
|
|
fprintf(stderr, "%s FAILED (%s)\n", a.cmd.c_str(), resp);
|
2009-03-04 04:32:55 +01:00
|
|
|
return status;
|
|
|
|
}
|
2018-03-28 17:20:00 +02:00
|
|
|
fprintf(stderr, "%s: %s\n", static_cast<const char*>(a.data), resp);
|
|
|
|
free(static_cast<char*>(a.data));
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_display(const std::string& label, const std::string& var) {
|
2018-05-16 02:02:50 +02:00
|
|
|
Action& a = queue_action(OP_QUERY, FB_CMD_GETVAR ":" + var);
|
2018-03-28 17:20:00 +02:00
|
|
|
a.data = xstrdup(label.c_str());
|
|
|
|
a.func = cb_display;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
static int cb_save(Action& a, int status, const char* resp) {
|
2011-04-05 02:54:59 +02:00
|
|
|
if (status) {
|
2018-03-28 17:20:00 +02:00
|
|
|
fprintf(stderr, "%s FAILED (%s)\n", a.cmd.c_str(), resp);
|
2011-04-05 02:54:59 +02:00
|
|
|
return status;
|
|
|
|
}
|
2018-03-28 17:20:00 +02:00
|
|
|
strncpy(reinterpret_cast<char*>(a.data), resp, a.size);
|
2011-04-05 02:54:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_query_save(const std::string& var, char* dest, uint32_t dest_size) {
|
2018-05-16 02:02:50 +02:00
|
|
|
Action& a = queue_action(OP_QUERY, FB_CMD_GETVAR ":" + var);
|
2018-03-28 17:20:00 +02:00
|
|
|
a.data = dest;
|
|
|
|
a.size = dest_size;
|
|
|
|
a.func = cb_save;
|
2011-04-05 02:54:59 +02:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
static int cb_do_nothing(Action&, int, const char*) {
|
|
|
|
fprintf(stderr, "\n");
|
2009-03-04 04:32:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_reboot() {
|
2018-05-16 02:02:50 +02:00
|
|
|
Action& a = queue_action(OP_COMMAND, FB_CMD_REBOOT);
|
2018-03-28 17:20:00 +02:00
|
|
|
a.func = cb_do_nothing;
|
2018-03-29 23:46:29 +02:00
|
|
|
a.msg = "Rebooting";
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_command(const std::string& cmd, const std::string& msg) {
|
|
|
|
Action& a = queue_action(OP_COMMAND, cmd);
|
|
|
|
a.msg = msg;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_download(const std::string& name, void* data, uint32_t size) {
|
|
|
|
Action& a = queue_action(OP_DOWNLOAD, "");
|
|
|
|
a.data = data;
|
|
|
|
a.size = size;
|
|
|
|
a.msg = "Downloading '" + name + "'";
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_download_fd(const std::string& name, int fd, uint32_t sz) {
|
|
|
|
Action& a = queue_action(OP_DOWNLOAD_FD, "");
|
|
|
|
a.fd = fd;
|
|
|
|
a.size = sz;
|
2018-03-29 23:46:29 +02:00
|
|
|
a.msg = android::base::StringPrintf("Sending '%s' (%u KB)", name.c_str(), sz / 1024);
|
2017-01-27 04:20:53 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_upload(const std::string& outfile) {
|
|
|
|
Action& a = queue_action(OP_UPLOAD, "");
|
|
|
|
a.data = xstrdup(outfile.c_str());
|
|
|
|
a.msg = "Uploading '" + outfile + "'";
|
2017-01-27 23:17:56 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_notice(const std::string& notice) {
|
|
|
|
Action& a = queue_action(OP_NOTICE, "");
|
|
|
|
a.msg = notice;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:20:00 +02:00
|
|
|
void fb_queue_wait_for_disconnect() {
|
2013-10-02 15:35:38 +02:00
|
|
|
queue_action(OP_WAIT_FOR_DISCONNECT, "");
|
|
|
|
}
|
|
|
|
|
2018-06-26 22:38:35 +02:00
|
|
|
int64_t fb_execute_queue() {
|
2017-04-04 16:52:47 +02:00
|
|
|
int64_t status = 0;
|
2018-03-28 17:20:00 +02:00
|
|
|
for (auto& a : action_list) {
|
2010-02-25 20:05:33 +01:00
|
|
|
a->start = now();
|
2018-03-28 17:20:00 +02:00
|
|
|
if (!a->msg.empty()) {
|
2018-03-29 23:46:29 +02:00
|
|
|
fprintf(stderr, "%-50s ", a->msg.c_str());
|
2018-04-02 23:24:03 +02:00
|
|
|
verbose("\n");
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
if (a->op == OP_DOWNLOAD) {
|
2018-06-26 22:38:35 +02:00
|
|
|
char* cbuf = static_cast<char*>(a->data);
|
|
|
|
status = fb->Download(cbuf, a->size);
|
2018-03-28 17:20:00 +02:00
|
|
|
status = a->func(*a, status, status ? fb_get_error().c_str() : "");
|
2009-03-04 04:32:55 +01:00
|
|
|
if (status) break;
|
2017-04-12 17:25:57 +02:00
|
|
|
} else if (a->op == OP_DOWNLOAD_FD) {
|
2018-06-26 22:38:35 +02:00
|
|
|
status = fb->Download(a->fd, a->size);
|
2018-03-28 17:20:00 +02:00
|
|
|
status = a->func(*a, status, status ? fb_get_error().c_str() : "");
|
2017-04-12 17:25:57 +02:00
|
|
|
if (status) break;
|
2009-03-04 04:32:55 +01:00
|
|
|
} else if (a->op == OP_COMMAND) {
|
2018-06-26 22:38:35 +02:00
|
|
|
status = fb->RawCommand(a->cmd);
|
2018-03-28 17:20:00 +02:00
|
|
|
status = a->func(*a, status, status ? fb_get_error().c_str() : "");
|
2009-03-04 04:32:55 +01:00
|
|
|
if (status) break;
|
|
|
|
} else if (a->op == OP_QUERY) {
|
2018-06-26 22:38:35 +02:00
|
|
|
std::string resp;
|
|
|
|
status = fb->RawCommand(a->cmd, &resp);
|
|
|
|
status = a->func(*a, status, status ? fb_get_error().c_str() : resp.c_str());
|
2009-03-04 04:32:55 +01:00
|
|
|
if (status) break;
|
|
|
|
} else if (a->op == OP_NOTICE) {
|
2018-03-28 17:20:00 +02:00
|
|
|
// We already showed the notice because it's in `Action::msg`.
|
2018-03-29 23:46:29 +02:00
|
|
|
fprintf(stderr, "\n");
|
2012-05-25 02:18:41 +02:00
|
|
|
} else if (a->op == OP_DOWNLOAD_SPARSE) {
|
2018-06-26 22:38:35 +02:00
|
|
|
status = fb->Download(reinterpret_cast<sparse_file*>(a->data));
|
2018-03-28 17:20:00 +02:00
|
|
|
status = a->func(*a, status, status ? fb_get_error().c_str() : "");
|
2012-05-25 02:18:41 +02:00
|
|
|
if (status) break;
|
2013-10-02 15:35:38 +02:00
|
|
|
} else if (a->op == OP_WAIT_FOR_DISCONNECT) {
|
2018-06-26 22:38:35 +02:00
|
|
|
fb->WaitForDisconnect();
|
2017-01-27 23:17:56 +01:00
|
|
|
} else if (a->op == OP_UPLOAD) {
|
2018-06-26 22:38:35 +02:00
|
|
|
status = fb->Upload(reinterpret_cast<const char*>(a->data));
|
2018-03-28 17:20:00 +02:00
|
|
|
status = a->func(*a, status, status ? fb_get_error().c_str() : "");
|
2009-03-04 04:32:55 +01:00
|
|
|
} else {
|
2018-03-28 17:20:00 +02:00
|
|
|
die("unknown action: %d", a->op);
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-28 17:20:00 +02:00
|
|
|
action_list.clear();
|
2010-04-23 21:38:51 +02:00
|
|
|
return status;
|
2009-03-04 04:32:55 +01:00
|
|
|
}
|