Ignore:
Timestamp:
Dec 14, 2012, 4:34:42 AM (9 years ago)
Author:
jordan
Message:

refactor libtransmission's tr_benc class as tr_variant.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent-magnet.c

    r13631 r13667  
    1818
    1919#include "transmission.h"
    20 #include "bencode.h"
    2120#include "crypto.h" /* tr_sha1 () */
    2221#include "magnet.h"
     
    2625#include "torrent-magnet.h"
    2726#include "utils.h"
     27#include "variant.h"
    2828#include "web.h"
    2929
     
    110110    if ((fileContents = tr_loadFile (tor->info.torrent, &fileLen)))
    111111    {
    112         tr_benc top;
    113 
    114         if (!tr_bencParse (fileContents, fileContents + fileLen, &top, NULL))
    115         {
    116             tr_benc * infoDict;
    117 
    118             if (tr_bencDictFindDict (&top, "info", &infoDict))
     112        tr_variant top;
     113
     114        if (!tr_variantFromBenc (&top, fileContents, fileLen))
     115        {
     116            tr_variant * infoDict;
     117
     118            if (tr_variantDictFindDict (&top, "info", &infoDict))
    119119            {
    120120                int infoLen;
    121                 char * infoContents = tr_bencToStr (infoDict, TR_FMT_BENC, &infoLen);
     121                char * infoContents = tr_variantToStr (infoDict, TR_VARIANT_FMT_BENC, &infoLen);
    122122                const uint8_t * i = (const uint8_t*) tr_memmem ((char*)fileContents, fileLen, infoContents, infoLen);
    123123                offset = i != NULL ? i - fileContents : 0;
     
    125125            }
    126126
    127             tr_bencFree (&top);
     127            tr_variantFree (&top);
    128128        }
    129129
     
    246246        {
    247247            /* checksum passed; now try to parse it as benc */
    248             tr_benc infoDict;
    249             const int err = tr_bencLoad (m->metadata, m->metadata_size, &infoDict, NULL);
     248            tr_variant infoDict;
     249            const int err = tr_variantFromBenc (&infoDict, m->metadata, m->metadata_size);
    250250            dbgmsg (tor, "err is %d", err);
    251251            if ((metainfoParsed = !err))
    252252            {
    253253                /* yay we have bencoded metainfo... merge it into our .torrent file */
    254                 tr_benc newMetainfo;
     254                tr_variant newMetainfo;
    255255                char * path = tr_strdup (tor->info.torrent);
    256256
    257                 if (!tr_bencLoadFile (&newMetainfo, TR_FMT_BENC, path))
     257                if (!tr_variantFromFile (&newMetainfo, TR_VARIANT_FMT_BENC, path))
    258258                {
    259259                    bool hasInfo;
     
    266266
    267267                    dbgmsg (tor, "Saving completed metadata to \"%s\"", path);
    268                     tr_bencMergeDicts (tr_bencDictAddDict (&newMetainfo, "info", 0), &infoDict);
     268                    tr_variantMergeDicts (tr_variantDictAddDict (&newMetainfo, "info", 0), &infoDict);
    269269
    270270                    memset (&info, 0, sizeof (tr_info));
     
    284284
    285285                        /* save the new .torrent file */
    286                         tr_bencToFile (&newMetainfo, TR_FMT_BENC, tor->info.torrent);
     286                        tr_variantToFile (&newMetainfo, TR_VARIANT_FMT_BENC, tor->info.torrent);
    287287                        tr_sessionSetTorrentFile (tor->session, tor->info.hashString, tor->info.torrent);
    288288                        tr_torrentGotNewInfoDict (tor);
     
    290290                    }
    291291
    292                     tr_bencFree (&newMetainfo);
     292                    tr_variantFree (&newMetainfo);
    293293                }
    294294
    295                 tr_bencFree (&infoDict);
     295                tr_variantFree (&infoDict);
    296296                tr_free (path);
    297297            }
Note: See TracChangeset for help on using the changeset viewer.