/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef AAPT_XML_PULL_PARSER_H
#define AAPT_XML_PULL_PARSER_H

#include <expat.h>

#include <optional>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#include "Resource.h"
#include "android-base/macros.h"
#include "androidfw/Streams.h"
#include "androidfw/StringPiece.h"
#include "process/IResourceTableConsumer.h"
#include "xml/XmlUtil.h"

namespace aapt {
namespace xml {

class XmlPullParser : public IPackageDeclStack {
 public:
  enum class Event {
    kBadDocument,
    kStartDocument,
    kEndDocument,

    kStartNamespace,
    kEndNamespace,
    kStartElement,
    kEndElement,
    kText,
    kComment,
    kCdataStart,
    kCdataEnd,
  };

  /**
   * Skips to the next direct descendant node of the given start_depth,
   * skipping namespace nodes.
   *
   * When NextChildNode() returns true, you can expect Comments, Text, and
   * StartElement events.
   */
  static bool NextChildNode(XmlPullParser* parser, size_t start_depth);
  static bool SkipCurrentElement(XmlPullParser* parser);
  static bool IsGoodEvent(Event event);

  explicit XmlPullParser(android::InputStream* in);
  ~XmlPullParser();

  /**
   * Returns the current event that is being processed.
   */
  Event event() const;

  const std::string& error() const;

  /**
   * Note, unlike XmlPullParser, the first call to next() will return
   * StartElement of the first element.
   */
  Event Next();

  //
  // These are available for all nodes.
  //

  const std::string& comment() const;
  size_t line_number() const;
  size_t depth() const;

  /**
   * Returns the character data for a Text event.
   */
  const std::string& text() const;

  //
  // Namespace prefix and URI are available for StartNamespace and EndNamespace.
  //

  const std::string& namespace_prefix() const;
  const std::string& namespace_uri() const;

  //
  // These are available for StartElement and EndElement.
  //

  const std::string& element_namespace() const;
  const std::string& element_name() const;

  /*
   * Uses the current stack of namespaces to resolve the package. Eg:
   * xmlns:app = "http://schemas.android.com/apk/res/com.android.app"
   * ...
   * android:text="@app:string/message"
   *
   * In this case, 'app' will be converted to 'com.android.app'.
   *
   * If xmlns:app="http://schemas.android.com/apk/res-auto", then
   * 'package' will be set to 'defaultPackage'.
   */
  std::optional<ExtractedPackage> TransformPackageAlias(android::StringPiece alias) const override;

  struct PackageDecl {
    std::string prefix;
    ExtractedPackage package;
  };

  const std::vector<PackageDecl>& package_decls() const;

  //
  // Remaining methods are for retrieving information about attributes
  // associated with a StartElement.
  //
  // Attributes must be in sorted order (according to the less than operator
  // of struct Attribute).
  //

  struct Attribute {
    std::string namespace_uri;
    std::string name;
    std::string value;

    int compare(const Attribute& rhs) const;
    bool operator<(const Attribute& rhs) const;
    bool operator==(const Attribute& rhs) const;
    bool operator!=(const Attribute& rhs) const;
  };

  using const_iterator = std::vector<Attribute>::const_iterator;

  const_iterator begin_attributes() const;
  const_iterator end_attributes() const;
  size_t attribute_count() const;
  const_iterator FindAttribute(android::StringPiece namespace_uri, android::StringPiece name) const;

 private:
  DISALLOW_COPY_AND_ASSIGN(XmlPullParser);

  static void XMLCALL StartNamespaceHandler(void* user_data, const char* prefix,
                                            const char* uri);
  static void XMLCALL StartElementHandler(void* user_data, const char* name,
                                          const char** attrs);
  static void XMLCALL CharacterDataHandler(void* user_data, const char* s,
                                           int len);
  static void XMLCALL EndElementHandler(void* user_data, const char* name);
  static void XMLCALL EndNamespaceHandler(void* user_data, const char* prefix);
  static void XMLCALL CommentDataHandler(void* user_data, const char* comment);
  static void XMLCALL StartCdataSectionHandler(void* user_data);
  static void XMLCALL EndCdataSectionHandler(void* user_data);

  struct EventData {
    Event event;
    size_t line_number;
    size_t depth;
    std::string data1;
    std::string data2;
    std::vector<Attribute> attributes;
  };

  android::InputStream* in_;
  XML_Parser parser_;
  std::queue<EventData> event_queue_;
  std::string error_;
  const std::string empty_;
  size_t depth_;
  std::stack<std::string> namespace_uris_;
  std::vector<PackageDecl> package_aliases_;
};

/**
 * Finds the attribute in the current element within the global namespace.
 */
std::optional<android::StringPiece> FindAttribute(const XmlPullParser* parser,
                                                  android::StringPiece name);

/**
 * Finds the attribute in the current element within the given namespace.
 */
std::optional<android::StringPiece> FindAttribute(const XmlPullParser* parser,
                                                  android::StringPiece namespace_uri,
                                                  android::StringPiece name);

/**
 * Finds the attribute in the current element within the global namespace. The
 * attribute's value
 * must not be the empty string.
 */
std::optional<android::StringPiece> FindNonEmptyAttribute(const XmlPullParser* parser,
                                                          android::StringPiece name);

//
// Implementation
//

inline ::std::ostream& operator<<(::std::ostream& out,
                                  XmlPullParser::Event event) {
  switch (event) {
    case XmlPullParser::Event::kBadDocument:
      return out << "BadDocument";
    case XmlPullParser::Event::kStartDocument:
      return out << "StartDocument";
    case XmlPullParser::Event::kEndDocument:
      return out << "EndDocument";
    case XmlPullParser::Event::kStartNamespace:
      return out << "StartNamespace";
    case XmlPullParser::Event::kEndNamespace:
      return out << "EndNamespace";
    case XmlPullParser::Event::kStartElement:
      return out << "StartElement";
    case XmlPullParser::Event::kEndElement:
      return out << "EndElement";
    case XmlPullParser::Event::kText:
      return out << "Text";
    case XmlPullParser::Event::kComment:
      return out << "Comment";
    case XmlPullParser::Event::kCdataStart:
      return out << "CdataStart";
    case XmlPullParser::Event::kCdataEnd:
      return out << "CdataEnd";
  }
  return out;
}

inline bool XmlPullParser::NextChildNode(XmlPullParser* parser, size_t start_depth) {
  Event event;

  // First get back to the start depth.
  while (IsGoodEvent(event = parser->Next()) && parser->depth() > start_depth + 1) {
  }

  // Now look for the first good node.
  while ((event != Event::kEndElement || parser->depth() > start_depth) && IsGoodEvent(event)) {
    switch (event) {
      case Event::kText:
      case Event::kComment:
      case Event::kStartElement:
      case Event::kCdataStart:
      case Event::kCdataEnd:
        return true;
      default:
        break;
    }
    event = parser->Next();
  }
  return false;
}

inline bool XmlPullParser::SkipCurrentElement(XmlPullParser* parser) {
  int depth = 1;
  while (depth > 0) {
    switch (parser->Next()) {
      case Event::kEndDocument:
        return true;
      case Event::kBadDocument:
        return false;
      case Event::kStartElement:
        depth++;
        break;
      case Event::kEndElement:
        depth--;
        break;
      default:
        break;
    }
  }
  return true;
}

inline bool XmlPullParser::IsGoodEvent(XmlPullParser::Event event) {
  return event != Event::kBadDocument && event != Event::kEndDocument;
}

inline int XmlPullParser::Attribute::compare(const Attribute& rhs) const {
  int cmp = namespace_uri.compare(rhs.namespace_uri);
  if (cmp != 0) return cmp;
  return name.compare(rhs.name);
}

inline bool XmlPullParser::Attribute::operator<(const Attribute& rhs) const {
  return compare(rhs) < 0;
}

inline bool XmlPullParser::Attribute::operator==(const Attribute& rhs) const {
  return compare(rhs) == 0;
}

inline bool XmlPullParser::Attribute::operator!=(const Attribute& rhs) const {
  return compare(rhs) != 0;
}

}  // namespace xml
}  // namespace aapt

#endif  // AAPT_XML_PULL_PARSER_H
