1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-04 05:56:02 +00:00
transmission/libtransmission/web.h
Charles Kerr a822a46e47
refactor: add fetch options object to tr_webRun() (#2620)
* refactor: add fetch options object to tr_webRun()

Fold `tr_webRun()`, `tr_webRunWithCookies()`, and `tr_webRunWebseed()`
into a single API that takes an options argument that callers can
customize to their needs.

Also does a surface cleanup pass to the tr_webseed and tr_web internal
structures, e.g. making fields const where possible, not using raw
pointers, and making some fields private.

This revision is still full of code smells. Refactoring the entire
system is overwhelming, so instead I'm doing it in incremental steps.
2022-02-13 20:09:56 -06:00

55 lines
1.3 KiB
C++

// This file Copyright © 2021-2022 Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0), GPLv3 (SPDX: GPL-3.0),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#pragma once
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include "transmission.h"
struct evbuffer;
struct tr_web_task;
enum tr_web_close_mode
{
TR_WEB_CLOSE_WHEN_IDLE,
TR_WEB_CLOSE_NOW
};
void tr_webClose(tr_session* session, tr_web_close_mode close_mode);
using tr_web_done_func = void (*)(
tr_session* session,
bool did_connect_flag,
bool timeout_flag,
long response_code,
std::string_view response,
void* user_data);
class tr_web_options
{
public:
tr_web_options(std::string_view url_in, tr_web_done_func done_func_in, void* done_func_user_data_in)
: url{ url_in }
, done_func{ done_func_in }
, done_func_user_data{ done_func_user_data_in }
{
}
std::string url;
std::optional<int> torrent_id;
tr_web_done_func done_func = nullptr;
void* done_func_user_data = nullptr;
std::string range;
std::string cookies;
evbuffer* buffer = nullptr;
};
struct tr_web_task* tr_webRun(tr_session* session, tr_web_options&& options);
long tr_webGetTaskResponseCode(struct tr_web_task* task);