Example #1
0
static void show_records_ready(void *data)
{
    struct http_channel *c = (struct http_channel *) data;
    struct http_session *s = locate_session(c);
    if (s) {
        yaz_log(c->http_sessions->log_level, "Session %u: show watch released", s->session_id);
        show_records(c, s, -1);
    }
    else {
        /* some error message  */
    }
    release_session(c,s);
}
/*
 * Searches for a inventory item based on that item's name. The search is
 * performed using the item name secondary database. Displays all
 * inventory items that use the specified name, as well as the vendor
 * associated with that inventory item.
 *
 * If no item name is provided, then all inventory items are displayed.
 */
int
main(int argc, char *argv[])
{
    STOCK_DBS my_stock;
    int ch, ret;
    char *itemname;

    /* Initialize the STOCK_DBS struct */
    initialize_stockdbs(&my_stock);

    /* Parse the command line arguments */
    itemname = NULL;
    while ((ch = getopt(argc, argv, "h:i:?")) != EOF)
	switch (ch) {
	case 'h':
	    if (optarg[strlen(optarg)-1] != '/' &&
		optarg[strlen(optarg)-1] != '\\')
		return (usage());
	    my_stock.db_home_dir = optarg;
	    break;
	case 'i':
	    itemname = optarg;
	    break;
	case '?':
	default:
	    return (usage());
	}

    /* Identify the files that hold our databases */
    set_db_filenames(&my_stock);

    /* Open all databases */
    ret = databases_setup(&my_stock, "example_database_read", stderr);
    if (ret != 0) {
	fprintf(stderr, "Error opening databases\n");
	databases_close(&my_stock);
	return (ret);
    }

    if (itemname == NULL)
	ret = show_all_records(&my_stock);
    else
	ret = show_records(&my_stock, itemname);

    /* close our databases */
    databases_close(&my_stock);
    return (ret);
}
Example #3
0
static void cmd_show(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 *sort = http_argbyname(rq, "sort");
    const char *block_error = http_argbyname(rq, "report");
    struct conf_service *service = 0;

    struct reclist_sortparms *sp;
    int status;
    int report_error = 0;
    if (block_error && !strcmp("1", block_error)) {
        report_error = 1;
    }
    if (!s)
        return;

    service = s->psession->service;
    if (!sort) {
        sort = service->default_sort;
    }

    if (!(sp = reclist_parse_sortparms(c->nmem, sort, service)))
    {
        error(c->response, PAZPAR2_MALFORMED_PARAMETER_VALUE, "sort");
        release_session(c, s);
        return;
    }
    session_sort(s->psession, sp);

    status = session_active_clients(s->psession);

    if (block)
    {
        if (!strcmp(block, "preferred") && !session_is_preferred_clients_ready(s->psession) && reclist_get_num_records(s->psession->reclist) == 0)
        {
            // if there is already a watch/block. we do not block this one
            if (session_set_watch(s->psession, SESSION_WATCH_SHOW_PREF,
                                  show_records_ready, c, c) == 0)
            {
                yaz_log(c->http_sessions->log_level,
                        "Session %u: Blocking on command show (preferred targets)", s->session_id);
                release_session(c, s);
                return;
            }
            else
            {
                yaz_log(YLOG_WARN, "Session %u: Attempt to block multiple times on show (preferred targets) block. Not supported!",
                        s->session_id);
                if (report_error) {
                    error(rs, PAZPAR2_ALREADY_BLOCKED, "show (preferred targets)");
                    release_session(c, s);
                    return;
                }
                else {
                    yaz_log(YLOG_WARN, "Session %u: Ignoring show(preferred) block. Returning current result.", s->session_id);
                }
            }

        }
        else if (status)
        {
            // if there is already a watch/block. we do not block this one
            if (session_set_watch(s->psession, SESSION_WATCH_SHOW,
                                  show_records_ready, c, c) != 0)
            {
                yaz_log(YLOG_WARN, "Session %u: Attempt to block multiple times on show block. Not supported!", s->session_id);
                if (report_error) {
                    error(rs, PAZPAR2_ALREADY_BLOCKED, "show");
                    release_session(c, s);
                    return;
                }
                else {
                    yaz_log(YLOG_WARN, "Session %u: Ignoring show block. Returning current result.", s->session_id);
                }
            }
            else
            {
                yaz_log(c->http_sessions->log_level, "Session %u: Blocking on command show", s->session_id);
                release_session(c, s);
                return;
            }
        }
    }
    show_records(c, s, status);
    release_session(c, s);
}