Esempio n. 1
0
 @Override
 ContentType updateContentType(ContentType ctype) {
   if (ctype != null && !ctype.getContentType().equals(ContentType.MESSAGE_RFC822)) {
     throw new UnsupportedOperationException("cannot change a message to text:" + ctype);
   }
   return super.updateContentType(
       ctype == null ? new ContentType(ContentType.MESSAGE_RFC822) : ctype);
 }
  @Override
  public void handle(HttpExchange t) throws IOException {
    OutputStream os = t.getResponseBody();
    URI uri = t.getRequestURI();

    if (!uri.toString().startsWith("/")) {
      /* suspecting path traversal attack */
      String response = "403 (Forbidden)\n";
      t.sendResponseHeaders(403, response.getBytes().length);
      os.write(response.getBytes());
      os.close();
      return;
    }

    ContentType contentType;
    if (uri.toString().equals("/")) {
      contentType = ContentType.HTML;
    } else {
      contentType = ContentType.getContentType(uri.toString());
    }
    if (contentType != ContentType.REQUEST) {
      handleFile(t, contentType);
      return;
    }

    // Presentation layer on of VCenterPluginResp
    // Accept with response code 200.
    t.sendResponseHeaders(200, 0);
    Headers h = t.getResponseHeaders();

    h.set("Content-Type", contentType.toString());
    StringBuilder s =
        new StringBuilder()
            .append("<?xml-stylesheet type=\"")
            .append(ContentType.XSL)
            .append("\" href=\"")
            .append(styleSheet)
            .append("\"?>");

    // serialize the actual response object in XML
    VCenterPluginReq req = new VCenterPluginReq(uri);
    VCenterPluginResp resp = new VCenterPluginResp(req);
    resp.writeObject(s);

    os.write(s.toString().getBytes());
    os.close();
  }
Esempio n. 3
0
  public static boolean doesMatch(Submission s, String baseSubreddit, boolean ignore18) {
    String title = s.getTitle();
    String body = s.getSelftext();
    String domain = s.getUrl();
    String subreddit = s.getSubredditName();
    String flair = s.getSubmissionFlair().getText() != null ? s.getSubmissionFlair().getText() : "";

    boolean titlec;
    boolean bodyc;
    boolean domainc;
    boolean subredditc;
    boolean userc;

    if (titles == null) {
      titles = SettingValues.titleFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (texts == null) {
      texts = SettingValues.textFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (domains == null) {
      domains = SettingValues.domainFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (subreddits == null) {
      subreddits = SettingValues.subredditFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }
    if (flairs == null) {
      flairs = SettingValues.flairFilters.replaceAll("^[,]+", "").split("[,]+");
    }
    if (users == null) {
      users = SettingValues.userFilters.replaceAll("^[,\\s]+", "").split("[,\\s]+");
    }

    titlec = !SettingValues.titleFilters.isEmpty() && contains(title.toLowerCase(), titles, false);

    bodyc = !SettingValues.textFilters.isEmpty() && contains(body.toLowerCase(), texts, false);

    userc =
        !SettingValues.userFilters.isEmpty() && contains(s.getAuthor().toLowerCase(), users, false);

    try {
      domainc = !SettingValues.domainFilters.isEmpty() && isDomain(domain.toLowerCase(), domains);
    } catch (MalformedURLException e) {
      domainc = false;
    }

    subredditc =
        !subreddit.equalsIgnoreCase(baseSubreddit)
            && !SettingValues.subredditFilters.isEmpty()
            && contains(subreddit.toLowerCase(), subreddits, true);

    boolean contentMatch = false;

    if (baseSubreddit == null || baseSubreddit.isEmpty()) {
      baseSubreddit = "frontpage";
    }

    baseSubreddit = baseSubreddit.toLowerCase();
    boolean gifs = isGif(baseSubreddit);
    boolean images = isImage(baseSubreddit);
    boolean nsfw = isNsfw(baseSubreddit);
    boolean albums = isAlbums(baseSubreddit);
    boolean urls = isUrls(baseSubreddit);
    boolean selftext = isSelftext(baseSubreddit);
    boolean videos = isVideo(baseSubreddit);

    if (s.isNsfw()) {
      if (nsfw) {
        contentMatch = true;
      }
      if (!Reddit.over18 && !ignore18) {
        contentMatch = true;
      }
    }
    switch (ContentType.getContentType(s)) {
      case REDDIT:
      case EMBEDDED:
      case LINK:
        if (urls) {
          contentMatch = true;
        }
        break;
      case SELF:
      case NONE:
        if (selftext) {
          contentMatch = true;
        }
        break;
      case ALBUM:
        if (albums) {
          contentMatch = true;
        }
        break;
      case IMAGE:
      case DEVIANTART:
      case IMGUR:
      case XKCD:
        if (images) {
          contentMatch = true;
        }
        break;
      case GIF:
        if (gifs) {
          contentMatch = true;
        }
        break;
      case VID_ME:
      case STREAMABLE:
      case VIDEO:
        if (videos) {
          contentMatch = true;
        }
        break;
    }

    if (!flair.isEmpty())
      for (String flairText : flairs) {
        if (flairText.toLowerCase().startsWith(baseSubreddit)) {
          String[] split = flairText.split(":");
          if (split[0].equalsIgnoreCase(baseSubreddit)) {
            if (flair.equalsIgnoreCase(split[1].trim())) {
              contentMatch = true;
              break;
            }
          }
        }
      }

    return (titlec
        || bodyc
        || userc
        || domainc
        || subredditc
        || contentMatch
        || Hidden.id.contains(s.getFullName()));
  }
 /**
  * parses the raw bytes of the frame body and stores the parsed values in the frame's fields.
  *
  * @throws IllegalArgumentException if an invalid value is detected while parsing the frame body's
  *     raw bytes.
  */
 @Override
 public void parse() throws IllegalArgumentException {
   try {
     setEncoding(Encoding.valueOf(buffer[0]));
   } catch (
       IllegalArgumentException
           ex) { // ignore the bad value and set it to ISO-8859-1 so we can continue parsing the
                 // tag
     setEncoding(Encoding.ISO_8859_1);
   }
   try {
     setLanguage(
         Language.getLanguage(new String(buffer, 1, 3, Encoding.ISO_8859_1.getCharacterSet())));
   } catch (
       IllegalArgumentException
           ex) { // ignore the bad value and set it to english so we can continue parsing the tag
     setLanguage(Language.ENG);
   }
   try {
     setTimeStampFormat(TimeStampFormat.valueOf(buffer[4]));
   } catch (
       IllegalArgumentException
           ex) { // ignore the bad value and set it to milliseconds so we can continue parsing the
                 // tag
     setTimeStampFormat(TimeStampFormat.MS);
   }
   try {
     setContentType(ContentType.getContentType(buffer[5]));
   } catch (
       IllegalArgumentException
           ex) { // ignore the bad value and set it to other so we can continue parsing the tag
     setContentType(ContentType.OTHER);
   }
   nullTerminatorIndex = getNextNullTerminator(6, encoding);
   description = new String(buffer, 6, nullTerminatorIndex - 6, encoding.getCharacterSet()).trim();
   nullTerminatorIndex += encoding.getNumBytesInNullTerminator();
   Vector<SynchronizedLyric> lyrics = new Vector<SynchronizedLyric>();
   String text;
   int timeStamp;
   while (nullTerminatorIndex < buffer.length) {
     nextNullTerminatorIndex = getNextNullTerminator(nullTerminatorIndex, encoding);
     text =
         new String(
                 buffer,
                 nullTerminatorIndex,
                 nextNullTerminatorIndex - nullTerminatorIndex,
                 encoding.getCharacterSet())
             .trim();
     nullTerminatorIndex = nextNullTerminatorIndex + encoding.getNumBytesInNullTerminator();
     timeStamp =
         ((buffer[nullTerminatorIndex] & 0xFF) << 24)
             + ((buffer[nullTerminatorIndex + 1] & 0xFF) << 16)
             + ((buffer[nullTerminatorIndex + 2] & 0xFF) << 8)
             + (buffer[nullTerminatorIndex + 3] & 0xFF);
     nullTerminatorIndex += 4;
     lyrics.add(new SynchronizedLyric(text, timeStamp));
   }
   setSynchronizedLyrics(lyrics);
   dirty =
       false; // we just read in the frame info, so the frame body's internal byte buffer is up to
              // date
 }