コード例 #1
0
ファイル: http.c プロジェクト: saiful76/pazpar2
static int http_parse_arguments(struct http_request *r, NMEM nmem,
                                const char *args)
{
    const char *p2 = args;

    while (*p2)
    {
        struct http_argument *a;
        const char *equal = strchr(p2, '=');
        const char *eoa = strchr(p2, '&');
        if (!equal)
        {
            yaz_log(YLOG_WARN, "Expected '=' in argument");
            return -1;
        }
        if (!eoa)
            eoa = equal + strlen(equal); // last argument
        else if (equal > eoa)
        {
            yaz_log(YLOG_WARN, "Missing '&' in argument");
            return -1;
        }
        a = nmem_malloc(nmem, sizeof(struct http_argument));
        a->name = nmem_strdupn(nmem, p2, equal - p2);
        a->value = nmem_strdupn(nmem, equal+1, eoa - equal - 1);
        urldecode(a->name, a->name);
        urldecode(a->value, a->value);
        a->next = r->arguments;
        r->arguments = a;
        p2 = eoa;
        while (*p2 == '&')
            p2++;
    }
    return 0;
}
コード例 #2
0
ファイル: http.c プロジェクト: saiful76/pazpar2
/* Accept a new command connection */
static void http_accept(IOCHAN i, int event)
{
    struct sockaddr_in addr;
    int fd = iochan_getfd(i);
    socklen_t len;
    int s;
    IOCHAN c;
    struct http_channel *ch;
    struct conf_server *server = iochan_getdata(i);

    len = sizeof addr;
    if ((s = accept(fd, (struct sockaddr *) &addr, &len)) < 0)
    {
        yaz_log(YLOG_WARN|YLOG_ERRNO, "accept");
        return;
    }
    enable_nonblock(s);

    yaz_log(YLOG_DEBUG, "New command connection");
    c = iochan_create(s, http_io, EVENT_INPUT | EVENT_EXCEPT, "http_session_socket");
    
    ch = http_channel_create(server->http_server, inet_ntoa(addr.sin_addr),
                             server);
    ch->iochan = c;
    iochan_setdata(c, ch);
    iochan_add(server->iochan_man, c);
}
コード例 #3
0
static int compare(cql_transform_t ct, const char *pqf, const char *cql)
{
    int ret = 0;
    ODR odr = odr_createmem(ODR_ENCODE);
    WRBUF w = wrbuf_alloc();
    Z_RPNQuery *q = p_query_rpn(odr, pqf);
    
    if (q)
    {
        int r = cql_transform_rpn2cql_wrbuf(ct, w, q);

        if (r != 0)
        {
            /* transform error */
            yaz_log(YLOG_LOG, "%s -> Error %d", pqf, r);
            if (!cql) /* also expected error? */
                ret = 1;
        }
        else if (r == 0)
        {
            yaz_log(YLOG_LOG, "%s -> %s", pqf, wrbuf_cstr(w));
            if (cql && !strcmp(wrbuf_cstr(w), cql))
            {
                ret = 1;
            }
        }
    }
    wrbuf_destroy(w);
    odr_destroy(odr);
    return ret;
}
コード例 #4
0
ファイル: database.c プロジェクト: dcrossleyau/pazpar2
struct database *new_database_inherit_settings(const char *id, NMEM nmem, struct settings_array *service_settings)
{
    struct database *db;
    struct setting *idset;

    db = nmem_malloc(nmem, sizeof(*db));
    db->id = nmem_strdup(nmem, id);
    db->next = 0;

    if (service_settings && service_settings->num_settings > 0) {
        yaz_log(YLOG_DEBUG, "copying settings from service to database %s settings", db->id);
        db->num_settings = service_settings->num_settings;
        db->settings = nmem_malloc(nmem, sizeof(*db->settings) * db->num_settings);
        // Initialize database settings with service settings
        memcpy(db->settings, service_settings->settings,  sizeof(*db->settings) * db->num_settings);
    }
    else {
        yaz_log(YLOG_DEBUG, "No service settings to database %s ", db->id);
        db->num_settings = PZ_MAX_EOF;
        db->settings = nmem_malloc(nmem, sizeof(*db->settings) * db->num_settings);
        memset(db->settings, 0, sizeof(*db->settings) * db->num_settings);
    }
    idset = nmem_malloc(nmem, sizeof(*idset));
    idset->precedence = 0;
    idset->name = "pz:id";
    idset->target = idset->value = db->id;
    idset->next = db->settings[PZ_ID];
    db->settings[PZ_ID] = idset;

    return db;
}
コード例 #5
0
static void xml_config_bend_start(void)
{
    if (control_block.xml_config[0])
    {
        struct gfs_server *gfs = gfs_server_list;
        for (; gfs; gfs = gfs->next)
        {
            yaz_log(YLOG_DEBUG, "xml_config_bend_start config=%s",
                    gfs->cb.configname);
            statserv_setcontrol(&gfs->cb);
            if (control_block.bend_start)
            {
                gfs_server_chdir(gfs);
                (control_block.bend_start)(&gfs->cb);
            }
        }
    }
    else
    {
        yaz_log(YLOG_DEBUG, "xml_config_bend_start default config");
        statserv_setcontrol(&control_block);
        if (control_block.bend_start)
            (*control_block.bend_start)(&control_block);
    }
}
コード例 #6
0
ファイル: charsets.c プロジェクト: pombredanne/pazpar2
pp2_charset_t pp2_charset_create_xml(xmlNode *xml_node)
{
#if YAZ_HAVE_ICU
    UErrorCode status = U_ZERO_ERROR;
    struct icu_chain *chain = 0;
    while (xml_node && xml_node->type != XML_ELEMENT_NODE)
        xml_node = xml_node->next;
    chain = icu_chain_xml_config(xml_node, 1, &status);
    if (!chain || U_FAILURE(status)){
        //xmlDocPtr icu_doc = 0;
        //xmlChar *xmlstr = 0;
                //int size = 0;
                //xmlDocDumpMemory(icu_doc, size);
        
        yaz_log(YLOG_FATAL, "Could not parse ICU chain config:\n"
                "<%s>\n ... \n</%s>",
                xml_node->name, xml_node->name);
        return 0;
    }
    return pp2_charset_create(chain);
#else // YAZ_HAVE_ICU
    yaz_log(YLOG_FATAL, "Error: ICU support requested with element:\n"
            "<%s>\n ... \n</%s>",
            xml_node->name, xml_node->name);
    yaz_log(YLOG_FATAL, 
            "But no ICU support is compiled into the YAZ library.");
    return 0;
#endif // YAZ_HAVE_ICU
}
コード例 #7
0
ファイル: http_command.c プロジェクト: piskvorky/pazpar2
void http_session_destroy(struct http_session *s)
{
    int must_destroy = 0;

    http_sessions_t http_sessions = s->http_sessions;

    yaz_log(http_sessions->log_level, "Session %u destroy", s->session_id);
    yaz_mutex_enter(http_sessions->mutex);
    /* only if http_session has no active http sessions on it can be destroyed */
    if (s->destroy_counter == s->activity_counter)
    {
        struct http_session **p = 0;
        must_destroy = 1;
        for (p = &http_sessions->session_list; *p; p = &(*p)->next)
            if (*p == s)
            {
                *p = (*p)->next;
                break;
            }
    }
    yaz_mutex_leave(http_sessions->mutex);
    if (must_destroy)
    {   /* destroying for real */
        yaz_log(http_sessions->log_level, "Session %u destroyed", s->session_id);
        iochan_destroy(s->timeout_iochan);
        session_destroy(s->psession);
        http_session_use(-1);
        nmem_destroy(s->nmem);
    }
    else {
        yaz_log(http_sessions->log_level, "Session %u destroying delayed. Active clients (%d-%d). Waiting for new timeout.",
                s->session_id, s->activity_counter, s->destroy_counter);
    }

}
コード例 #8
0
ファイル: test.c プロジェクト: nla/yaz
void yaz_check_print1(int type, const char *file, int line,
                      const char *expr)
{
    const char *msg = "unknown";
    int printit = 1;

    test_total++;
    switch(type)
    {
    case YAZ_TEST_TYPE_FAIL:
        test_failed++;
        msg = "FAILED";
        if (test_verbose < 1)
            printit = 0;
        break;
    case YAZ_TEST_TYPE_OK:
        msg = "ok";
        if (test_verbose < 3)
            printit = 0;
        break;
    }
    if (printit)
    {
        fprintf(get_file(), "%s:%d: %s: ", file, line, msg);
        fprintf(get_file(), "%s\n", expr);
    }
    if (log_tests)
    {
        yaz_log(YLOG_LOG, "%s:%d %s: ", file, line, msg);
        yaz_log(YLOG_LOG, "%s", expr);
    }
}
コード例 #9
0
ファイル: connection.c プロジェクト: pombredanne/pazpar2
static void connection_handler(IOCHAN iochan, int event)
{
    struct connection *co = iochan_getdata(iochan);
    struct client *cl;
    struct host *host = co->host;

    yaz_mutex_enter(host->mutex);
    cl = co->client;
    if (!cl) 
    {
        /* no client associated with it.. We are probably getting
           a closed connection from the target.. Or, perhaps, an unexpected
           package.. We will just close the connection */
        yaz_log(YLOG_LOG, "timeout connection %p event=%d", co, event);
        remove_connection_from_host(co);
        yaz_mutex_leave(host->mutex);
        connection_destroy(co);
    }
    else if (event & EVENT_TIMEOUT)
    {
        if (co->state == Conn_Connecting)
        {
            yaz_log(YLOG_WARN, "%p connect timeout %s", co, client_get_id(cl));

            client_set_state(cl, Client_Error);
            remove_connection_from_host(co);
            yaz_mutex_leave(host->mutex);
            connection_destroy(co);
        }
        else
        {
            yaz_log(YLOG_LOG,  "%p Connection idle timeout %s", co, client_get_id(cl));
            remove_connection_from_host(co);
            yaz_mutex_leave(host->mutex);
            connection_destroy(co);
        }
    }
    else
    {
        yaz_mutex_leave(host->mutex);

        client_lock(cl);
        non_block_events(co);

        ZOOM_connection_fire_event_socket(co->link, event);
        
        non_block_events(co);
        client_unlock(cl);

        if (co->link)
        {
            iochan_setflags(iochan, ZOOM_connection_get_mask(co->link));
            iochan_setfd(iochan, ZOOM_connection_get_socket(co->link));
        }
    }
}
コード例 #10
0
ファイル: test_icu.c プロジェクト: dcrossleyau/yaz
static void check_icu_chain(void)
{
    const char *en_str
        = "O Romeo, Romeo! wherefore art thou\t Romeo?";

    UErrorCode status = U_ZERO_ERROR;
    struct icu_chain *chain = 0;

    const char *xml_str = "<icu locale=\"en\">"
        "<transform rule=\"[:Control:] Any-Remove\"/>"
        "<tokenize rule=\"l\"/>"
        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
        "<display/>"
        "<casemap rule=\"l\"/>"
        "</icu>";


    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
    xmlNode *xml_node = xmlDocGetRootElement(doc);
    YAZ_CHECK(xml_node);

    chain = icu_chain_xml_config(xml_node, 0, &status);

    xmlFreeDoc(doc);
    YAZ_CHECK(chain);
    if (!chain)
        return;

    YAZ_CHECK(icu_chain_assign_cstr(chain, en_str, &status));

    while (icu_chain_next_token(chain, &status))
    {
        yaz_log(YLOG_LOG, "%d '%s' '%s'",
                icu_chain_token_number(chain),
                icu_chain_token_norm(chain),
                icu_chain_token_display(chain));
    }

    YAZ_CHECK_EQ(icu_chain_token_number(chain), 7);


    YAZ_CHECK(icu_chain_assign_cstr(chain, "what is this?", &status));

    while (icu_chain_next_token(chain, &status))
    {
        yaz_log(YLOG_LOG, "%d '%s' '%s'",
                icu_chain_token_number(chain),
                icu_chain_token_norm(chain),
                icu_chain_token_display(chain));
    }


    YAZ_CHECK_EQ(icu_chain_token_number(chain), 3);

    icu_chain_destroy(chain);
}
コード例 #11
0
ファイル: getaddrinfo.c プロジェクト: jajm/pazpar2
void perform_getaddrinfo(struct work *w)
{
    struct addrinfo hints, *res;
    char host[512], *cp;
    char *port = 0;
    int error;

    hints.ai_flags = 0;
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = 0;
    hints.ai_addrlen        = 0;
    hints.ai_addr           = NULL;
    hints.ai_canonname      = NULL;
    hints.ai_next           = NULL;

    strncpy(host, w->hostport, sizeof(host)-1);
    host[sizeof(host)-1] = 0;
    if ((cp = strrchr(host, ':')))
    {
        *cp = '\0';
        port = cp + 1;
    }
    error = getaddrinfo(host, port ? port : "210", &hints, &res);
    if (error)
    {
        yaz_log(YLOG_WARN, "Failed to resolve %s: %s",
                w->hostport, gai_strerror(error));
    }
    else
    {
        char n_host[512];
        if (getnameinfo((struct sockaddr *) res->ai_addr, res->ai_addrlen,
                        n_host, sizeof(n_host)-1,
                        0, 0,
                        NI_NUMERICHOST) == 0)
        {
            w->ipport = xmalloc(strlen(n_host) + (port ? strlen(port) : 0) + 2);
            strcpy(w->ipport, n_host);
            if (port)
            {
                strcat(w->ipport, ":");
                strcat(w->ipport, port);
            }
            yaz_log(log_level, "Resolved %s -> %s", w->hostport, w->ipport);
        }
        else
        {
            yaz_log(YLOG_LOG|YLOG_ERRNO, "getnameinfo failed for %s",
                    w->hostport);
        }
        freeaddrinfo(res);
    }
}
コード例 #12
0
ファイル: http_command.c プロジェクト: piskvorky/pazpar2
static void cmd_termlist(struct http_channel *c)
{
    struct http_request *rq = c->request;
    struct http_response *rs = c->response;
    struct http_session *s = locate_session(c);
    const char *block = http_argbyname(rq, "block");
    const char *report = http_argbyname(rq, "report");
    int report_status = 0;
    int report_error = 0;
    const char *status_message = 0;
    int active_clients;
    if (report  && !strcmp("error", report)) {
        report_error = 1;
        status_message = "OK";
    }
    if (report  && !strcmp("status", report)) {
        report_status = 1;
        status_message = "OK";
    }
    if (!s)
        return;

    active_clients = session_active_clients(s->psession);
    if (block && !strcmp("1", block) && active_clients)
    {
        // if there is already a watch/block. we do not block this one
        if (session_set_watch(s->psession, SESSION_WATCH_TERMLIST,
                              termlist_result_ready, c, c) != 0)
        {
            yaz_log(YLOG_WARN, "Session %u: Attempt to block multiple times on termlist block. Not supported!", s->session_id);
            if (report_error) {
                error(rs, PAZPAR2_ALREADY_BLOCKED, "termlist");
                release_session(c, s);
                return;
            }
            else if (report_status) {
                status_message = "WARNING (Already blocked on termlist)";
            }
            else {
                yaz_log(YLOG_WARN, "Session %u: Ignoring termlist block. Return current result", s->session_id);
            }
        }
        else
        {
            yaz_log(c->http_sessions->log_level, "Session %u: Blocking on command termlist", s->session_id);
            release_session(c, s);
            return;
        }
    }

    termlist_response(c, s, status_message);
    release_session(c, s);
}
コード例 #13
0
ファイル: test_icu.c プロジェクト: dcrossleyau/yaz
static int test_icu_casemap(const char *locale, char action,
                            const char *src8cstr, const char *chk8cstr)
{
    int success = 0;
    UErrorCode status = U_ZERO_ERROR;

    struct icu_buf_utf8 *src8 = icu_buf_utf8_create(0);
    struct icu_buf_utf8 *dest8 = icu_buf_utf8_create(0);
    struct icu_buf_utf16 *src16 = icu_buf_utf16_create(0);
    struct icu_buf_utf16 *dest16 = icu_buf_utf16_create(0);


    int src8cstr_len = strlen(src8cstr);
    int chk8cstr_len = strlen(chk8cstr);

    /* converting to UTF16 */
    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);

    /* perform case mapping */
    icu_utf16_casemap(dest16, src16, locale, action, &status);

    /* converting to UTF8 */
    icu_utf16_to_utf8(dest8, dest16, &status);

    /* determine success */
    if (dest8->utf8
        && (dest8->utf8_len == strlen(chk8cstr))
        && !strcmp(chk8cstr, (const char *) dest8->utf8))
        success = 1;
    else
        success = 0;

    /* report failures */
    if (!success)
    {
        yaz_log(YLOG_WARN, "test_icu_casemap failed");
        yaz_log(YLOG_LOG, "Original string:   '%s' (%d)",
                src8cstr, src8cstr_len);
        yaz_log(YLOG_LOG, "icu_casemap '%s:%c' '%s' (%d)",
                locale, action, dest8->utf8, dest8->utf8_len);
        yaz_log(YLOG_LOG, "expected string:   '%s' (%d)",
                chk8cstr, chk8cstr_len);
    }

    /* clean the buffers */
    icu_buf_utf8_destroy(src8);
    icu_buf_utf8_destroy(dest8);
    icu_buf_utf16_destroy(src16);
    icu_buf_utf16_destroy(dest16);

    return success;
}
コード例 #14
0
ファイル: test_icu.c プロジェクト: dcrossleyau/yaz
static int test_icu_tokenizer(const char *locale, char action,
                              const char *src8cstr, int count)
{
    int success = 1;

    UErrorCode status = U_ZERO_ERROR;
    struct icu_buf_utf16 *src16 = icu_buf_utf16_create(0);
    struct icu_buf_utf16 *tkn16 = icu_buf_utf16_create(0);
    struct icu_buf_utf8 *tkn8 = icu_buf_utf8_create(0);
    struct icu_tokenizer *tokenizer = 0;
    size_t org_start, org_len;

    /* transforming to UTF16 */
    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
    icu_check_status(status);

    /* set up tokenizer */
    tokenizer = icu_tokenizer_create(locale, action, &status);
    icu_check_status(status);
    YAZ_CHECK(tokenizer);

    /* attach text buffer to tokenizer */
    icu_tokenizer_attach(tokenizer, src16, &status);
    icu_check_status(status);

    /* perform work on tokens */
    while (icu_tokenizer_next_token(tokenizer, tkn16, &status,
                                    &org_start, &org_len))
    {
        icu_check_status(status);

        /* converting to UTF8 */
        icu_utf16_to_utf8(tkn8, tkn16, &status);
    }

    if (count != icu_tokenizer_token_count(tokenizer))
    {
        success = 0;
        yaz_log(YLOG_LOG, "Tokenizer '%s:%c' Error:", locale, action);
        yaz_log(YLOG_LOG, " Input:  '%s'", src8cstr);
        yaz_log(YLOG_LOG, " Tokens: %d", icu_tokenizer_token_count(tokenizer));
        yaz_log(YLOG_LOG, " Expected: %d", count);
    }

    icu_tokenizer_destroy(tokenizer);
    icu_buf_utf16_destroy(src16);
    icu_buf_utf16_destroy(tkn16);
    icu_buf_utf8_destroy(tkn8);

    return success;
}
コード例 #15
0
/*
 * Set up a listening endpoint, and give it to the event-handler.
 */
static int add_listener(char *where, int listen_id)
{
    COMSTACK l;
    void *ap;
    IOCHAN lst = NULL;
    const char *mode;

    if (control_block.dynamic)
        mode = "dynamic";
    else if (control_block.threads)
        mode = "threaded";
    else
        mode = "static";

    yaz_log(log_server, "Adding %s listener on %s id=%d", mode, where,
            listen_id);

    l = cs_create_host(where, 2, &ap);
    if (!l)
    {
        yaz_log(YLOG_FATAL, "Failed to listen on %s", where);
        return -1;
    }
    if (*control_block.cert_fname)
        cs_set_ssl_certificate_file(l, control_block.cert_fname);

    if (cs_bind(l, ap, CS_SERVER) < 0)
    {
        if (cs_errno(l) == CSYSERR)
            yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to bind to %s", where);
        else
            yaz_log(YLOG_FATAL, "Failed to bind to %s: %s", where,
                    cs_strerror(l));
        cs_close(l);
        return -1;
    }
    if (!(lst = iochan_create(cs_fileno(l), listener, EVENT_INPUT |
                              EVENT_EXCEPT, listen_id)))
    {
        yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to create IOCHAN-type");
        cs_close(l);
        return -1;
    }
    iochan_setdata(lst, l); /* user-defined data for listener is COMSTACK */
    l->user = lst;  /* user-defined data for COMSTACK is listener chan */

    /* Add listener to chain */
    lst->next = pListener;
    pListener = lst;
    return 0; /* OK */
}
コード例 #16
0
static void gfs_server_chdir(struct gfs_server *gfs)
{
    if (gfs_root_dir[0])
    {
        if (chdir(gfs_root_dir))
            yaz_log(YLOG_WARN|YLOG_ERRNO, "chdir %s", gfs_root_dir);
    }
    if (gfs->directory)
    {
        if (chdir(gfs->directory))
            yaz_log(YLOG_WARN|YLOG_ERRNO, "chdir %s",
                    gfs->directory);
    }
}
コード例 #17
0
ファイル: mutex.c プロジェクト: dcrossleyau/yaz
void yaz_mutex_enter(YAZ_MUTEX p)
{
    if (p)
    {
#ifdef WIN32
        EnterCriticalSection(&p->handle);
#elif YAZ_POSIX_THREADS
        int r = 1; /* signal : not locked (yet) */

        if (p->log_level)
        {   /* debugging */
            r = pthread_mutex_trylock(&p->handle);
            if (r)
            {
#if HAVE_SYS_TIME_H
                long long d;
                struct timeval tv1, tv2;
                gettimeofday(&tv1, 0);
#endif
                yaz_log(p->log_level,
                        "yaz_mutex_enter: %p tid=%p name=%s waiting",
                        p, (void *) pthread_self(), p->name);
#if HAVE_SYS_TIME_H
                r = pthread_mutex_lock(&p->handle);
                gettimeofday(&tv2, 0);
                d = 1000000LL * ((long long) tv2.tv_sec - tv1.tv_sec) +
                    tv2.tv_usec - tv1.tv_usec;
                yaz_log(p->log_level, "yaz_mutex_enter: %p tid=%p name=%s "
                        "lock delay %lld",
                        p, (void *) pthread_self(), p->name, d);
#endif
            }
            else
            {
                yaz_log(p->log_level, "yaz_mutex_enter: %p tid=%p name=%s lock",
                        p, (void *) pthread_self(), p->name);
            }
        }
        if (r)
        {
            r = pthread_mutex_lock(&p->handle);
            if (p->log_level)
            {
                yaz_log(p->log_level, "yaz_mutex_enter: %p tid=%p name=%s lock",
                        p, (void *) pthread_self(), p->name);
            }
        }
#endif
    }
}
コード例 #18
0
ファイル: http_command.c プロジェクト: piskvorky/pazpar2
static void bytarget_result_ready(void *data)
{
    struct http_channel *c = (struct http_channel *) data;
    struct http_session *s = locate_session(c);
    const char *status_message = "OK";
    if (s) {
        yaz_log(c->http_sessions->log_level, "Session %u: bytarget watch released", s->session_id);
        bytarget_response(c, s, status_message);
        release_session(c, s);
    }
    else {
        yaz_log(c->http_sessions->log_level, "No Session found for released bytarget watch");
    }
}
コード例 #19
0
ファイル: http.c プロジェクト: saiful76/pazpar2
static void enable_nonblock(int sock)
{
    int flags;
#ifdef WIN32
    flags = (flags & CS_FLAGS_BLOCKING) ? 0 : 1;
    if (ioctlsocket(sock, FIONBIO, &flags) < 0)
        yaz_log(YLOG_FATAL|YLOG_ERRNO, "ioctlsocket");
#else
    if ((flags = fcntl(sock, F_GETFL, 0)) < 0) 
        yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl");
    if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0)
        yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2");
#endif
}
コード例 #20
0
ファイル: icu_utf16.c プロジェクト: dcrossleyau/yaz
void icu_buf_utf16_log(const char *lead, struct icu_buf_utf16 *src16)
{
    if (src16)
    {
        struct icu_buf_utf8 *dst8 = icu_buf_utf8_create(0);
        UErrorCode status = U_ZERO_ERROR;
        icu_utf16_to_utf8(dst8, src16, &status);
        yaz_log(YLOG_LOG, "%s=%s", lead, dst8->utf8);
        icu_buf_utf8_destroy(dst8);
    }
    else
    {
        yaz_log(YLOG_LOG, "%s=NULL", lead);
    }
}
コード例 #21
0
ファイル: test_rpn2cql.c プロジェクト: drigolin/node-zoom
static int compare2(cql_transform_t ct, const char *pqf, const char *cql,
                    int expected_error)
{
    int ret = 0;
    ODR odr = odr_createmem(ODR_ENCODE);
    WRBUF w = wrbuf_alloc();
    Z_RPNQuery *q = p_query_rpn(odr, pqf);

    if (q)
    {
        int r = cql_transform_rpn2cql_wrbuf(ct, w, q);

        if (r != 0)
        {
            const char *addinfo = 0;
            int err = cql_transform_error(ct, &addinfo);
            /* transform error */
            yaz_log(YLOG_LOG, "%s -> Error %d", pqf, r);
            if (err == 0)
                ;
            else if (err == expected_error)
            {
                if (addinfo && cql && !strcmp(addinfo, cql))
                    ret = 1;
                else if (!addinfo && !cql)
                    ret = 1;
            }
        }
        else if (r == 0)
        {
            yaz_log(YLOG_LOG, "%s -> %s", pqf, wrbuf_cstr(w));
            if (!expected_error)
                ret = 1;
            else if (cql && !strcmp(wrbuf_cstr(w), cql))
            {
                ret = 1;
            }
            else
            {
                yaz_log(YLOG_WARN, " expected: %s", cql ? cql : "null");
                yaz_log(YLOG_WARN, " got:      %s", wrbuf_cstr(w));
            }
        }
    }
    wrbuf_destroy(w);
    odr_destroy(odr);
    return ret;
}
コード例 #22
0
ファイル: http_command.c プロジェクト: piskvorky/pazpar2
struct http_session *http_session_create(struct conf_service *service,
        http_sessions_t http_sessions,
        unsigned int sesid)
{
    NMEM nmem = nmem_create();
    struct http_session *r = nmem_malloc(nmem, sizeof(*r));
    char tmp_str[50];

    sprintf(tmp_str, "session#%u", sesid);
    r->psession = new_session(nmem, service, sesid);
    r->session_id = sesid;
    r->timestamp = 0;
    r->nmem = nmem;
    r->destroy_counter = r->activity_counter = 0;
    r->http_sessions = http_sessions;

    yaz_mutex_enter(http_sessions->mutex);
    r->next = http_sessions->session_list;
    http_sessions->session_list = r;
    yaz_mutex_leave(http_sessions->mutex);

    r->timeout_iochan = iochan_create(-1, session_timeout, 0, "http_session_timeout");
    iochan_setdata(r->timeout_iochan, r);
    yaz_log(http_sessions->log_level, "Session %u created. timeout chan=%p timeout=%d", sesid, r->timeout_iochan, service->session_timeout);
    iochan_settimeout(r->timeout_iochan, service->session_timeout);

    iochan_add(service->server->iochan_man, r->timeout_iochan);
    http_session_use(1);
    return r;
}
コード例 #23
0
ファイル: http.c プロジェクト: saiful76/pazpar2
static struct http_channel *http_channel_create(http_server_t hs,
                                                const char *addr,
                                                struct conf_server *server)
{
    struct http_channel *r;

    r = xmalloc(sizeof(struct http_channel));
    r->nmem = nmem_create();
    r->wrbuf = wrbuf_alloc();

    http_server_incref(hs);
    r->http_server = hs;
    r->http_sessions = hs->http_sessions;
    assert(r->http_sessions);
    r->server = server;
    r->proxy = 0;
    r->iochan = 0;
    r->iqueue = r->oqueue = 0;
    r->state = Http_Idle;
    r->keep_alive = 0;
    r->request = 0;
    r->response = 0;
    if (!addr)
    {
        yaz_log(YLOG_WARN, "Invalid HTTP forward address");
        exit(1);
    }
    strcpy(r->addr, addr);
    r->observers = 0;
    return r;
}
コード例 #24
0
ファイル: ztest.c プロジェクト: 2010fares/PMB
bend_initresult *bend_init(bend_initrequest *q)
{
    bend_initresult *r = (bend_initresult *)
        odr_malloc (q->stream, sizeof(*r));
    int *counter = (int *) xmalloc (sizeof(int));

    *counter = 0;
    r->errcode = 0;
    r->errstring = 0;
    r->handle = counter;         /* user handle, in this case a simple int */
    q->bend_sort = ztest_sort;              /* register sort handler */
    q->bend_search = ztest_search;          /* register search handler */
    q->bend_present = ztest_present;        /* register present handle */
    q->bend_esrequest = ztest_esrequest;
    q->bend_delete = ztest_delete;
    q->bend_fetch = ztest_fetch;
    q->bend_scan = ztest_scan;
    q->bend_explain = ztest_explain;
    
    if (read_conf_file()) {
    	yaz_log(LOG_LOG,"Can't handle configuration file");
    	r->errcode = 2;
    }
     return r;
}
コード例 #25
0
ファイル: charsets.c プロジェクト: pombredanne/pazpar2
int pp2_charset_fact_define(pp2_charset_fact_t pft,
                            xmlNode *xml_node, const char *default_id)
{
    int r;
    pp2_charset_t pct;
    xmlChar *id = 0;

    assert(xml_node);
    pct = pp2_charset_create_xml(xml_node);
    if (!pct)
        return -1;
    if (!default_id)
    {
        id = xmlGetProp(xml_node, (xmlChar*) "id");
        if (!id)
        {
            yaz_log(YLOG_WARN, "Missing id for icu_chain");
            pp2_charset_destroy(pct);
            return -1;
        }
        default_id = (const char *) id;
    }
    r = pp2_charset_fact_add(pft, pct, default_id);
    if (id)
        xmlFree(id);
    return r;
}
コード例 #26
0
ファイル: ztest.c プロジェクト: 2010fares/PMB
/* retrieval of a single record (present, and piggy back search) */
int ztest_fetch(void *handle, bend_fetch_rr *r)
{
	char query[100];
	
    r->errstring = 0;
    r->last_in_set = 0;
    r->basename = database;
    r->output_format = r->request_format;  
    
    
    if (cur_results>=n_results) {
      r->errcode=13;
      return 0;
    } else {
    	sprintf(query,"query=%s&command=get_notice",ids[cur_results]);
    	cur_results++;
    	if (cur_results==n_results) 
    		r->last_in_set=1;	
    		
      	if (http_get(query)) {	
			r->errcode=2;
			return 0;
      	}
    }
    yaz_log(LOG_LOG,"sending notice for notice_id %s",ids[cur_results-1]);
    r->len = strlen(http_content);
    r->record = http_content;
    r->output_format = VAL_UNIMARC;
    r->errcode = 0;
    return 0;
}
コード例 #27
0
ファイル: cclqfile.c プロジェクト: dcrossleyau/yaz
void ccl_qual_field(CCL_bibset bibset, const char *cp, const char *qual_name)
{
    const char *addinfo;
    ccl_qual_field2(bibset, cp, qual_name, &addinfo);
    if (addinfo)
        yaz_log(YLOG_WARN, "ccl_qual_field2 fail: %s", addinfo);
}
コード例 #28
0
ファイル: http.c プロジェクト: saiful76/pazpar2
void http_set_proxyaddr(const char *host, struct conf_server *server)
{
    const char *p;
    short port;
    struct hostent *he;
    WRBUF w = wrbuf_alloc();

    yaz_log(YLOG_LOG, "HTTP backend  %s", host);

    p = strchr(host, ':');
    if (p)
    {
        port = atoi(p + 1);
        wrbuf_write(w, host, p - host);
        wrbuf_puts(w, "");
    }
    else
    {
        port = 80;
        wrbuf_puts(w, host);
    }
    if (!(he = gethostbyname(wrbuf_cstr(w))))
    {
        fprintf(stderr, "Failed to lookup '%s'\n", wrbuf_cstr(w));
        exit(1);
    }
    wrbuf_destroy(w);

    server->http_server->proxy_addr = xmalloc(sizeof(struct sockaddr_in));
    server->http_server->proxy_addr->sin_family = he->h_addrtype;
    memcpy(&server->http_server->proxy_addr->sin_addr.s_addr,
           he->h_addr_list[0], he->h_length);
    server->http_server->proxy_addr->sin_port = htons(port);
}
コード例 #29
0
ファイル: http.c プロジェクト: saiful76/pazpar2
// Serialize a HTTP request
static struct http_buf *http_serialize_request(struct http_request *r)
{
    struct http_channel *c = r->channel;
    struct http_header *h;

    wrbuf_rewind(c->wrbuf);
    wrbuf_printf(c->wrbuf, "%s %s%s%s", r->method, r->path,
                 *r->search ? "?" : "", r->search);

    wrbuf_printf(c->wrbuf, " HTTP/%s\r\n", r->http_version);

    for (h = r->headers; h; h = h->next)
        wrbuf_printf(c->wrbuf, "%s: %s\r\n", h->name, h->value);

    wrbuf_puts(c->wrbuf, "\r\n");

    if (r->content_buf)
        wrbuf_write(c->wrbuf, r->content_buf, r->content_len);

#if 0
    yaz_log(YLOG_LOG, "WRITING TO PROXY:\n%s\n----",
            wrbuf_cstr(c->wrbuf));
#endif
    return http_buf_bywrbuf(c->http_server, c->wrbuf);
}
コード例 #30
0
ファイル: http_command.c プロジェクト: piskvorky/pazpar2
unsigned int make_sessionid(void)
{
    static int seq = 0; /* thread pr */
    unsigned int res;

    seq++;
    if (global_parameters.predictable_sessions)
        res = seq;
    else
    {
#ifdef WIN32
        res = seq;
#else
        struct timeval t;

        if (gettimeofday(&t, 0) < 0)
        {
            yaz_log(YLOG_WARN|YLOG_ERRNO, "gettimeofday");
            exit(1);
        }
        /* at most 256 sessions per second ..
           (long long would be more appropriate)*/
        res = t.tv_sec;
        res = ((res << 8) | (seq & 0xff)) & ((1U << 31) - 1);
#endif
    }
    return res;
}