metaregistrar / php-epp-client

Object-oriented PHP EPP Client
https://www.metaregistrar.com/docs/
MIT License
214 stars 160 forks source link

eppCheckResponse #32

Closed karborator closed 8 years ago

karborator commented 8 years ago

The problem

domains are with taken availability status

Debuging

I think there is wrong using of strpos at eppCheckResponse :

If we take a look at : if (strpos($child->tagName, ':name')) or if (strpos($child->tagName, ':reason')) this checks will return false because $child->tagName is just "name" without ":" ( at my situation Ficora registry )

But even if we fix this , another problem will just appear because of how strpos works. Some times it returns FALSE but sometime it can return 0 ( position of the first occurrence) which will be evaluates to FALSE.The same situation is for ":reason" check . So , availability status will be affected , always taken !

I do not know the epp protocol and because of that I want to ask is the expected values , for $child->tagName are just "name" , "reason" or ":name",":reason" (my situation is without dots like that ":") ?

public function getCheckedDomains() {
    if ($this->getResultCode() == self::RESULT_SUCCESS) {
        $result = array();
        $xpath = $this->xPath();
        $domains = $xpath->query('/epp:epp/epp:response/epp:resData/domain:chkData/domain:cd');
        foreach ($domains as $domain) {
            $childs = $domain->childNodes;
            $checkeddomain = array('domainname' => null, 'available' => false, 'reason' => null);
            foreach ($childs as $child) {
                if ($child instanceof \domElement) {
                    if (strpos($child->tagName, ':name')) {
                        $available = $child->getAttribute('avail');
                        switch ($available) {
                            case '0':
                            case 'false':
                                $checkeddomain['available'] = false;
                                break;
                            case '1':
                            case 'true':
                                $checkeddomain['available'] = true;
                                break;
                        }
                        $checkeddomain['domainname'] = $child->nodeValue;
                    }
                    if (strpos($child->tagName, ':reason')) {
                        $checkeddomain['reason'] = $child->nodeValue;
                    }
                }
            }
            $result[] = $checkeddomain;
        }
    }
    return ($result);
}

Printed $child obj :

DOMElement Object ( [tagName] => name [schemaTypeInfo] => [nodeName] => name [nodeValue] => sevdi-a-demo.fi [nodeType] => 1 [parentNode] => (object value omitted) [childNodes] => (object value omitted) [firstChild] => (object value omitted) [lastChild] => (object value omitted) [previousSibling] => (object value omitted) [nextSibling] => (object value omitted) [attributes] => (object value omitted) [ownerDocument] => (object value omitted) [namespaceURI] => urn:ietf:params:xml:ns:domain-1.0 [prefix] => [localName] => name [baseURI] => /var/www/html/ApiHawk/PrimeEngine/ [textContent] => sevdi-a-demo.fi )

metaregistrar commented 8 years ago

The normal EPP response for a domain check is (https://tools.ietf.org/html/rfc5731#section-3.1.1) <?xml version="1.0" encoding="UTF-8" standalone="no"?> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> <response> <result code="1000"> <msg>Command completed successfully</msg> </result> <resData> <domain:chkData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> <domain:cd> <domain:name avail="1">example.com</domain:name> </domain:cd> <domain:cd> <domain:name avail="0">example.net</domain:name> <domain:reason>In use</domain:reason> </domain:cd> <domain:cd> <domain:name avail="1">example.org</domain:name> </domain:cd> </domain:chkData> </resData> <trID> <clTRID>ABC-12345</clTRID> <svTRID>54322-XYZ</svTRID> </trID> </response> </epp> You can see that the tag domain:name contains the semicolon. Most registries use domain:name and domain:reason, but i have also seen dom:name and dom:reason, thats why the check is with the semicolon.

That being said, this is very old code and a strpos on a domdocument is not the most elegant way to find out which tag we are processing, i will see if i can fix this shortly.

karborator commented 8 years ago

Great thanks :+1:

metaregistrar commented 8 years ago

I have pushed a change that removes the strpos and just checks for 'name' and 'reason'