Exemple #1
0
/**
 * This function resolves host name or dotted IP representation into 32 bit
 * binary IP address in host byte order. This function mostly deals with the
 * stupidity of Windoze implementation of gethostbyname() which, given an
 * IP address in standard dot notation, is unable to convert it into a 
 * binary form. 
 */
Bool INET_ResolveAddr(Str s, IPaddr * addr)
{
    Bool ok = False;
    if (s) {
        while (*s && IsSpace(*s)) s++;
        if (*s) {
#ifdef UNICODE
            char * host = STRING_ToMultiByte(s);
            if (host) {
#else  /* UNICODE */
                const char * host = s;
#endif /* UNICODE */
                IPaddr tmp = inet_addr(host);
                if (tmp == INADDR_NONE) {
                    struct hostent * h = gethostbyname(host);
                    if (h && h->h_addr_list[0]) {
                        tmp = *((IPaddr*)h->h_addr_list[0]);
                        ok = True;
                    }
                } else {
                    ok = True;
                }
                if (ok && addr) *addr = ntohl(tmp);
#ifdef UNICODE
                MEM_Free(host);
            }
#endif /* UNICODE */
        }
    }
    return ok;
}
Exemple #2
0
STATIC void EXPAT_StartElement(void * ctx, XML_Str tag, XML_Str * atts)
{
    ExpatContext * expat = (ExpatContext *)ctx;
    if (expat->cb.startElem) {
        XMLAttr aset;
        XML_Str * s = atts;

        BUFFER_Clear(&expat->buf);
        BUFFER_Clear(&expat->atts);
        while (*s) {
            wchar_t* ws;
            XML_Str xs = *s++;

            /* 
             * store offset in the vector - later will be replaces with the 
             * pointer. Cannot store the pointers now because buffer may be
             * reallocated during conversion. 
             */
            const int off = BUFFER_Size(&expat->buf)/sizeof(Char);
            BUFFER_Put(&expat->atts, &off, sizeof(off), False);

            /* Convert from UTF-8 XML_Str to Str */
            ws = STRING_ToUnicode(xs);
            if (ws) {
#ifdef UNICODE
                BUFFER_Put(&expat->buf,ws,(wcslen(ws)+1)*sizeof(ws[0]),False);
#else
                char * mb = STRING_ToMultiByte(ws);
                if (mb) {
                    BUFFER_Put(&expat->buf, mb, strlen(mb)+1, False);
                    MEM_Free(mb);
                } else {
                    BUFFER_Put(&expat->buf, xs, strlen(xs)+1, False);
                }
#endif
                MEM_Free(ws);
            }
        }

        ASSERT(!((BUFFER_Size(&expat->atts)/sizeof(int))%2));
        aset.storage = BUFFER_Access(&expat->buf);
        aset.size = BUFFER_Size(&expat->buf);
        aset.off = BUFFER_Access(&expat->atts);
        aset.n = BUFFER_Size(&expat->atts)/sizeof(int)/2;

        EXPAT_ConvertTag(&expat->sb, tag);
        (*expat->cb.startElem)(expat->ctx, STRBUF_Text(&expat->sb), &aset);
    }
}