1 module soup.HSTSPolicy; 2 3 private import glib.ConstructionException; 4 private import glib.MemorySlice; 5 private import glib.Str; 6 private import gobject.ObjectG; 7 private import soup.Date; 8 private import soup.Message; 9 private import soup.c.functions; 10 public import soup.c.types; 11 12 13 /** 14 * #SoupHSTSPolicy implements HTTP policies, as described by <ulink 15 * url="http://tools.ietf.org/html/rfc6797">RFC 6797</ulink>. 16 * 17 * To have a #SoupSession handle HSTS policies for your appliction 18 * automatically, use a #SoupHSTSEnforcer. 19 * 20 * Since: 2.68 21 */ 22 public final class HSTSPolicy 23 { 24 /** the main Gtk struct */ 25 protected SoupHSTSPolicy* soupHSTSPolicy; 26 protected bool ownedRef; 27 28 /** Get the main Gtk struct */ 29 public SoupHSTSPolicy* getHSTSPolicyStruct(bool transferOwnership = false) 30 { 31 if (transferOwnership) 32 ownedRef = false; 33 return soupHSTSPolicy; 34 } 35 36 /** the main Gtk struct as a void* */ 37 protected void* getStruct() 38 { 39 return cast(void*)soupHSTSPolicy; 40 } 41 42 /** 43 * Sets our main struct and passes it to the parent class. 44 */ 45 public this (SoupHSTSPolicy* soupHSTSPolicy, bool ownedRef = false) 46 { 47 this.soupHSTSPolicy = soupHSTSPolicy; 48 this.ownedRef = ownedRef; 49 } 50 51 ~this () 52 { 53 if ( ownedRef ) 54 soup_hsts_policy_free(soupHSTSPolicy); 55 } 56 57 58 /** 59 * The domain or hostname that the policy applies to 60 */ 61 public @property string domain() 62 { 63 return Str.toString(soupHSTSPolicy.domain); 64 } 65 66 /** Ditto */ 67 public @property void domain(string value) 68 { 69 soupHSTSPolicy.domain = Str.toStringz(value); 70 } 71 72 /** 73 * The maximum age, in seconds, that the policy is valid 74 */ 75 public @property ulong maxAge() 76 { 77 return soupHSTSPolicy.maxAge; 78 } 79 80 /** Ditto */ 81 public @property void maxAge(ulong value) 82 { 83 soupHSTSPolicy.maxAge = value; 84 } 85 86 /** 87 * the policy expiration time, or %NULL for a permanent session policy 88 */ 89 public @property Date expires() 90 { 91 return ObjectG.getDObject!(Date)(soupHSTSPolicy.expires, false); 92 } 93 94 /** Ditto */ 95 public @property void expires(Date value) 96 { 97 soupHSTSPolicy.expires = value.getDateStruct(); 98 } 99 100 /** 101 * %TRUE if the policy applies on subdomains 102 */ 103 public @property bool includeSubdomains() 104 { 105 return soupHSTSPolicy.includeSubdomains != 0; 106 } 107 108 /** Ditto */ 109 public @property void includeSubdomains(bool value) 110 { 111 soupHSTSPolicy.includeSubdomains = value; 112 } 113 114 /** */ 115 public static GType getType() 116 { 117 return soup_hsts_policy_get_type(); 118 } 119 120 /** 121 * Creates a new #SoupHSTSPolicy with the given attributes. 122 * 123 * @domain is a domain on which the strict transport security policy 124 * represented by this object must be enforced. 125 * 126 * @max_age is used to set the "expires" attribute on the policy; pass 127 * SOUP_HSTS_POLICY_MAX_AGE_PAST for an already-expired policy, or a 128 * lifetime in seconds. 129 * 130 * If @include_subdomains is %TRUE, the strict transport security policy 131 * must also be enforced on all subdomains of @domain. 132 * 133 * Params: 134 * domain = policy domain or hostname 135 * maxAge = max age of the policy 136 * includeSubdomains = %TRUE if the policy applies on subdomains 137 * 138 * Returns: a new #SoupHSTSPolicy. 139 * 140 * Since: 2.68 141 * 142 * Throws: ConstructionException GTK+ fails to create the object. 143 */ 144 public this(string domain, ulong maxAge, bool includeSubdomains) 145 { 146 auto __p = soup_hsts_policy_new(Str.toStringz(domain), maxAge, includeSubdomains); 147 148 if(__p is null) 149 { 150 throw new ConstructionException("null returned by new"); 151 } 152 153 this(cast(SoupHSTSPolicy*) __p); 154 } 155 156 /** 157 * Parses @msg's first "Strict-Transport-Security" response header and 158 * returns a #SoupHSTSPolicy. 159 * 160 * Params: 161 * msg = a #SoupMessage 162 * 163 * Returns: a new #SoupHSTSPolicy, or %NULL if no valid 164 * "Strict-Transport-Security" response header was found. 165 * 166 * Since: 2.68 167 * 168 * Throws: ConstructionException GTK+ fails to create the object. 169 */ 170 public this(Message msg) 171 { 172 auto __p = soup_hsts_policy_new_from_response((msg is null) ? null : msg.getMessageStruct()); 173 174 if(__p is null) 175 { 176 throw new ConstructionException("null returned by new_from_response"); 177 } 178 179 this(cast(SoupHSTSPolicy*) __p); 180 } 181 182 /** 183 * Full version of #soup_hsts_policy_new(), to use with an existing 184 * expiration date. See #soup_hsts_policy_new() for details. 185 * 186 * Params: 187 * domain = policy domain or hostname 188 * maxAge = max age of the policy 189 * expires = the date of expiration of the policy or %NULL for a permanent policy 190 * includeSubdomains = %TRUE if the policy applies on subdomains 191 * 192 * Returns: a new #SoupHSTSPolicy. 193 * 194 * Since: 2.68 195 * 196 * Throws: ConstructionException GTK+ fails to create the object. 197 */ 198 public this(string domain, ulong maxAge, Date expires, bool includeSubdomains) 199 { 200 auto __p = soup_hsts_policy_new_full(Str.toStringz(domain), maxAge, (expires is null) ? null : expires.getDateStruct(), includeSubdomains); 201 202 if(__p is null) 203 { 204 throw new ConstructionException("null returned by new_full"); 205 } 206 207 this(cast(SoupHSTSPolicy*) __p); 208 } 209 210 /** 211 * Creates a new session #SoupHSTSPolicy with the given attributes. 212 * A session policy is a policy that is valid during the lifetime of 213 * the #SoupHSTSEnforcer it is added to. Contrary to regular policies, 214 * it has no expiration date and is not stored in persistent 215 * enforcers. These policies are useful for user-agent to load their 216 * own or user-defined rules. 217 * 218 * @domain is a domain on which the strict transport security policy 219 * represented by this object must be enforced. 220 * 221 * If @include_subdomains is %TRUE, the strict transport security policy 222 * must also be enforced on all subdomains of @domain. 223 * 224 * Params: 225 * domain = policy domain or hostname 226 * includeSubdomains = %TRUE if the policy applies on sub domains 227 * 228 * Returns: a new #SoupHSTSPolicy. 229 * 230 * Since: 2.68 231 * 232 * Throws: ConstructionException GTK+ fails to create the object. 233 */ 234 public this(string domain, bool includeSubdomains) 235 { 236 auto __p = soup_hsts_policy_new_session_policy(Str.toStringz(domain), includeSubdomains); 237 238 if(__p is null) 239 { 240 throw new ConstructionException("null returned by new_session_policy"); 241 } 242 243 this(cast(SoupHSTSPolicy*) __p); 244 } 245 246 /** 247 * Copies @policy. 248 * 249 * Returns: a copy of @policy 250 * 251 * Since: 2.68 252 */ 253 public HSTSPolicy copy() 254 { 255 auto __p = soup_hsts_policy_copy(soupHSTSPolicy); 256 257 if(__p is null) 258 { 259 return null; 260 } 261 262 return ObjectG.getDObject!(HSTSPolicy)(cast(SoupHSTSPolicy*) __p, true); 263 } 264 265 /** 266 * Tests if @policy1 and @policy2 are equal. 267 * 268 * Params: 269 * policy2 = a #SoupHSTSPolicy 270 * 271 * Returns: whether the policies are equal. 272 * 273 * Since: 2.68 274 */ 275 public bool equal(HSTSPolicy policy2) 276 { 277 return soup_hsts_policy_equal(soupHSTSPolicy, (policy2 is null) ? null : policy2.getHSTSPolicyStruct()) != 0; 278 } 279 280 /** 281 * Frees @policy. 282 * 283 * Since: 2.68 284 */ 285 public void free() 286 { 287 soup_hsts_policy_free(soupHSTSPolicy); 288 ownedRef = false; 289 } 290 291 /** 292 * Gets @policy's domain. 293 * 294 * Returns: @policy's domain. 295 * 296 * Since: 2.68 297 */ 298 public string getDomain() 299 { 300 return Str.toString(soup_hsts_policy_get_domain(soupHSTSPolicy)); 301 } 302 303 /** 304 * Gets whether @policy include its subdomains. 305 * 306 * Returns: %TRUE if @policy includes subdomains, %FALSE otherwise. 307 * 308 * Since: 2.68 309 */ 310 public bool includesSubdomains() 311 { 312 return soup_hsts_policy_includes_subdomains(soupHSTSPolicy) != 0; 313 } 314 315 /** 316 * Gets whether @policy is expired. Permanent policies never 317 * expire. 318 * 319 * Returns: %TRUE if @policy is expired, %FALSE otherwise. 320 * 321 * Since: 2.68 322 */ 323 public bool isExpired() 324 { 325 return soup_hsts_policy_is_expired(soupHSTSPolicy) != 0; 326 } 327 328 /** 329 * Gets whether @policy is a non-permanent, non-expirable session policy. 330 * see soup_hsts_policy_new_session_policy() for details. 331 * 332 * Returns: %TRUE if @policy is permanent, %FALSE otherwise 333 * 334 * Since: 2.68 335 */ 336 public bool isSessionPolicy() 337 { 338 return soup_hsts_policy_is_session_policy(soupHSTSPolicy) != 0; 339 } 340 }