Exemplo n.º 1
0
static void
handle_request (CcnetPeer *peer, int req_id, char *data, int len)
{
    char *msg;
    gchar **commands;
    gchar **pcmd;
    int  i, perm;

    /* TODO: remove string copy */
    if (len < 1)
        return;
    msg = g_malloc (len+1);
    memcpy (msg, data, len);
    msg[len] = '\0';

    commands = g_strsplit_set (msg, " \t", 10);
    for (i=0, pcmd = commands; *pcmd; pcmd++)
        i++;
    if (i <= 0) return;
    g_free (msg);

    /* permission checking */
    if (!peer->is_local) {
        perm = ccnet_perm_manager_check_permission(peer->manager->session->perm_mgr,
                                                   peer, commands[0],
                                                   req_id,
                                                   i, commands);
        if (perm == PERM_CHECK_ERROR) {
            ccnet_peer_send_response (peer, req_id, SC_PERM_ERR, SS_PERM_ERR,
                                      NULL, 0);
            goto ret;
        } else if (perm == PERM_CHECK_DELAY) {
            ccnet_peer_send_response (peer, req_id, SC_PERM_ERR, SS_PERM_ERR,
                                      NULL, 0);
            goto ret;
        } else if (perm == PERM_CHECK_NOSERVICE) {
            ccnet_peer_send_response (peer, req_id, SC_UNKNOWN_SERVICE_IN_PERM,
                                      SS_UNKNOWN_SERVICE_IN_PERM, NULL, 0);
            goto ret;
        }
    }

    /* check duplication request */
    CcnetProcessor *processor;
    processor = ccnet_peer_get_processor (peer, SLAVE_ID(req_id));
    if (processor != NULL) {
        ccnet_warning ("Received duplication request, id is %d\n", req_id);
        goto ret;
    }

    create_processor (peer, req_id, i, commands);

ret:
    g_strfreev (commands);
}
Exemplo n.º 2
0
static void pm8x41_reg_write(uint32_t addr, uint8_t val)
{
	struct pmic_arb_cmd cmd;
	struct pmic_arb_param param;

	cmd.address  = PERIPH_ID(addr);
	cmd.offset   = REG_OFFSET(addr);
	cmd.slave_id = SLAVE_ID(addr);
	cmd.priority = 0;

	param.buffer = &val;
	param.size   = 1;

	pmic_arb_write_cmd(&cmd, &param);
}
Exemplo n.º 3
0
/* Local functions */
static uint8_t pm8x41_reg_read(uint32_t addr)
{
	uint8_t val = 0;
	struct pmic_arb_cmd cmd;
	struct pmic_arb_param param;

	cmd.address  = PERIPH_ID(addr);
	cmd.offset   = REG_OFFSET(addr);
	cmd.slave_id = SLAVE_ID(addr);
	cmd.priority = 0;

	param.buffer = &val;
	param.size   = 1;

	pmic_arb_read_cmd(&cmd, &param);

	return val;
}
Exemplo n.º 4
0
static void
handle_update (CcnetPeer *peer, int req_id, char *data, int len)
{
    CcnetProcessor *processor;
    char *code, *code_msg = 0, *content = 0;
    int clen;
    char *ptr, *end;

    if (len < 4)
        goto error;
    
    code = data;
    
    ptr = data + 3;
    if (*ptr == '\n') {
        /* no code_msg */
        *ptr++ = '\0';
        content = ptr;
        clen = len - (ptr - data);
        goto parsed;
    }
    
    if (*ptr != ' ')
        goto error;
    
    *ptr++ = '\0';
    code_msg = ptr;

    end = data + len;
    for (ptr = data; *ptr != '\n' && ptr != end; ptr++) ;

    if (ptr == end)             /* must end with '\n' */
        goto error;

    /* if (*(ptr-1) == '\r') */
    /*     *(ptr-1) = '\0'; */
    *ptr++ = '\0';
    content = ptr;
    clen = len - (ptr - data);
    
parsed:
    processor = ccnet_peer_get_processor (peer, SLAVE_ID(req_id));
    if (processor == NULL) {
        if (memcmp(code, SC_PROC_DEAD, 3) != 0 
            && memcmp(code, SC_PROC_DONE, 3) != 0) {
            ccnet_debug ("Delayed update from %s(%.8s), id is %d, %s %s\n",
                         peer->name, peer->id, req_id, code, code_msg);
            ccnet_peer_send_response (peer, req_id,
                                      SC_PROC_DEAD, SS_PROC_DEAD,
                                      NULL, 0);
        }
        return;
    }

    /* if (!peer->is_local) */
    /*     ccnet_debug ("[RECV] handle_update %s id is %d, %s %s\n", */
    /*                  GET_PNAME(processor), PRINT_ID(processor->id), */
    /*                  code, code_msg); */
    peer->in_processor_call = 1;
    ccnet_processor_handle_update (processor, code, code_msg, content, clen);
    peer->in_processor_call = 0;
    return;

error:
    ccnet_warning ("Bad update format from %s\n", peer->id);
}