Example #1
0
/**
 * Callback function to populate rows of the show variable
 * command
 *
 * @param data	The context point
 * @return	The next row or NULL if end of rows
 */
static RESULT_ROW *
variable_row(RESULTSET *result, void *data)
{
VARCONTEXT	*context = (VARCONTEXT *)data;
RESULT_ROW	*row;
char		buf[80];

	if (variables[context->index].name)
	{
		if (context->like &&
			 maxinfo_pattern_match(context->like,
					variables[context->index].name))
		{
			context->index++;
			return variable_row(result, data);
		}
		row = resultset_make_row(result);
		resultset_row_set(row, 0, variables[context->index].name);
		switch (variables[context->index].type)
		{
		case VT_STRING:
			resultset_row_set(row, 1,
				(char *)(*variables[context->index].func)());
			break;
		case VT_INT:
			snprintf(buf, 80, "%ld",
				(long)(*variables[context->index].func)());
			resultset_row_set(row, 1, buf);
			break;
		}
		context->index++;
		return row;
	}
	return NULL;
}
Example #2
0
/**
 * Provide a row to the result set that defines the set of services
 *
 * @param set	The result set
 * @param data	The index of the row to send
 * @return The next row or NULL
 */
static RESULT_ROW *
serviceRowCallback(RESULTSET *set, void *data)
{
int		*rowno = (int *)data;
int		i = 0;;
char		buf[20];
RESULT_ROW	*row;
SERVICE		*ptr;

	spinlock_acquire(&service_spin);
	ptr = allServices;
	while (i < *rowno && ptr)
	{
		i++;
		ptr = ptr->next;
	}
	if (ptr == NULL)
	{
		spinlock_release(&service_spin);
		free(data);
		return NULL;
	}
	(*rowno)++;
	row = resultset_make_row(set);
	resultset_row_set(row, 0, ptr->name);
	resultset_row_set(row, 1, ptr->routerModule);
	sprintf(buf, "%d", ptr->stats.n_current);
	resultset_row_set(row, 2, buf);
	sprintf(buf, "%d", ptr->stats.n_sessions);
	resultset_row_set(row, 3, buf);
	spinlock_release(&service_spin);
	return row;
}
Example #3
0
/**
 * Provide a row to the result set that defines the set of sessions
 *
 * @param set   The result set
 * @param data  The index of the row to send
 * @return The next row or NULL
 */
static RESULT_ROW *
sessionRowCallback(RESULTSET *set, void *data)
{
    SESSIONFILTER *cbdata = (SESSIONFILTER *)data;
    int i = 0;
    char buf[20];
    RESULT_ROW *row;
    SESSION *list_session;

    spinlock_acquire(&session_spin);
    list_session = allSessions;
    /* Skip to the first non-listener if not showing listeners */
    while (list_session && cbdata->filter == SESSION_LIST_CONNECTION &&
           list_session->state == SESSION_STATE_LISTENER)
    {
        list_session = list_session->next;
    }
    while (i < cbdata->index && list_session)
    {
        if (cbdata->filter == SESSION_LIST_CONNECTION &&
            list_session->state !=  SESSION_STATE_LISTENER)
        {
            i++;
        }
        else if (cbdata->filter == SESSION_LIST_ALL)
        {
            i++;
        }
        list_session = list_session->next;
    }
    /* Skip to the next non-listener if not showing listeners */
    while (list_session && cbdata->filter == SESSION_LIST_CONNECTION &&
           list_session->state == SESSION_STATE_LISTENER)
    {
        list_session = list_session->next;
    }
    if (list_session == NULL)
    {
        spinlock_release(&session_spin);
        free(data);
        return NULL;
    }
    cbdata->index++;
    row = resultset_make_row(set);
    snprintf(buf,19, "%p", list_session);
    buf[19] = '\0';
    resultset_row_set(row, 0, buf);
    resultset_row_set(row, 1, ((list_session->client_dcb && list_session->client_dcb->remote)
                               ? list_session->client_dcb->remote : ""));
    resultset_row_set(row, 2, (list_session->service && list_session->service->name
                               ? list_session->service->name : ""));
    resultset_row_set(row, 3, session_state(list_session->state));
    spinlock_release(&session_spin);
    return row;
}
Example #4
0
/**
 * Provide a row to the result set that defines the set of service
 * listeners
 *
 * @param set	The result set
 * @param data	The index of the row to send
 * @return The next row or NULL
 */
static RESULT_ROW *
serviceListenerRowCallback(RESULTSET *set, void *data)
{
int		*rowno = (int *)data;
int		i = 0;;
char		buf[20];
RESULT_ROW	*row;
SERVICE		*ptr;
SERV_PROTOCOL	*lptr = NULL;

	spinlock_acquire(&service_spin);
	ptr = allServices;
	if (ptr)
		lptr = ptr->ports;
	while (i < *rowno && ptr)
	{
		lptr = ptr->ports;
		while (i < *rowno && lptr)
		{
			if ((lptr = lptr->next) != NULL)
				i++;
		}
		if (i < *rowno)
		{
			ptr = ptr->next;
			if (ptr && (lptr = ptr->ports) != NULL)
				i++;
		}
	}
	if (lptr == NULL)
	{
		spinlock_release(&service_spin);
		free(data);
		return NULL;
	}
	(*rowno)++;
	row = resultset_make_row(set);
	resultset_row_set(row, 0, ptr->name);
	resultset_row_set(row, 1, lptr->protocol);
	resultset_row_set(row, 2, (lptr && lptr->address) ? lptr->address : "*");
	sprintf(buf, "%d", lptr->port);
	resultset_row_set(row, 3, buf);
	resultset_row_set(row, 4,
			(!lptr->listener || !lptr->listener->session ||
			lptr->listener->session->state == SESSION_STATE_LISTENER_STOPPED) ?
                                "Stopped" : "Running");
	spinlock_release(&service_spin);
	return row;
}
Example #5
0
/**
 * Provide a row to the result set that defines the set of servers
 *
 * @param set	The result set
 * @param data	The index of the row to send
 * @return The next row or NULL
 */
static RESULT_ROW *
serverRowCallback(RESULTSET *set, void *data)
{
int		*rowno = (int *)data;
int		i = 0;;
char		*stat, buf[20];
RESULT_ROW	*row;
SERVER		*ptr;

	spinlock_acquire(&server_spin);
	ptr = allServers;
	while (i < *rowno && ptr)
	{
		i++;
		ptr = ptr->next;
	}
	if (ptr == NULL)
	{
		spinlock_release(&server_spin);
		free(data);
		return NULL;
	}
	(*rowno)++;
	row = resultset_make_row(set);
	resultset_row_set(row, 0, ptr->unique_name);
	resultset_row_set(row, 1, ptr->name);
	sprintf(buf, "%d", ptr->port);
	resultset_row_set(row, 2, buf);
	sprintf(buf, "%d", ptr->stats.n_current);
	resultset_row_set(row, 3, buf);
	stat = server_status(ptr);
	resultset_row_set(row, 4, stat);
	free(stat);
	spinlock_release(&server_spin);
	return row;
}
Example #6
0
/**
 * Populate the version comment with the MaxScale version
 *
 * @param	result	The result set
 * @param	data	Pointer to int which is row count
 * @return	The populated row
 */
static RESULT_ROW *
version_comment(RESULTSET *result, void *data)
{
int		*context = (int *)data;
RESULT_ROW	*row;

	if (*context == 0)
	{
		(*context)++;
		row = resultset_make_row(result);
		resultset_row_set(row, 0, MAXSCALE_VERSION);
		return row;
	}
	return NULL;
}
Example #7
0
/**
 * Populate the version comment with the MaxScale version
 *
 * @param	result	The result set
 * @param	data	Pointer to int which is row count
 * @return	The populated row
 */
static RESULT_ROW *
starttime_row(RESULTSET *result, void *data)
{
int		*context = (int *)data;
RESULT_ROW	*row;
struct tm	tm;
static char	buf[40];

	if (*context == 0)
	{
		(*context)++;
		row = resultset_make_row(result);
		sprintf(buf, "%u", (unsigned int)maxscale_started());
		resultset_row_set(row, 0, buf);
		return row;
	}
	return NULL;
}