PageRenderTime 48ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/code/classes/Daemon/DNSd/Type/RFC4408.class.php

https://github.com/blekkzor/pinetd2
PHP | 38 lines | 31 code | 5 blank | 2 comment | 3 complexity | e91b3701339926f256f7503de0ec5106 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // http://www.ietf.org/rfc/rfc4408.txt
  3. // Type "SPF" works same as type "TXT"
  4. namespace Daemon\DNSd\Type;
  5. class RFC4408 extends Base {
  6. const TYPE_SPF = 99;
  7. public function decode($val, array $context) {
  8. switch($this->type) {
  9. case self::TYPE_SPF:
  10. $len = ord($val[0]);
  11. if ((strlen($val) + 1) < $len) {
  12. $this->value = NULL;
  13. break;
  14. }
  15. $this->value = substr($val, 1, $len);
  16. break;
  17. default: // unknown type
  18. $this->value = $val;
  19. return false;
  20. }
  21. return true;
  22. }
  23. public function encode($val = NULL, $offset = NULL) {
  24. if (is_null($val)) $val = $this->value;
  25. switch($this->type) {
  26. case self::TYPE_SPF:
  27. if (strlen($val) > 255) $val = substr($val, 0, 255);
  28. return chr(strlen($val)) . $val;
  29. default: // unknown type
  30. return $val;
  31. }
  32. }
  33. }