2014-01-19 01:09:44 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2013-2014 Mnemosyne LLC
|
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-12-22 20:35:19 +00:00
|
|
|
#include <stdlib.h> /* bsearch() */
|
|
|
|
#include <string.h> /* memcmp() */
|
|
|
|
|
|
|
|
#include "transmission.h"
|
|
|
|
#include "ptrarray.h"
|
|
|
|
#include "quark.h"
|
2017-06-08 07:24:12 +00:00
|
|
|
#include "tr-assert.h"
|
2012-12-22 20:35:19 +00:00
|
|
|
#include "utils.h" /* tr_memdup(), tr_strndup() */
|
|
|
|
|
|
|
|
struct tr_key_struct
|
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* str;
|
2017-04-19 12:04:45 +00:00
|
|
|
size_t len;
|
2012-12-22 20:35:19 +00:00
|
|
|
};
|
|
|
|
|
2019-03-12 21:01:17 +00:00
|
|
|
#define Q(name) { "" name "", sizeof("" name "") - 1 }
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static struct tr_key_struct const my_static[] =
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2019-03-12 21:01:17 +00:00
|
|
|
Q(""),
|
|
|
|
Q("activeTorrentCount"),
|
|
|
|
Q("activity-date"),
|
|
|
|
Q("activityDate"),
|
|
|
|
Q("added"),
|
|
|
|
Q("added-date"),
|
|
|
|
Q("added.f"),
|
|
|
|
Q("added6"),
|
|
|
|
Q("added6.f"),
|
|
|
|
Q("addedDate"),
|
|
|
|
Q("address"),
|
|
|
|
Q("alt-speed-down"),
|
|
|
|
Q("alt-speed-enabled"),
|
|
|
|
Q("alt-speed-time-begin"),
|
|
|
|
Q("alt-speed-time-day"),
|
|
|
|
Q("alt-speed-time-enabled"),
|
|
|
|
Q("alt-speed-time-end"),
|
|
|
|
Q("alt-speed-up"),
|
|
|
|
Q("announce"),
|
|
|
|
Q("announce-list"),
|
|
|
|
Q("announceState"),
|
|
|
|
Q("arguments"),
|
|
|
|
Q("bandwidth-priority"),
|
|
|
|
Q("bandwidthPriority"),
|
|
|
|
Q("bind-address-ipv4"),
|
|
|
|
Q("bind-address-ipv6"),
|
|
|
|
Q("bitfield"),
|
|
|
|
Q("blocklist-date"),
|
|
|
|
Q("blocklist-enabled"),
|
|
|
|
Q("blocklist-size"),
|
|
|
|
Q("blocklist-updates-enabled"),
|
|
|
|
Q("blocklist-url"),
|
|
|
|
Q("blocks"),
|
|
|
|
Q("bytesCompleted"),
|
|
|
|
Q("cache-size-mb"),
|
|
|
|
Q("clientIsChoked"),
|
|
|
|
Q("clientIsInterested"),
|
|
|
|
Q("clientName"),
|
|
|
|
Q("comment"),
|
|
|
|
Q("comment_utf_8"),
|
|
|
|
Q("compact-view"),
|
|
|
|
Q("complete"),
|
|
|
|
Q("config-dir"),
|
|
|
|
Q("cookies"),
|
|
|
|
Q("corrupt"),
|
|
|
|
Q("corruptEver"),
|
|
|
|
Q("created by"),
|
|
|
|
Q("created by.utf-8"),
|
|
|
|
Q("creation date"),
|
|
|
|
Q("creator"),
|
|
|
|
Q("cumulative-stats"),
|
|
|
|
Q("current-stats"),
|
|
|
|
Q("date"),
|
|
|
|
Q("dateCreated"),
|
|
|
|
Q("delete-local-data"),
|
|
|
|
Q("desiredAvailable"),
|
|
|
|
Q("destination"),
|
2020-04-27 21:34:02 +00:00
|
|
|
Q("details-window-height"),
|
|
|
|
Q("details-window-width"),
|
2019-03-12 21:01:17 +00:00
|
|
|
Q("dht-enabled"),
|
|
|
|
Q("display-name"),
|
|
|
|
Q("dnd"),
|
|
|
|
Q("done-date"),
|
|
|
|
Q("doneDate"),
|
|
|
|
Q("download-dir"),
|
|
|
|
Q("download-dir-free-space"),
|
|
|
|
Q("download-queue-enabled"),
|
|
|
|
Q("download-queue-size"),
|
|
|
|
Q("downloadCount"),
|
|
|
|
Q("downloadDir"),
|
|
|
|
Q("downloadLimit"),
|
|
|
|
Q("downloadLimited"),
|
|
|
|
Q("downloadSpeed"),
|
|
|
|
Q("downloaded"),
|
|
|
|
Q("downloaded-bytes"),
|
|
|
|
Q("downloadedBytes"),
|
|
|
|
Q("downloadedEver"),
|
|
|
|
Q("downloaders"),
|
|
|
|
Q("downloading-time-seconds"),
|
|
|
|
Q("dropped"),
|
|
|
|
Q("dropped6"),
|
|
|
|
Q("e"),
|
2019-11-12 23:13:42 +00:00
|
|
|
Q("editDate"),
|
2019-03-12 21:01:17 +00:00
|
|
|
Q("encoding"),
|
|
|
|
Q("encryption"),
|
|
|
|
Q("error"),
|
|
|
|
Q("errorString"),
|
|
|
|
Q("eta"),
|
|
|
|
Q("etaIdle"),
|
|
|
|
Q("failure reason"),
|
|
|
|
Q("fields"),
|
2020-10-13 15:33:56 +00:00
|
|
|
Q("file-count"),
|
2019-03-12 21:01:17 +00:00
|
|
|
Q("fileStats"),
|
|
|
|
Q("filename"),
|
|
|
|
Q("files"),
|
|
|
|
Q("files-added"),
|
|
|
|
Q("files-unwanted"),
|
|
|
|
Q("files-wanted"),
|
|
|
|
Q("filesAdded"),
|
|
|
|
Q("filter-mode"),
|
|
|
|
Q("filter-text"),
|
|
|
|
Q("filter-trackers"),
|
|
|
|
Q("flagStr"),
|
|
|
|
Q("flags"),
|
2019-11-09 23:02:23 +00:00
|
|
|
Q("format"),
|
2019-03-12 21:01:17 +00:00
|
|
|
Q("fromCache"),
|
|
|
|
Q("fromDht"),
|
|
|
|
Q("fromIncoming"),
|
|
|
|
Q("fromLpd"),
|
|
|
|
Q("fromLtep"),
|
|
|
|
Q("fromPex"),
|
|
|
|
Q("fromTracker"),
|
|
|
|
Q("hasAnnounced"),
|
|
|
|
Q("hasScraped"),
|
|
|
|
Q("hashString"),
|
|
|
|
Q("have"),
|
|
|
|
Q("haveUnchecked"),
|
|
|
|
Q("haveValid"),
|
|
|
|
Q("honorsSessionLimits"),
|
|
|
|
Q("host"),
|
|
|
|
Q("id"),
|
|
|
|
Q("idle-limit"),
|
|
|
|
Q("idle-mode"),
|
|
|
|
Q("idle-seeding-limit"),
|
|
|
|
Q("idle-seeding-limit-enabled"),
|
|
|
|
Q("ids"),
|
|
|
|
Q("incomplete"),
|
|
|
|
Q("incomplete-dir"),
|
|
|
|
Q("incomplete-dir-enabled"),
|
|
|
|
Q("info"),
|
|
|
|
Q("info_hash"),
|
|
|
|
Q("inhibit-desktop-hibernation"),
|
|
|
|
Q("interval"),
|
|
|
|
Q("ip"),
|
|
|
|
Q("ipv4"),
|
|
|
|
Q("ipv6"),
|
|
|
|
Q("isBackup"),
|
|
|
|
Q("isDownloadingFrom"),
|
|
|
|
Q("isEncrypted"),
|
|
|
|
Q("isFinished"),
|
|
|
|
Q("isIncoming"),
|
|
|
|
Q("isPrivate"),
|
|
|
|
Q("isStalled"),
|
|
|
|
Q("isUTP"),
|
|
|
|
Q("isUploadingTo"),
|
|
|
|
Q("labels"),
|
|
|
|
Q("lastAnnouncePeerCount"),
|
|
|
|
Q("lastAnnounceResult"),
|
|
|
|
Q("lastAnnounceStartTime"),
|
|
|
|
Q("lastAnnounceSucceeded"),
|
|
|
|
Q("lastAnnounceTime"),
|
|
|
|
Q("lastAnnounceTimedOut"),
|
|
|
|
Q("lastScrapeResult"),
|
|
|
|
Q("lastScrapeStartTime"),
|
|
|
|
Q("lastScrapeSucceeded"),
|
|
|
|
Q("lastScrapeTime"),
|
|
|
|
Q("lastScrapeTimedOut"),
|
|
|
|
Q("leecherCount"),
|
|
|
|
Q("leftUntilDone"),
|
|
|
|
Q("length"),
|
|
|
|
Q("location"),
|
|
|
|
Q("lpd-enabled"),
|
|
|
|
Q("m"),
|
|
|
|
Q("magnet-info"),
|
|
|
|
Q("magnetLink"),
|
|
|
|
Q("main-window-height"),
|
|
|
|
Q("main-window-is-maximized"),
|
|
|
|
Q("main-window-layout-order"),
|
|
|
|
Q("main-window-width"),
|
|
|
|
Q("main-window-x"),
|
|
|
|
Q("main-window-y"),
|
|
|
|
Q("manualAnnounceTime"),
|
|
|
|
Q("max-peers"),
|
|
|
|
Q("maxConnectedPeers"),
|
|
|
|
Q("memory-bytes"),
|
|
|
|
Q("memory-units"),
|
|
|
|
Q("message-level"),
|
|
|
|
Q("metadataPercentComplete"),
|
|
|
|
Q("metadata_size"),
|
|
|
|
Q("metainfo"),
|
|
|
|
Q("method"),
|
|
|
|
Q("min interval"),
|
|
|
|
Q("min_request_interval"),
|
|
|
|
Q("move"),
|
|
|
|
Q("msg_type"),
|
|
|
|
Q("mtimes"),
|
|
|
|
Q("name"),
|
|
|
|
Q("name.utf-8"),
|
|
|
|
Q("nextAnnounceTime"),
|
|
|
|
Q("nextScrapeTime"),
|
|
|
|
Q("nodes"),
|
|
|
|
Q("nodes6"),
|
|
|
|
Q("open-dialog-dir"),
|
|
|
|
Q("p"),
|
|
|
|
Q("path"),
|
|
|
|
Q("path.utf-8"),
|
|
|
|
Q("paused"),
|
|
|
|
Q("pausedTorrentCount"),
|
|
|
|
Q("peer-congestion-algorithm"),
|
|
|
|
Q("peer-id-ttl-hours"),
|
|
|
|
Q("peer-limit"),
|
|
|
|
Q("peer-limit-global"),
|
|
|
|
Q("peer-limit-per-torrent"),
|
|
|
|
Q("peer-port"),
|
|
|
|
Q("peer-port-random-high"),
|
|
|
|
Q("peer-port-random-low"),
|
|
|
|
Q("peer-port-random-on-start"),
|
|
|
|
Q("peer-socket-tos"),
|
|
|
|
Q("peerIsChoked"),
|
|
|
|
Q("peerIsInterested"),
|
|
|
|
Q("peers"),
|
|
|
|
Q("peers2"),
|
|
|
|
Q("peers2-6"),
|
|
|
|
Q("peers6"),
|
|
|
|
Q("peersConnected"),
|
|
|
|
Q("peersFrom"),
|
|
|
|
Q("peersGettingFromUs"),
|
|
|
|
Q("peersSendingToUs"),
|
|
|
|
Q("percentDone"),
|
|
|
|
Q("pex-enabled"),
|
|
|
|
Q("piece"),
|
|
|
|
Q("piece length"),
|
|
|
|
Q("pieceCount"),
|
|
|
|
Q("pieceSize"),
|
|
|
|
Q("pieces"),
|
|
|
|
Q("play-download-complete-sound"),
|
|
|
|
Q("port"),
|
|
|
|
Q("port-forwarding-enabled"),
|
|
|
|
Q("port-is-open"),
|
|
|
|
Q("preallocation"),
|
|
|
|
Q("prefetch-enabled"),
|
2020-10-13 15:33:56 +00:00
|
|
|
Q("primary-mime-type"),
|
2019-03-12 21:01:17 +00:00
|
|
|
Q("priorities"),
|
|
|
|
Q("priority"),
|
|
|
|
Q("priority-high"),
|
|
|
|
Q("priority-low"),
|
|
|
|
Q("priority-normal"),
|
|
|
|
Q("private"),
|
|
|
|
Q("progress"),
|
|
|
|
Q("prompt-before-exit"),
|
|
|
|
Q("queue-move-bottom"),
|
|
|
|
Q("queue-move-down"),
|
|
|
|
Q("queue-move-top"),
|
|
|
|
Q("queue-move-up"),
|
|
|
|
Q("queue-stalled-enabled"),
|
|
|
|
Q("queue-stalled-minutes"),
|
|
|
|
Q("queuePosition"),
|
|
|
|
Q("rateDownload"),
|
|
|
|
Q("rateToClient"),
|
|
|
|
Q("rateToPeer"),
|
|
|
|
Q("rateUpload"),
|
|
|
|
Q("ratio-limit"),
|
|
|
|
Q("ratio-limit-enabled"),
|
|
|
|
Q("ratio-mode"),
|
|
|
|
Q("recent-download-dir-1"),
|
|
|
|
Q("recent-download-dir-2"),
|
|
|
|
Q("recent-download-dir-3"),
|
|
|
|
Q("recent-download-dir-4"),
|
|
|
|
Q("recheckProgress"),
|
|
|
|
Q("remote-session-enabled"),
|
|
|
|
Q("remote-session-host"),
|
|
|
|
Q("remote-session-password"),
|
|
|
|
Q("remote-session-port"),
|
|
|
|
Q("remote-session-requres-authentication"),
|
|
|
|
Q("remote-session-username"),
|
|
|
|
Q("removed"),
|
|
|
|
Q("rename-partial-files"),
|
|
|
|
Q("reqq"),
|
|
|
|
Q("result"),
|
|
|
|
Q("rpc-authentication-required"),
|
|
|
|
Q("rpc-bind-address"),
|
|
|
|
Q("rpc-enabled"),
|
|
|
|
Q("rpc-host-whitelist"),
|
|
|
|
Q("rpc-host-whitelist-enabled"),
|
|
|
|
Q("rpc-password"),
|
|
|
|
Q("rpc-port"),
|
|
|
|
Q("rpc-url"),
|
|
|
|
Q("rpc-username"),
|
|
|
|
Q("rpc-version"),
|
|
|
|
Q("rpc-version-minimum"),
|
|
|
|
Q("rpc-whitelist"),
|
|
|
|
Q("rpc-whitelist-enabled"),
|
|
|
|
Q("scrape"),
|
|
|
|
Q("scrape-paused-torrents-enabled"),
|
|
|
|
Q("scrapeState"),
|
|
|
|
Q("script-torrent-done-enabled"),
|
|
|
|
Q("script-torrent-done-filename"),
|
|
|
|
Q("seconds-active"),
|
|
|
|
Q("secondsActive"),
|
|
|
|
Q("secondsDownloading"),
|
|
|
|
Q("secondsSeeding"),
|
|
|
|
Q("seed-queue-enabled"),
|
|
|
|
Q("seed-queue-size"),
|
|
|
|
Q("seedIdleLimit"),
|
|
|
|
Q("seedIdleMode"),
|
|
|
|
Q("seedRatioLimit"),
|
|
|
|
Q("seedRatioLimited"),
|
|
|
|
Q("seedRatioMode"),
|
|
|
|
Q("seederCount"),
|
|
|
|
Q("seeding-time-seconds"),
|
|
|
|
Q("session-count"),
|
|
|
|
Q("session-id"),
|
|
|
|
Q("sessionCount"),
|
|
|
|
Q("show-backup-trackers"),
|
|
|
|
Q("show-extra-peer-details"),
|
|
|
|
Q("show-filterbar"),
|
|
|
|
Q("show-notification-area-icon"),
|
|
|
|
Q("show-options-window"),
|
|
|
|
Q("show-statusbar"),
|
|
|
|
Q("show-toolbar"),
|
|
|
|
Q("show-tracker-scrapes"),
|
|
|
|
Q("size-bytes"),
|
|
|
|
Q("size-units"),
|
|
|
|
Q("sizeWhenDone"),
|
|
|
|
Q("sort-mode"),
|
|
|
|
Q("sort-reversed"),
|
|
|
|
Q("speed"),
|
|
|
|
Q("speed-Bps"),
|
|
|
|
Q("speed-bytes"),
|
|
|
|
Q("speed-limit-down"),
|
|
|
|
Q("speed-limit-down-enabled"),
|
|
|
|
Q("speed-limit-up"),
|
|
|
|
Q("speed-limit-up-enabled"),
|
|
|
|
Q("speed-units"),
|
|
|
|
Q("start-added-torrents"),
|
|
|
|
Q("start-minimized"),
|
|
|
|
Q("startDate"),
|
|
|
|
Q("status"),
|
|
|
|
Q("statusbar-stats"),
|
|
|
|
Q("tag"),
|
|
|
|
Q("tier"),
|
|
|
|
Q("time-checked"),
|
|
|
|
Q("torrent-added"),
|
|
|
|
Q("torrent-added-notification-command"),
|
|
|
|
Q("torrent-added-notification-enabled"),
|
|
|
|
Q("torrent-complete-notification-command"),
|
|
|
|
Q("torrent-complete-notification-enabled"),
|
|
|
|
Q("torrent-complete-sound-command"),
|
|
|
|
Q("torrent-complete-sound-enabled"),
|
|
|
|
Q("torrent-duplicate"),
|
|
|
|
Q("torrent-get"),
|
|
|
|
Q("torrent-set"),
|
|
|
|
Q("torrent-set-location"),
|
|
|
|
Q("torrentCount"),
|
|
|
|
Q("torrentFile"),
|
|
|
|
Q("torrents"),
|
|
|
|
Q("totalSize"),
|
|
|
|
Q("total_size"),
|
|
|
|
Q("tracker id"),
|
|
|
|
Q("trackerAdd"),
|
|
|
|
Q("trackerRemove"),
|
|
|
|
Q("trackerReplace"),
|
|
|
|
Q("trackerStats"),
|
|
|
|
Q("trackers"),
|
|
|
|
Q("trash-can-enabled"),
|
|
|
|
Q("trash-original-torrent-files"),
|
|
|
|
Q("umask"),
|
|
|
|
Q("units"),
|
|
|
|
Q("upload-slots-per-torrent"),
|
|
|
|
Q("uploadLimit"),
|
|
|
|
Q("uploadLimited"),
|
|
|
|
Q("uploadRatio"),
|
|
|
|
Q("uploadSpeed"),
|
|
|
|
Q("upload_only"),
|
|
|
|
Q("uploaded"),
|
|
|
|
Q("uploaded-bytes"),
|
|
|
|
Q("uploadedBytes"),
|
|
|
|
Q("uploadedEver"),
|
|
|
|
Q("url-list"),
|
|
|
|
Q("use-global-speed-limit"),
|
|
|
|
Q("use-speed-limit"),
|
|
|
|
Q("user-has-given-informed-consent"),
|
|
|
|
Q("ut_comment"),
|
|
|
|
Q("ut_holepunch"),
|
|
|
|
Q("ut_metadata"),
|
|
|
|
Q("ut_pex"),
|
|
|
|
Q("ut_recommend"),
|
|
|
|
Q("utp-enabled"),
|
|
|
|
Q("v"),
|
|
|
|
Q("version"),
|
|
|
|
Q("wanted"),
|
|
|
|
Q("warning message"),
|
|
|
|
Q("watch-dir"),
|
|
|
|
Q("watch-dir-enabled"),
|
|
|
|
Q("webseeds"),
|
|
|
|
Q("webseedsSendingToUs")
|
2012-12-22 20:35:19 +00:00
|
|
|
};
|
|
|
|
|
2019-03-12 21:01:17 +00:00
|
|
|
#undef Q
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static int compareKeys(void const* va, void const* vb)
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int ret;
|
2017-04-20 16:02:19 +00:00
|
|
|
struct tr_key_struct const* a = va;
|
|
|
|
struct tr_key_struct const* b = vb;
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
ret = memcmp(a->str, b->str, MIN(a->len, b->len));
|
2013-02-03 21:43:17 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (ret == 0 && a->len != b->len)
|
|
|
|
{
|
|
|
|
ret = a->len < b->len ? -1 : 1;
|
|
|
|
}
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return ret;
|
2012-12-22 20:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static tr_ptrArray my_runtime = TR_PTR_ARRAY_INIT_STATIC;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
bool tr_quark_lookup(void const* str, size_t len, tr_quark* setme)
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
static size_t const n_static = TR_N_ELEMENTS(my_static);
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-06-08 07:24:12 +00:00
|
|
|
TR_ASSERT(n_static == TR_N_KEYS);
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-06-13 02:24:09 +00:00
|
|
|
struct tr_key_struct tmp;
|
|
|
|
struct tr_key_struct* match;
|
|
|
|
bool success = false;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tmp.str = str;
|
|
|
|
tmp.len = len;
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* is it in our static array? */
|
|
|
|
match = bsearch(&tmp, my_static, n_static, sizeof(struct tr_key_struct), compareKeys);
|
|
|
|
|
|
|
|
if (match != NULL)
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
*setme = match - my_static;
|
|
|
|
success = true;
|
2012-12-22 20:35:19 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* was it added during runtime? */
|
|
|
|
if (!success && !tr_ptrArrayEmpty(&my_runtime))
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
struct tr_key_struct** runtime = (struct tr_key_struct**)tr_ptrArrayBase(&my_runtime);
|
2017-04-20 16:02:19 +00:00
|
|
|
size_t const n_runtime = tr_ptrArraySize(&my_runtime);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (size_t i = 0; i < n_runtime; ++i)
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (compareKeys(&tmp, runtime[i]) == 0)
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
*setme = TR_N_KEYS + i;
|
|
|
|
success = true;
|
|
|
|
break;
|
2012-12-22 20:35:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return success;
|
2012-12-22 20:35:19 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static tr_quark append_new_quark(void const* str, size_t len)
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_quark ret;
|
|
|
|
struct tr_key_struct* tmp;
|
|
|
|
tmp = tr_new(struct tr_key_struct, 1);
|
|
|
|
tmp->str = tr_strndup(str, len);
|
|
|
|
tmp->len = len;
|
|
|
|
ret = TR_N_KEYS + tr_ptrArraySize(&my_runtime);
|
|
|
|
tr_ptrArrayAppend(&my_runtime, tmp);
|
|
|
|
return ret;
|
2012-12-22 20:35:19 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_quark tr_quark_new(void const* str, size_t len)
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_quark ret = TR_KEY_NONE;
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2020-11-05 22:46:21 +00:00
|
|
|
if (str != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-05 22:46:21 +00:00
|
|
|
if (len == TR_BAD_SIZE)
|
|
|
|
{
|
|
|
|
len = strlen(str);
|
|
|
|
}
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2020-11-05 22:46:21 +00:00
|
|
|
if (!tr_quark_lookup(str, len, &ret))
|
|
|
|
{
|
|
|
|
ret = append_new_quark(str, len);
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return ret;
|
2012-12-22 20:35:19 +00:00
|
|
|
}
|
2015-01-02 11:15:31 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* tr_quark_get_string(tr_quark q, size_t* len)
|
2012-12-22 20:35:19 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
struct tr_key_struct const* tmp;
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (q < TR_N_KEYS)
|
|
|
|
{
|
|
|
|
tmp = &my_static[q];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = tr_ptrArrayNth(&my_runtime, q - TR_N_KEYS);
|
|
|
|
}
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (len != NULL)
|
|
|
|
{
|
|
|
|
*len = tmp->len;
|
|
|
|
}
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return tmp->str;
|
2012-12-22 20:35:19 +00:00
|
|
|
}
|