Ticket #5552: rpc-sugar.diff

File rpc-sugar.diff, 7.0 KB (added by eirnym, 8 years ago)

some sugar for command-line and RPC clients

  • libtransmission/rpcimpl.c

     
    160160    }
    161161  else if (tr_variantDictFindStr (args, TR_KEY_ids, &str, NULL))
    162162    {
    163       if (!strcmp (str, "recently-active"))
     163      if (!strcmp (str, "recently-active")) /* Torrents with last activity in RECENTLY_ACTIVE_SECONDS */
    164164        {
    165165          tr_torrent * tor = NULL;
    166166          const time_t now = tr_time ();
     
    171171            if (tor->anyDate >= now - window)
    172172              torrents[torrentCount++] = tor;
    173173        }
     174      else if (!strcmp (str, "running")) /* Currently active torrents. */
     175        {
     176          tr_torrent * tor = NULL;
     177          const int n = tr_sessionCountTorrents (session);
     178          torrents = tr_new0 (tr_torrent *, n);
     179          while ((tor = tr_torrentNext (session, tor)))
     180            {
     181              const tr_torrent_activity activity = tr_torrentGetActivity (tor);
     182              if (activity != TR_STATUS_STOPPED && activity != TR_STATUS_CHECK && \
     183                      activity != TR_STATUS_CHECK_WAIT)
     184                torrents[torrentCount++] = tor;
     185            }
     186        }
     187      else if (!strcmp (str, "paused")) /* Not finished and stopped torrents */
     188        {
     189          tr_torrent * tor = NULL;
     190          const int n = tr_sessionCountTorrents (session);
     191          torrents = tr_new0 (tr_torrent *, n);
     192          while ((tor = tr_torrentNext (session, tor)))
     193            if (tr_torrentGetActivity (tor) == TR_STATUS_STOPPED && \
     194                    tr_torrentGetCompleteness(tor) != TR_SEED)
     195              torrents[torrentCount++] = tor;
     196        }
     197      else if (!strcmp (str, "stopped")) /* Finished and stopped torrents */
     198        {
     199          tr_torrent * tor = NULL;
     200          const int n = tr_sessionCountTorrents (session);
     201          torrents = tr_new0 (tr_torrent *, n);
     202          while ((tor = tr_torrentNext (session, tor)))
     203            if (tr_torrentGetActivity (tor) == TR_STATUS_STOPPED && \
     204                    tr_torrentGetCompleteness(tor) == TR_SEED)
     205              torrents[torrentCount++] = tor;
     206        }
     207      else if (!strcmp (str, "idle")) /* Torrents has been queued to seed or download */
     208        {
     209          tr_torrent * tor = NULL;
     210          const int n = tr_sessionCountTorrents (session);
     211          torrents = tr_new0 (tr_torrent *, n);
     212          while ((tor = tr_torrentNext (session, tor)))
     213            {
     214              const tr_torrent_activity activity = tr_torrentGetActivity (tor);
     215              if (activity == TR_STATUS_SEED_WAIT || activity == TR_STATUS_DOWNLOAD_WAIT)
     216                torrents[torrentCount++] = tor;
     217            }
     218        }
     219      else if (!strcmp (str, "downloading")) /* Download in progress */
     220        {
     221          tr_torrent * tor = NULL;
     222          const int n = tr_sessionCountTorrents (session);
     223          torrents = tr_new0 (tr_torrent *, n);
     224          while ((tor = tr_torrentNext (session, tor)))
     225            if (tr_torrentGetActivity (tor) == TR_STATUS_DOWNLOAD)
     226              torrents[torrentCount++] = tor;
     227        }
     228      else if (!strcmp (str, "seeding")) /* Now seeding */
     229        {
     230          tr_torrent * tor = NULL;
     231          const int n = tr_sessionCountTorrents (session);
     232          torrents = tr_new0 (tr_torrent *, n);
     233          while ((tor = tr_torrentNext (session, tor)))
     234            if (tr_torrentGetActivity (tor) == TR_STATUS_SEED)
     235              torrents[torrentCount++] = tor;
     236        }
     237      else if (!strcmp (str, "verify")) /* Torrents in verify state */
     238        {
     239          tr_torrent * tor = NULL;
     240          const int n = tr_sessionCountTorrents (session);
     241          torrents = tr_new0 (tr_torrent *, n);
     242          while ((tor = tr_torrentNext (session, tor)))
     243            {
     244              const tr_torrent_activity activity = tr_torrentGetActivity (tor);
     245              if (activity == TR_STATUS_CHECK || activity == TR_STATUS_CHECK_WAIT)
     246                torrents[torrentCount++] = tor;
     247            }
     248        }
     249      else if (!strcmp (str, "error")) /* Torrents with local errors */
     250        {
     251          tr_torrent * tor = NULL;
     252          const int n = tr_sessionCountTorrents (session);
     253          torrents = tr_new0 (tr_torrent *, n);
     254          while ((tor = tr_torrentNext (session, tor)))
     255            {
     256              const tr_torrent_activity activity = tr_torrentGetActivity (tor);
     257              if (tor->error == TR_STAT_LOCAL_ERROR && activity != TR_STATUS_CHECK && \
     258                      activity != TR_STATUS_CHECK_WAIT)
     259                torrents[torrentCount++] = tor;
     260            }
     261        }
     262      else if (!strcmp (str, "gone")) /* Torrents with permanent tracker errors */
     263        {
     264          tr_torrent * tor = NULL;
     265          const int n = tr_sessionCountTorrents (session);
     266          torrents = tr_new0 (tr_torrent *, n);
     267          while ((tor = tr_torrentNext (session, tor)))
     268            {
     269              const tr_torrent_activity activity = tr_torrentGetActivity (tor);
     270              if (tor->error == TR_STAT_TRACKER_ERROR && activity != TR_STATUS_CHECK && \
     271                      activity != TR_STATUS_CHECK_WAIT)
     272                torrents[torrentCount++] = tor;
     273            }
     274        }
     275      else if (!strcmp (str, "warn")) /* Torrents which has tracker warnings */
     276        {
     277          tr_torrent * tor = NULL;
     278          const int n = tr_sessionCountTorrents (session);
     279          torrents = tr_new0 (tr_torrent *, n);
     280          while ((tor = tr_torrentNext (session, tor)))
     281            {
     282              const tr_torrent_activity activity = tr_torrentGetActivity (tor);
     283              if (tor->error == TR_STAT_TRACKER_WARNING && activity != TR_STATUS_CHECK && \
     284                      activity != TR_STATUS_CHECK_WAIT)
     285                torrents[torrentCount++] = tor;
     286            }
     287        }
     288      else if (!strcmp (str, "healthy")) /* Fine torrents */
     289        {
     290          tr_torrent * tor = NULL;
     291          const int n = tr_sessionCountTorrents (session);
     292          torrents = tr_new0 (tr_torrent *, n);
     293          while ((tor = tr_torrentNext (session, tor)))
     294            if (tor->error == TR_STAT_OK)
     295              torrents[torrentCount++] = tor;
     296        }
     297      else if (!strcmp (str, "done")) /* Finished torrents */
     298        {
     299          tr_torrent * tor = NULL;
     300          const int n = tr_sessionCountTorrents (session);
     301          torrents = tr_new0 (tr_torrent *, n);
     302          while ((tor = tr_torrentNext (session, tor)))
     303            if (tr_torrentGetCompleteness(tor) == TR_SEED)
     304              torrents[torrentCount++] = tor;
     305        }
     306      else if (!strcmp (str, "leech")) /* Not finished torrents */
     307        {
     308          tr_torrent * tor = NULL;
     309          const int n = tr_sessionCountTorrents (session);
     310          torrents = tr_new0 (tr_torrent *, n);
     311          while ((tor = tr_torrentNext (session! tor)))
     312            if (tr_torrentGetCompleteness(tor) != TR_SEED)
     313              torrents[torrentCount++] = tor;
     314        }
    174315      else
    175316        {
    176317          tr_torrent * tor;