Example #1
0
static void cmd_search(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 *query = http_argbyname(rq, "query");
    const char *filter = http_argbyname(rq, "filter");
    const char *maxrecs = http_argbyname(rq, "maxrecs");
    const char *startrecs = http_argbyname(rq, "startrecs");
    const char *limit = http_argbyname(rq, "limit");
    const char *sort = http_argbyname(rq, "sort");
    enum pazpar2_error_code code;
    const char *addinfo = 0;
    struct reclist_sortparms *sp;
    struct conf_service *service = 0;

    if (!s)
        return;

    if (!query)
    {
        error(rs, PAZPAR2_MISSING_PARAMETER, "query");
        release_session(c, s);
        return;
    }
    if (!yaz_utf8_check(query))
    {
        error(rs, PAZPAR2_MALFORMED_PARAMETER_ENCODING, "query");
        release_session(c, s);
        return;
    }
    service = s->psession->service;
    if (!sort) {
        sort = service->default_sort;
    }
    if (!(sp = reclist_parse_sortparms(c->nmem, sort, s->psession->service)))
    {
        error(c->response, PAZPAR2_MALFORMED_PARAMETER_VALUE, "sort");
        release_session(c, s);
        return;
    }

    code = session_search(s->psession, query, startrecs, maxrecs, filter, limit,
                          &addinfo, sp);
    if (code)
    {
        error(rs, code, addinfo);
        release_session(c, s);
        return;
    }
    response_open(c, "search");
    response_close(c, "search");
    release_session(c, s);
}
Example #2
0
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);
}
Example #3
0
int main( int argc, char **argv )
{
	void *pTaskHandle = NULL;
	
	enable_log( 1 );
	set_log( LOG_TYPE_CONSOLE, NULL, 0 );

	if( init_session(  ) < 0 )
		return -1;
		
	pTaskHandle = create_task( task_test, 5, 100 );
	if ( pTaskHandle )
	{
		CMessage stMsg;
		
		memset( &stMsg, 0x00, sizeof(stMsg) );
		
		post_task_msg( pTaskHandle, &stMsg );
		
		log_print( "create task ok................." );
	}
	else 
		log_print( "create task failed?????????????????????" );
	
	while ( 1 )
		os_sleep( 1000 );
		
	release_session(  );
	
	return 0;	
}
Example #4
0
static void cmd_stat(struct http_channel *c)
{
    struct http_session *s = locate_session(c);
    struct statistics stat;
    int clients;

    float progress = 0;

    if (!s)
        return;

    clients = session_active_clients(s->psession);
    statistics(s->psession, &stat);

    if (stat.num_clients > 0)
    {
        progress = (stat.num_clients  - clients) / (float)stat.num_clients;
    }

    response_open_no_status(c, "stat");
    wrbuf_printf(c->wrbuf, "\n <activeclients>%d</activeclients>\n", clients);
    wrbuf_printf(c->wrbuf, " <hits>" ODR_INT_PRINTF "</hits>\n", stat.num_hits);
    wrbuf_printf(c->wrbuf, " <records>%d</records>\n", stat.num_records);
    wrbuf_printf(c->wrbuf, " <clients>%d</clients>\n", stat.num_clients);
    wrbuf_printf(c->wrbuf, " <unconnected>%d</unconnected>\n", stat.num_no_connection);
    wrbuf_printf(c->wrbuf, " <connecting>%d</connecting>\n", stat.num_connecting);
    wrbuf_printf(c->wrbuf, " <working>%d</working>\n", stat.num_working);
    wrbuf_printf(c->wrbuf, " <idle>%d</idle>\n", stat.num_idle);
    wrbuf_printf(c->wrbuf, " <failed>%d</failed>\n", stat.num_failed);
    wrbuf_printf(c->wrbuf, " <error>%d</error>\n", stat.num_error);
    wrbuf_printf(c->wrbuf, " <progress>%.2f</progress>\n", progress);
    response_close(c, "stat");
    release_session(c, s);
}
Example #5
0
static DBusMessage *remove_session(DBusConnection *connection,
				DBusMessage *message, void *user_data)
{
	struct obc_session *session;
	const char *sender, *path;

	if (dbus_message_get_args(message, NULL,
			DBUS_TYPE_OBJECT_PATH, &path,
			DBUS_TYPE_INVALID) == FALSE)
		return g_dbus_create_error(message,
				ERROR_INTERFACE ".InvalidArguments", NULL);

	session = find_session(path);
	if (session == NULL)
		return g_dbus_create_error(message,
				ERROR_INTERFACE ".InvalidArguments", NULL);

	sender = dbus_message_get_sender(message);
	if (g_str_equal(sender, obc_session_get_owner(session)) == FALSE)
		return g_dbus_create_error(message,
				ERROR_INTERFACE ".NotAuthorized",
				"Not Authorized");

	release_session(session);

	return dbus_message_new_method_return(message);
}
Example #6
0
static void cmd_record(struct http_channel *c)
{
    struct http_session *s = locate_session(c);
    if (s) {
        show_record(c, s);
        release_session(c,s);
    }
}
Example #7
0
static void cmd_ping(struct http_channel *c)
{
    struct http_session *s = locate_session(c);
    if (!s)
        return;
    response_open(c, "ping");
    response_close(c, "ping");
    release_session(c, s);
}
Example #8
0
static void cmd_record_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: record watch released", s->session_id);
        show_record(c, s);
        release_session(c,s);
    }
}
Example #9
0
static void cmd_session_status(struct http_channel *c)
{
    struct http_session *s = locate_session(c);
    if (!s)
        return;

    response_open(c, "session-status");
    session_status(c, s);
    response_close(c, "session-status");
    release_session(c, s);
}
Example #10
0
static void cmd_settings(struct http_channel *c)
{
    struct http_response *rs = c->response;
    struct http_request *rq = c->request;
    struct http_session *s = locate_session(c);
    const char *content_type = http_lookup_header(rq->headers, "Content-Type");

    if (!s)
        return;

    if (rq->content_len && content_type &&
            !yaz_strcmp_del("text/xml", content_type, "; "))
    {
        xmlDoc *doc = xmlParseMemory(rq->content_buf, rq->content_len);
        xmlNode *root_n;
        int ret;
        if (!doc)
        {
            error(rs, PAZPAR2_MALFORMED_SETTING, 0);
            release_session(c,s);
            return;
        }
        root_n = xmlDocGetRootElement(doc);
        ret = settings_read_node_x(root_n, s->psession, apply_local_setting);
        xmlFreeDoc(doc);
        if (ret)
        {
            error(rs, PAZPAR2_MALFORMED_SETTING, 0);
            release_session(c,s);
            return;
        }
    }
    if (process_settings(s->psession, rq, rs) < 0)
    {
        release_session(c, s);
        return;
    }
    response_open(c, "settings");
    response_close(c, "settings");
    release_session(c, s);
}
Example #11
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);
}
Example #12
0
/**
 * Type of a function to call when we receive a session release
 * message from the service.
 *
 * @param cls the `struct GNUNET_ATS_SchedulingHandle`
 * @param msg message received, NULL on timeout or fatal error
 */
static void
process_ats_session_release_message (void *cls,
                                     const struct GNUNET_MessageHeader *msg)
{
  struct GNUNET_ATS_SchedulingHandle *sh = cls;
  const struct GNUNET_ATS_SessionReleaseMessage *srm;

  srm = (const struct GNUNET_ATS_SessionReleaseMessage *) msg;
  /* Note: peer field in srm not necessary right now,
     but might be good to have in the future */
  release_session (sh,
                   ntohl (srm->session_id));
}
Example #13
0
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");
    }
}
Example #14
0
static void termlist_result_ready(void *data)
{
    struct http_channel *c = (struct http_channel *) data;
    struct http_request *rq = c->request;
    const char *report = http_argbyname(rq, "report");
    const char *status = 0;
    struct http_session *s = locate_session(c);
    if (report && !strcmp("status", report))
        status = "OK";
    if (s) {
        yaz_log(c->http_sessions->log_level, "Session %u termlist watch released", s->session_id);
        termlist_response(c, s, status);
        release_session(c,s);
    }
}
Example #15
0
int main( int argc, char **argv )
{
	CSession *pSession = NULL;
	CSessionParam stSessionParam;
	const int8_t *pPeerIP = "www.lelsen.sinaapp.com";
	//const int8_t *pPeerIP = "www.baidu.com";
	const int8_t *pURL = "/business/api/punch.php";
	//const int8_t *pURL = "/index.html";
	const int16u_t iPeerPort = 80;
	
	enable_log( 1 );
	set_log( LOG_TYPE_CONSOLE, NULL, 0 );
	
	pHandle = fopen( "./log.txt", "wb" );
	if ( !pHandle )
		return -1;
	
	if ( init_session(  ) < 0 )
		return -1;
	
	log_print( "init_session ok.................." );
		
	memset( &stSessionParam, 0x00, sizeof(stSessionParam) );
	memcpy( stSessionParam.pIP, pPeerIP, strlen(pPeerIP) + 1 );
	stSessionParam.iPort = iPeerPort;
	
	log_print( "start to create session............" );
	pSession = create_session( SESSION_TYPE_HTTP_CLIENT, &stSessionParam );
	
	if ( pSession )
	{
		log_print( "create tcp session ok................" );
		if ( set_session_business( pSession, stream_session_business, NULL ) >= 0 )
		{
			if ( set_session_event( pSession, stream_session_event ) >= 0 )
			{
				CHttpData stHttpData;
				
				memset( &stHttpData, 0x00, sizeof(stHttpData) );
				stHttpData.pHost = pPeerIP;
				stHttpData.pURL = pURL;
				stHttpData.eHttpAction = SESSION_HTTP_GET;

				while ( 1 )
				{
					int i, iNSent = -1;
					
					//printf( "Please enter 1 to send http request:\r\n" );
					i = 0;
				//	scanf( "%d", &i );
					//if ( i == 1 )
						iNSent = send_session_data( pSession, &stHttpData, sizeof(stHttpData), NULL );
						
					os_sleep( 1000 * 2);
				}
			}
		}
	}
	else 
		log_print( "create udp session failed????????????????????????" );
		
	while ( 1 )
		os_sleep( 1000 );
		
	destroy_session( pSession );
	pSession = NULL;
		
	release_session(  );	
	
	return 0;	
}
Example #16
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);
}