Exemple #1
0
/*
void response_client_open_ex(response_client_t *uclient, char *conn_str, char *(*id_f)(), char *(*pph_f)()) {
    uclient->id_f = id_f;
    uclient->passphrase_f = pph_f;
    response_client_open_int(uclient, conn_str);
}
*/
int response_client_send(response_client_t *uclient, response_request_t *request) {
    int ret;
    long nbytes;
    char buff[UCLIENT_BUFSIZE];
#if defined(USERVER_ENCRYPTED)
    char cipher[UCLIENT_BUFSIZE];
    char message[UCLIENT_BUFSIZE];
    uint32_t timestamp;
    char sts[32];
    char *passphrase = uclient->passphrase_f();
    char otp[100];
    char *id = uclient->id_f();
    char challenge[32];
    int len = 32;
    int len1 = 32;
    
    lvc_t lvc;
    
    timestamp = get_ts();
    len1 = ts2str(timestamp, sts);
    
    generate_otp(otp, passphrase, sts);

    do_encrypt(challenge, &len, sts, len1, otp);

    lvc_init(&lvc, message, UCLIENT_BUFSIZE);

    fprintf(stdout, "lvc_pack id:%s\n", id);
    lvc_pack( &lvc, strlen(id), id );
    fprintf(stdout, "lvc_pack ts:%u\n", timestamp);
    lvc_pack( &lvc, sizeof(uint32_t), (char *)&timestamp );
    fprintf(stdout, "lvc_pack challenge:%d\n", len);
    lvc_pack( &lvc, len, challenge );
#endif
    response_build_request(buff, sizeof(buff), request);
    nbytes = strlen(buff);

#if defined(USERVER_ENCRYPTED)
    fprintf(stdout, "Message to send:%.*s\n", nbytes, buff);
    
    len = sizeof(cipher);
    do_encrypt(cipher, &len, buff, nbytes, otp);

    lvc_pack( &lvc, len, cipher );
    lvc_pack_finish(&lvc);
    
    nbytes = lvc.len;

    ret = pj_sock_sendto(uclient->fd, lvc.data, &nbytes, 0, (const pj_sockaddr_t *)uclient->connect_data, sizeof(pj_sockaddr_in));
#else
    ret = pj_sock_sendto(uclient->fd, buff, &nbytes, 0, (const pj_sockaddr_t *)uclient->connect_data, sizeof(pj_sockaddr_in));
#endif

    if(ret != 0) {
        PERROR_IF_TRUE(1, "Error in sending data\n");
        return -1;
    }

    return nbytes;
}
Exemple #2
0
void node_invite(node_t *node, char *guest) {
    gm_request_t req;
    if( node_is_online(node) ) {
        req.msg_id = GM_GROUP;
        req.gm_group.join = 1;
        ansi_copy_str(req.gm_group.owner, node->id);
        ansi_copy_str(req.gm_group.guest, guest);
        PERROR_IF_TRUE(gm_client_send(&node->gm_client, &req) < 0, "ERROR::node_invite: ");
    }
}
Exemple #3
0
static int udp_sendto(int fd, char *buff, int len, void *data, unsigned int data_len) {
    int ret = 0;
    long nbytes = len;
    ret = pj_sock_sendto(fd, buff, &nbytes, 0, (pj_sockaddr_t *)data, data_len);
    if( ret != 0 ) {
        PERROR_IF_TRUE(1, "Error in sending data\n");
        return -1;
    }
    return nbytes;
}
Exemple #4
0
static int udp_recvfrom(int fd, char *buff, int len, void *data, unsigned int *data_len) {
    int ret;
    long nbytes = len;
    ret = pj_sock_recvfrom(fd, buff, &nbytes, 0, (pj_sockaddr_t *)data, (int *)data_len);
    if( ret != 0 ) {
        PERROR_IF_TRUE(1, "Error receiving data\n");
        return -1;
    }
    return nbytes;
}
Exemple #5
0
void $UPROTO$_server_leave($UPROTO$_server_t *userver, char *multicast_ip) {
    pj_ip_mreq mreq;
    pj_str_t s;
    pj_status_t ret;
    mreq.imr_multiaddr = pj_inet_addr(pj_cstr(&s, multicast_ip));
    mreq.imr_interface.s_addr = pj_htonl(PJ_INADDR_ANY);

    pj_mutex_lock(userver->mutex);
    ret = pj_sock_setsockopt(userver->fd, PJ_SOL_IP, PJ_IP_DROP_MEMBERSHIP, &mreq,sizeof(mreq));
    PERROR_IF_TRUE(ret != 0, "Error in leaving mcast group");
    pj_mutex_unlock(userver->mutex);
}
Exemple #6
0
void $UPROTO$_server_join($UPROTO$_server_t *userver, char *multicast_ip) {
    pj_ip_mreq mreq;
    pj_str_t s, s1;
    pj_status_t ret;

    pj_bzero(&mreq, sizeof(pj_ip_mreq));
	mreq.imr_multiaddr = pj_inet_addr(pj_cstr(&s, multicast_ip));
	mreq.imr_interface = pj_inet_addr(pj_cstr(&s1, "0.0.0.0"));

    //mreq.imr_multiaddr.s_addr = inet_addr(multicast_ip);
    //mreq.imr_interface.s_addr = htonl(INADDR_ANY);

    pj_mutex_lock(userver->mutex);
    ret = pj_sock_setsockopt(userver->fd, PJ_SOL_IP, PJ_IP_ADD_MEMBERSHIP, &mreq,sizeof(mreq));
    PERROR_IF_TRUE(ret != 0, "Error in joining mcast group");
    pj_mutex_unlock(userver->mutex);
}
Exemple #7
0
void node_register(node_t *node) {
    if( !node_is_online(node) ) {
        SHOW_LOG(5, fprintf(stdout, "Registration is failed: Node is not online\n"));
        return;
    }
    gm_request_t req;
    
    //Set request value
    req.msg_id = GM_REG;
    memset(req.gm_reg.reg_id, 0, sizeof(req.gm_reg.reg_id));
    strncpy(req.gm_reg.reg_id, node->id, strlen(node->id));
    memset(req.gm_reg.gmc_cs, 0, sizeof(req.gm_reg.gmc_cs));
    strncpy(req.gm_reg.gmc_cs, node->gmc_cs, strlen(node->gmc_cs));
    memset(req.gm_reg.location, 0, sizeof(req.gm_reg.location));
    strncpy(req.gm_reg.location, node->location, strlen(node->location));
    memset(req.gm_reg.desc, 0, sizeof(req.gm_reg.desc));
    strncpy(req.gm_reg.desc, node->desc, strlen(node->desc));

    req.gm_reg.radio_port = node->radio_port;    

    //Send MG_REQ
    PERROR_IF_TRUE(gm_client_send(&node->gm_client, &req) < 0, "ERROR:: registered failed - ");
}