OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ |
| 5 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ |
| 6 |
| 7 #include <string> |
| 8 |
| 9 namespace extensions { |
| 10 |
| 11 // A pattern that can be used to match socket permission. |
| 12 // <socket-permission-pattern> |
| 13 // := <op> | <op> ':' <host> | <op> ':' ':' <port> | |
| 14 // <op> ':' <host> ':' <port> |
| 15 // <op> := 'tcp-connect' | 'tcp-listen' | 'udp-bind' | 'udp-send-to' |
| 16 // <host> := '*' | '*.' <anychar except '/' and '*'>+ |
| 17 // <port> := '*' | <port number between 0 and 65535>) |
| 18 class SocketPermissionData { |
| 19 public: |
| 20 enum OperationType { |
| 21 NONE = 0, |
| 22 TCP_CONNECT, |
| 23 TCP_LISTEN, |
| 24 UDP_BIND, |
| 25 UDP_SEND_TO, |
| 26 }; |
| 27 |
| 28 SocketPermissionData(); |
| 29 ~SocketPermissionData(); |
| 30 |
| 31 // operators <, == are needed by container std::set and algorithms |
| 32 // std::set_includes and std::set_differences. |
| 33 bool operator<(const SocketPermissionData& rhs) const; |
| 34 bool operator==(const SocketPermissionData& rhs) const; |
| 35 |
| 36 bool Match(OperationType type, const std::string& host, int port) const; |
| 37 |
| 38 bool Parse(const std::string& permission); |
| 39 |
| 40 const std::string& GetAsString() const; |
| 41 |
| 42 private: |
| 43 void Reset(); |
| 44 |
| 45 OperationType type_; |
| 46 std::string host_; |
| 47 bool match_subdomains_; |
| 48 int port_; |
| 49 mutable std::string spec_; |
| 50 }; |
| 51 |
| 52 } // namespace extensions |
| 53 |
| 54 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_SOCKET_PERMISSION_DATA_H_ |
OLD | NEW |