コード例 #1
0
ファイル: lwsd_conf.c プロジェクト: Qiware/tanlz
/******************************************************************************
 **函数名称: lwsd_conf_load_comm
 **功    能: 加载公共配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_load_comm(xml_tree_t *xml, lwsd_conf_t *conf, log_cycle_t *log)
{
    xml_node_t *node, *fix;

    /* > 加载结点ID */
    node = xml_query(xml, ".LISTEND.ID");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Get node id failed!");
        return -1;
    }

    conf->nid = str_to_num(node->value.str);

    /* > 加载工作路径 */
    node = xml_query(xml, ".LISTEND.WORKDIR");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Get work directory failed!");
        return -1;
    }

    snprintf(conf->wdir, sizeof(conf->wdir), "%s/%d", node->value.str, conf->nid);  /* 工作路径 */

    /* > 分发队列配置 */
    fix = xml_query(xml, ".LISTEND.DISTQ");
    if (NULL == fix) {
        log_error(log, "Get distribute queue failed!");
        return -1;
    }

    node = xml_search(xml, fix, "NUM");
    if (NULL == node) {
        log_error(log, "Get number of distribue queue failed!");
        return -1;
    }

    conf->distq.num = str_to_num(node->value.str);

    node = xml_search(xml, fix, "MAX");
    if (NULL == node) {
        log_error(log, "Get the max container of distribue queue failed!");
        return -1;
    }

    conf->distq.max = str_to_num(node->value.str);

    node = xml_search(xml, fix, "SIZE");
    if (NULL == node) {
        log_error(log, "Get the size of distribue queue failed!");
        return -1;
    }

    conf->distq.size = str_to_num(node->value.str);

    return 0;
}
コード例 #2
0
ファイル: client.c プロジェクト: JerJohn15/moonlight-embedded
int gs_quit_app(PSERVER_DATA server) {
  int ret = GS_OK;
  char url[4096];
  uuid_t uuid;
  char uuid_str[37];
  char* result = NULL;
  PHTTP_DATA data = http_create_data();
  if (data == NULL)
    return GS_OUT_OF_MEMORY;

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "https://%s:47984/cancel?uniqueid=%s&uuid=%s", server->address, unique_id, uuid_str);
  if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  if ((ret = xml_search(data->memory, data->size, "cancel", &result)) != GS_OK)
    goto cleanup;

  if (strcmp(result, "0") == 0) {
    ret = GS_FAILED;
    goto cleanup;
  }

  cleanup:
  if (result != NULL)
    free(result);

  http_free_data(data);
  return ret;
}
コード例 #3
0
ファイル: client.c プロジェクト: JerJohn15/moonlight-embedded
int gs_start_app(PSERVER_DATA server, STREAM_CONFIGURATION *config, int appId, bool sops, bool localaudio) {
  int ret = GS_OK;
  uuid_t uuid;
  char* result = NULL;
  char uuid_str[37];

  if (config->height >= 2160 && !server->supports4K)
    return GS_NOT_SUPPORTED_4K;

  RAND_bytes(config->remoteInputAesKey, 16);
  memset(config->remoteInputAesIv, 0, 16);

  srand(time(NULL));
  char url[4096];
  u_int32_t rikeyid = 0;
  char rikey_hex[33];
  bytes_to_hex(config->remoteInputAesKey, rikey_hex, 16);

  PHTTP_DATA data = http_create_data();
  if (data == NULL)
    return GS_OUT_OF_MEMORY;

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  if (server->currentGame == 0) {
    int channelCounnt = config->audioConfiguration == AUDIO_CONFIGURATION_STEREO ? CHANNEL_COUNT_STEREO : CHANNEL_COUNT_51_SURROUND;
    int mask = config->audioConfiguration == AUDIO_CONFIGURATION_STEREO ? CHANNEL_MASK_STEREO : CHANNEL_MASK_51_SURROUND;
    sprintf(url, "https://%s:47984/launch?uniqueid=%s&uuid=%s&appid=%d&mode=%dx%dx%d&additionalStates=1&sops=%d&rikey=%s&rikeyid=%d&localAudioPlayMode=%d&surroundAudioInfo=%d", server->address, unique_id, uuid_str, appId, config->width, config->height, config->fps, sops, rikey_hex, rikeyid, localaudio, (mask << 16) + channelCounnt);
  } else
    sprintf(url, "https://%s:47984/resume?uniqueid=%s&uuid=%s&rikey=%s&rikeyid=%d", server->address, unique_id, uuid_str, rikey_hex, rikeyid);

  if ((ret = http_request(url, data)) == GS_OK)
    server->currentGame = appId;
  else
    goto cleanup;

  if ((ret = xml_search(data->memory, data->size, "gamesession", &result)) != GS_OK)
    goto cleanup;

  if (!strcmp(result, "0")) {
    ret = GS_FAILED;
    goto cleanup;
  }

  cleanup:
  if (result != NULL)
    free(result);

  http_free_data(data);
  return ret;
}
コード例 #4
0
ファイル: lwsd_conf.c プロジェクト: Qiware/tanlz
/******************************************************************************
 **函数名称: lwsd_conf_parse_lws_connections
 **功    能: 解析LWS并发配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_parse_lws_connections(xml_tree_t *xml, lws_conf_t *conf, log_cycle_t *log)
{
    xml_node_t *fix, *node;

    /* > 定位并发配置 */
    fix = xml_query(xml, ".LISTEND.LWS.CONNECTIONS");
    if (NULL == fix) {
        log_error(log, "Didn't configure connections!");
        return -1;
    }

    node = xml_search(xml, fix, "MAX");         /* > 获取最大并发数 */
    if (NULL == node) {
        log_error(log, "Get max number of connections failed!");
        return -1;
    }

    conf->connections.max = str_to_num(node->value.str);

    node = xml_search(xml, fix, "TIMEOUT");     /* > 获取连接超时时间 */
    if (NULL == node) {
        log_error(log, "Get timeout of connection failed!");
        return -1;
    }

    conf->connections.timeout = str_to_num(node->value.str);

    /* > 获取侦听端口 */
    node = xml_search(xml, fix, "PORT");
    if (NULL == node) {
        log_error(log, "Get port of connection failed!");
        return -1;
    }

    conf->connections.port = str_to_num(node->value.str);

    return 0;
}
コード例 #5
0
ファイル: lwsd_conf.c プロジェクト: Qiware/tanlz
/******************************************************************************
 **函数名称: lwsd_conf_load_lws
 **功    能: 加载LWS配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     lcf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_load_lws(xml_tree_t *xml, lwsd_conf_t *lcf, log_cycle_t *log)
{
    xml_node_t *node, *lws;
    lws_conf_t *conf = &lcf->lws;

    /* > 定位队列标签 */
    lws = xml_query(xml, ".LISTEND.LWS");
    if (NULL == lws) {
        log_error(log, "Query lws configuration failed!");
        return -1;
    }

    /* > 获取IFACE */
    node = xml_search(xml, lws, "IFACE");
    if (NULL == node
        || 0 == node->value.len)
    {
        snprintf(conf->iface, sizeof(conf->iface), ".");
    }
    else {
        snprintf(conf->iface, sizeof(conf->iface), "%s", node->value.str);
    }

    /* > 加载连接配置 */
    if (lwsd_conf_parse_lws_connections(xml, conf, log)) {
        log_error(log, "Parse connections of lws configuration failed!");
        return -1;
    }

    /* > 加载队列配置 */
    if (lwsd_conf_parse_lws_queue(xml, conf, log)) {
        log_error(log, "Parse queue of lws configuration failed!");
        return -1;
    }

    /* > 加载路径配置 */
    if (lwsd_conf_parse_lws_path(xml, conf, log)) {
        log_error(log, "Parse path of lws configuration failed!");
        return -1;
    }

    return 0;
}
コード例 #6
0
ファイル: mon_conf.c プロジェクト: jinrenlab/tanlz
/******************************************************************************
 **函数名称: mon_conf_load
 **功    能: 加载配置信息
 **输入参数:
 **     path: 配置路径
 **输出参数: NONE
 **返    回: 0:成功 !0:失败
 **实现描述: 
 **注意事项: 
 **作    者: # Qifeng.zou # 2015.04.11 #
 ******************************************************************************/
static int mon_conf_load_menu(xml_tree_t *xml, mon_conf_t *conf)
{
    xml_node_t *node, *nail;

    nail = xml_query(xml, ".MONITOR.MENU");
    if (NULL == nail) {
        return -1;
    }

    node = xml_search(xml, nail, ".WIDTH");
    if (NULL == node) {
        conf->menu.width = MON_MENU_WIDTH;
    }
    else
    {
        conf->menu.width = atoi(node->value.str);
    }

    return 0;
}
コード例 #7
0
ファイル: lwsd_conf.c プロジェクト: Qiware/tanlz
/******************************************************************************
 **函数名称: lwsd_conf_parse_lws_path
 **功    能: 加载路径配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_parse_lws_path(xml_tree_t *xml, lws_conf_t *conf, log_cycle_t *log)
{
    xml_node_t *node, *lws;

    /* > 定位队列标签 */
    lws = xml_query(xml, ".LISTEND.LWS");
    if (NULL == lws) {
        log_error(log, "Get queue configuration failed!");
        return -1;
    }

    /* > 获取RESOURCE-PATH */
    node = xml_search(xml, lws, "RESOURCE_PATH");
    if (NULL == node
        || 0 == node->value.len)
    {
        snprintf(conf->resource_path, sizeof(conf->resource_path), ".");
    }
    else {
        snprintf(conf->resource_path, sizeof(conf->resource_path), "%s", node->value.str);
    }

    /* > 获取SSL配置 */
    node = xml_search(xml, lws, "SSL.USE");
    if (NULL == node
        || 0 == node->value.len)
    {
        conf->is_use_ssl = false;
    }
    else {
        if (!strcasecmp(node->value.str, "on")) {
            conf->is_use_ssl = true;
        }
        else {
            conf->is_use_ssl = false;
        }
    }

    if (conf->is_use_ssl) {
        /* > 获取KEY-PATH */
        node = xml_search(xml, lws, "KEY_PATH");
        if (NULL == node
            || 0 == node->value.len)
        {
            snprintf(conf->key_path, sizeof(conf->key_path), "%s", conf->resource_path);
        }
        else {
            snprintf(conf->key_path, sizeof(conf->key_path), "%s/%s",
                    conf->resource_path, node->value.str);
        }

        /* > 获取CERT-PATH */
        node = xml_search(xml, lws, "CERT_PATH");
        if (NULL == node
            || 0 == node->value.len)
        {
            snprintf(conf->cert_path, sizeof(conf->cert_path), "%s", conf->resource_path);
        }
        else {
            snprintf(conf->cert_path, sizeof(conf->cert_path), "%s/%s",
                    conf->resource_path, node->value.str);
        }
    }

    return 0;
}
コード例 #8
0
ファイル: pairing.c プロジェクト: wk1990ok/moonlight-chrome
int gs_pair(const char* address, const char* pin) {
    int ret = GS_OK;
    char url[4096];
    
    unsigned char salt_data[16];
    char salt_hex[33];
    RAND_bytes(salt_data, 16);
    bytes_to_hex(salt_data, salt_hex, 16);
    
    sprintf(url, "http://%s:47989/pair?uniqueid=%s&devicename=roth&updateState=1&phrase=getservercert&salt=%s&clientcert=%s", address, g_UniqueId, salt_hex, g_CertHex);
    PHTTP_DATA data = http_create_data();
    if (data == NULL)
        return GS_OUT_OF_MEMORY;
    else if ((ret = http_request(url, data)) != GS_OK)
        goto cleanup;
    
    unsigned char salt_pin[20];
    unsigned char aes_key_hash[20];
    AES_KEY enc_key, dec_key;
    memcpy(salt_pin, salt_data, 16);
    memcpy(salt_pin+16, pin, 4);
    SHA1(salt_pin, 20, aes_key_hash);
    AES_set_encrypt_key((unsigned char *)aes_key_hash, 128, &enc_key);
    AES_set_decrypt_key((unsigned char *)aes_key_hash, 128, &dec_key);
    
    unsigned char challenge_data[16];
    unsigned char challenge_enc[16];
    char challenge_hex[33];
    RAND_bytes(challenge_data, 16);
    AES_encrypt(challenge_data, challenge_enc, &enc_key);
    bytes_to_hex(challenge_enc, challenge_hex, 16);
    
    sprintf(url, "http://%s:47989/pair?uniqueid=%s&devicename=roth&updateState=1&clientchallenge=%s", address, g_UniqueId, challenge_hex);
    if ((ret = http_request(url, data)) != GS_OK)
        goto cleanup;
    
    char *result;
    if (xml_search(data->memory, data->size, "challengeresponse", &result) != GS_OK) {
        ret = GS_INVALID;
        goto cleanup;
    }
    
    unsigned char challenge_response_data_enc[48];
    unsigned char challenge_response_data[48];
    for (int count = 0; count < strlen(result); count += 2) {
        sscanf(&result[count], "%2hhx", &challenge_response_data_enc[count / 2]);
    }
    free(result);
    
    for (int i = 0; i < 48; i += 16) {
        AES_decrypt(&challenge_response_data_enc[i], &challenge_response_data[i], &dec_key);
    }
    
    unsigned char client_secret_data[16];
    RAND_bytes(client_secret_data, 16);
    
    unsigned char challenge_response[16 + 256 + 16];
    unsigned char challenge_response_hash[32];
    unsigned char challenge_response_hash_enc[32];
    char challenge_response_hex[65];
    memcpy(challenge_response, challenge_response_data + 20, 16);
    memcpy(challenge_response + 16, g_Cert->signature->data, 256);
    memcpy(challenge_response + 16 + 256, client_secret_data, 16);
    SHA1(challenge_response, 16 + 256 + 16, challenge_response_hash);
    
    for (int i = 0; i < 32; i += 16) {
        AES_encrypt(&challenge_response_hash[i], &challenge_response_hash_enc[i], &enc_key);
    }
    bytes_to_hex(challenge_response_hash_enc, challenge_response_hex, 32);
    
    sprintf(url, "http://%s:47989/pair?uniqueid=%s&devicename=roth&updateState=1&serverchallengeresp=%s", address, g_UniqueId, challenge_response_hex);
    if ((ret = http_request(url, data)) != GS_OK)
        goto cleanup;
    
    if (xml_search(data->memory, data->size, "pairingsecret", &result) != GS_OK) {
        ret = GS_INVALID;
        goto cleanup;
    }
    
    unsigned char *signature = NULL;
    size_t s_len;
    if (sign_it(client_secret_data, 16, &signature, &s_len, g_PrivateKey) != GS_OK) {
        gs_error = "Failed to sign data";
        ret = GS_FAILED;
        goto cleanup;
    }
    
    unsigned char client_pairing_secret[16 + 256];
    char client_pairing_secret_hex[(16 + 256) * 2 + 1];
    memcpy(client_pairing_secret, client_secret_data, 16);
    memcpy(client_pairing_secret + 16, signature, 256);
    bytes_to_hex(client_pairing_secret, client_pairing_secret_hex, 16 + 256);
    
    sprintf(url, "http://%s:47989/pair?uniqueid=%s&devicename=roth&updateState=1&clientpairingsecret=%s", address, g_UniqueId, client_pairing_secret_hex);
    if ((ret = http_request(url, data)) != GS_OK)
        goto cleanup;
    
    sprintf(url, "https://%s:47984/pair?uniqueid=%s&devicename=roth&updateState=1&phrase=pairchallenge", address, g_UniqueId);
    if ((ret = http_request(url, data)) != GS_OK)
        goto cleanup;
    
cleanup:
    http_free_data(data);
    
    return ret;
}
コード例 #9
0
ファイル: mon_search.c プロジェクト: jinrenlab/tanlz
/******************************************************************************
 **函数名称: mon_srch_recv_rsp
 **功    能: 接收搜索应答信息
 **输入参数:
 **     fd: 文件描述符
 **输出参数: NONE
 **返    回: 0:成功 !0:失败
 **实现描述: 
 **注意事项: 
 **作    者: # Qifeng.zou # 2015.06.05 17:01:04 #
 ******************************************************************************/
static int mon_srch_recv_rsp(mon_cntx_t *ctx, mon_srch_conn_t *conn)
{
    int idx;
    ssize_t n;
    char addr[8192];
    serial_t serial;
    xml_opt_t opt;
    xml_tree_t *xml;
    xml_node_t *node, *attr;
    struct timeval ctm;
    int sec, msec, usec;
    agent_header_t head;
    mesg_data_t *rsp;

    memset(addr, 0, sizeof(addr));

    /* > 接收应答数据 */
    n = read(conn->fd, (void *)&head, sizeof(head));
    gettimeofday(&ctm, NULL);
    if (n <= 0) {
        fprintf(stderr, "    errmsg:[%d] %s!\n", errno, strerror(errno));
        return -1;
    }
    else if (0 == conn->wrtm.tv_sec) {
        fprintf(stderr, "    Didn't send search request but received response!\n");
    }

    /* > 字节序转换 */
    head.type = ntohl(head.type);
    head.flag = ntohl(head.flag);
    head.length = ntohl(head.length);
    head.mark = ntohl(head.mark);
    head.serial = ntoh64(head.serial);

    n = read(conn->fd, addr, head.length);

    /* > 显示查询结果 */
    fprintf(stderr, "    ============================================\n");
    rsp = (mesg_data_t *)addr;

    rsp->serial = ntoh64(rsp->serial);

    serial.serial = head.serial;
    fprintf(stderr, "    >Serial: %lu [nid(%u) sid(%u) seq(%u)]\n",
            head.serial, serial.nid, serial.sid, serial.seq);
    fprintf(stderr, "    >Serial: %lu:%lu\n",
            rsp->serial, head.serial);

    memset(&opt, 0, sizeof(opt));

    opt.pool = NULL;
    opt.alloc = mem_alloc;
    opt.dealloc = mem_dealloc;

    xml = xml_screat(rsp->body, head.length, &opt);
    if (NULL == xml) { 
        fprintf(stderr, "    Format isn't right! body:%s\n", rsp->body);
        return -1;
    }
    
    node = xml_query(xml, ".SEARCH-RSP.ITEM");
    for (idx=1; NULL != node; node = xml_brother(node), ++idx) {
        attr = xml_search(xml, node, "URL");
        fprintf(stderr, "        [%02d] URL:%s", idx, attr->value.str);

        attr = xml_search(xml, node, "FREQ");
        fprintf(stderr, "    FREQ:%s\n", attr->value.str);
    }

    xml_destroy(xml);

    /* > 打印统计信息 */
    sec = ctm.tv_sec - conn->wrtm.tv_sec;
    msec = (ctm.tv_usec - conn->wrtm.tv_usec)/1000;
    if (msec < 0) {
        sec -= 1;
        msec += 1000;
    }
    usec = (ctm.tv_usec - conn->wrtm.tv_usec)%1000;
    if (usec < 0) {
        usec += 1000;
        msec -= 1;
        if (msec < 0) {
            sec -= 1;
            msec += 1000;
        }
    }
    if (msec < 0) {
        msec += 1000;
        sec -= 1;
    }

    fprintf(stderr, "    >Spend: %d(s).%03d(ms).%03d(us)\n", sec, msec, usec);
    fprintf(stderr, "    ============================================\n");

    return 0;
}
コード例 #10
0
ファイル: frwd_conf.c プロジェクト: jinrenlab/tanlz
/******************************************************************************
 **函数名称: frwd_conf_load_frwder
 **功    能: 加载转发配置
 **输入参数: 
 **     xml: XML树
 **     path: 结点路径
 **输出参数:
 **     conf: 发送配置
 **返    回: 0:成功 !0:失败
 **实现描述: 
 **注意事项: 
 **作    者: # Qifeng.zou # 2015.06.09 #
 ******************************************************************************/
static int frwd_conf_load_frwder(xml_tree_t *xml, const char *path, rtsd_conf_t *conf)
{
    xml_node_t *parent, *node;

    parent = xml_query(xml, path);
    if (NULL == parent) {
        fprintf(stderr, "Didn't find %s!\n", path);
        return -1;
    }

    /* > 结点ID */
    node = xml_search(xml, parent, "NODE");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.NODE!\n", path);
        return -1;
    }

    conf->nodeid = atoi(node->value.str);

    /* > 工作路径 */
    node = xml_search(xml, parent, "PATH");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.PATH!\n", path);
        return -1;
    }

    snprintf(conf->path, sizeof(conf->path), "%s", node->value.str);

    /* > 服务端IP */
    node = xml_search(xml, parent, "SERVER.IP");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.SERVER.IP!\n", path);
        return -1;
    }

    snprintf(conf->ipaddr, sizeof(conf->ipaddr), "%s", node->value.str);

    node = xml_search(xml, parent, "SERVER.PORT");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.SERVER.PORT!\n", path);
        return -1;
    }

    conf->port = atoi(node->value.str);

    /* > 鉴权信息 */
    node = xml_search(xml, parent, "AUTH.USR");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.AUTH.USR!\n", path);
        return -1;
    }

    snprintf(conf->auth.usr, sizeof(conf->auth.usr), "%s", node->value.str);

    node = xml_search(xml, parent, "AUTH.PASSWD");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.AUTH.PASSWD!\n", path);
        return -1;
    }

    snprintf(conf->auth.passwd, sizeof(conf->auth.passwd), "%s", node->value.str);

    /* > 线程数目 */
    node = xml_search(xml, parent, "THREAD-POOL.SEND_THD_NUM");  /* 发送线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.THREAD-POOL.SEND_THD_NUM!\n", path);
        return -1;
    }

    conf->send_thd_num = atoi(node->value.str);
    if (0 == conf->send_thd_num) {
        fprintf(stderr, "%s.THREAD-POOL.SEND_THD_NUM is zero!\n", path);
        return -1;
    }

    node = xml_search(xml, parent, "THREAD-POOL.WORK_THD_NUM");  /* 工作线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.THREAD-POOL.WORK_THD_NUM!\n", path);
        return -1;
    }

    conf->work_thd_num = atoi(node->value.str);
    if (0 == conf->work_thd_num) {
        fprintf(stderr, "%s.THREAD-POOL.WORK_THD_NUM is zero!\n", path);
        return -1;
    }

    /* > 缓存大小配置 */
    node = xml_search(xml, parent, "BUFFER-POOL-SIZE.RECV");  /* 接收缓存(MB) */
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.BUFFER-POOL-SIZE.RECV!\n", path);
        return -1;
    }

    conf->recv_buff_size = atoi(node->value.str) * MB;
    if (0 == conf->recv_buff_size) {
        return -1;
    }

    /* > 接收队列 */
    node = xml_search(xml, parent, "RECVQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.RECVQ.MAX!\n", path);
        return -1;
    }

    conf->recvq.max = atoi(node->value.str);
    if (0 == conf->recvq.max) {
        fprintf(stderr, "%s.RECVQ.MAX is zero!\n", path);
        return -1;
    }

    node = xml_search(xml, parent, "RECVQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.RECVQ.SIZE!\n", path);
        return -1;
    }

    conf->recvq.size = atoi(node->value.str);
    if (0 == conf->recvq.size) {
        fprintf(stderr, "%s.RECVQ.SIZE is zero!\n", path);
        return -1;
    }

    /* > 发送队列 */
    node = xml_search(xml, parent, "SENDQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.SENDQ.MAX!\n", path);
        return -1;
    }

    conf->sendq.max = atoi(node->value.str);
    if (0 == conf->sendq.max) {
        fprintf(stderr, "%s.SENDQ.MAX is zero!\n", path);
        return -1;
    }

    node = xml_search(xml, parent, "SENDQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        fprintf(stderr, "Didn't find %s.SENDQ.SIZE!\n", path);
        return -1;
    }

    conf->sendq.size = atoi(node->value.str);
    if (0 == conf->sendq.size) {
        fprintf(stderr, "%s.SENDQ.SIZE is zero!\n", path);
        return -1;
    }

    return 0;
}
コード例 #11
0
ファイル: bwxml.c プロジェクト: peper/pizza
// -----------------------------------------------
// ----------- main procedure for xml search -----
// -----------------------------------------------
int main(int argc, char *argv[])
{
  int getopt(int argc, char * const *argv, const char *options);
  void unbwi(char *);
  void xml_search(char *, int, char *);
  extern char *optarg;
  extern int optind, opterr;
  char *infile_name, *pattern, *tag;
  int c, num_opt, pattern_from_file;

  if(argc<3) {
    fprintf(stderr, "Usage:\n\t%s ",argv[0]);
    fprintf(stderr,"[-prv] [-x 1|2|3] [-c perc] [-w 0|1|2|3]");
    fprintf(stderr,"[-t tag] pattern bwifile\n");
    fprintf(stderr,"Valid options are:\n");
    fprintf(stderr,"\t-p    *pattern* gives the pattern file name\n");    
    fprintf(stderr,"\t-r    report row # and position of the occurrences\n");
    fprintf(stderr,"\t-v    produces a verbose output\n");
    fprintf(stderr,"\t-C    only count occurrences\n");
    fprintf(stderr,"\t-c    percentage of cached buckets (default 0)\n"); 
    fprintf(stderr,"\t-t    enclosing tag (default none)\n");
    fprintf(stderr,"\t-w    word search: 0=Subs 1=Pfx 2=Sfx ");
    fprintf(stderr,"3=FullWord (default 0)\n");
    fprintf(stderr,"\t-x    data access: 1=Ext, 2=Mmap, 3=In (default 1)\n\n");
    fprintf(stderr,"The command line was: ");
    for(c=0;c<argc;c++)
      fprintf(stderr,"%s ",argv[c]);
    fprintf(stderr,"\n\n");
    exit(1);
  }

  /* ----------------- read options --------------------- */
  Verbose=0;
  infile_name=NULL;
  num_opt = opterr=0;
  pattern_from_file = 0;
  Type_mem_ops = EXT_MEM;
  Cache_percentage = 0;
  Report_rows = 0;
  Word_search = 0;
  Count_only = 0;
  tag = NULL;

  while ((c=getopt(argc, argv, "rpvCc:t:w:x:")) != -1) {
    switch (c)
    {
      case 'v':
        Verbose++; break;
      case 'r':
        Report_rows=1; break;
      case 'x':
        Type_mem_ops = atoi(optarg); break;
      case 'w':
        Word_search = atoi(optarg); break;
      case 'C':
        Count_only = 1; break;
      case 'c':
        Cache_percentage = atof(optarg); break;
      case 'p':
        pattern_from_file = 1; break;
      case 't':
        tag = optarg; break;
      case '?':
        fprintf(stderr,"Unknown option: %c -main-\n", c);
        exit(1);
    }
    num_opt++;
  }

  /* ------- read pattern and filename --------- */
  if(optind!=argc-2) {
    fprintf(stderr,"You must supply a pattern and a filename! -main-\n");
    exit(1);
  }
  else {
    pattern = (char *) argv[optind++];
    infile_name = (char *) argv[optind];
  }
  if(strlen(pattern)<=0) {
    fprintf(stderr,"Invalid pattern -main-\n");
    exit(1);
  }

  if((Cache_percentage < 0) || (Cache_percentage > 1)) {
    fprintf(stderr,"Cache percentage must be in [0,1] -main-\n");
    exit(1);
  } 
  if(strlen(infile_name)<=0) {
    fprintf(stderr,"Invalid file name -main-\n");
    exit(1);
  }
  if (check_bwi_suffix(infile_name) == 0){
     fprintf(stderr,"The file name must end with .bwi -main-\n");  
     exit(1);
  }
  if((Word_search<0) || (Word_search>3)) 
    fatal_error("Invalid word search option -main-\n");
  if((Type_mem_ops<1) || (Type_mem_ops>3))
    fatal_error("Invalid data access option -main-\n");

 
  if(Verbose>1) {
    fprintf(stderr,"\n*****************************************************");
    fprintf(stderr,"\n             bwxml  Ver 1.0\n");
    fprintf(stderr,"Created on %s at %s from %s\n",__DATE__,__TIME__,__FILE__);
    fprintf(stderr,"*****************************************************\n");
  }
  if(Verbose) {
    fprintf(stderr,"Command line: ");
    for(c=0;c<argc;c++)
      fprintf(stderr,"%s ",argv[c]);
    fprintf(stderr,"\n");
  }

  /* ----- Hilights the type of memory management ------ */
  if(Verbose) 
    switch(Type_mem_ops)
      {
      case EXT_MEM: 
	fprintf(stderr,"Memory management: via fopen, fread, getc, ...\n"); 
	break;
      case EXT_MMAP: 
	fprintf(stderr,"Memory management: via mmap() system call ...\n");
	break;
      case IN_MEM: 
	fprintf(stderr,"Memory management: internal memory ...\n"); 
	break;
      default: 
	fprintf(stderr,"Error: -- type mem ops --\n"); exit(1); break;
      }

  /* ---------  open input file ------------- */
  my_open_file(infile_name);

  /* ---------  Initialize the Cache System ------------- */
  init_bwi_cache();

  xml_search(pattern,pattern_from_file,tag);

  /* ---------  Report Cache Usage Information ------------- */
  if (Verbose) 
    report_bwi_cache_usage();

  my_fclose(Infile);
  return 0;
}
コード例 #12
0
ファイル: client.c プロジェクト: pomkac/moonlight-embedded
static int load_server_status(PSERVER_DATA server) {
  char *pairedText = NULL;
  char *currentGameText = NULL;
  char *versionText = NULL;
  char *stateText = NULL;

  uuid_t uuid;
  char uuid_str[37];
  
  int ret = GS_INVALID;
  char url[4096];
  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "https://%s:47984/serverinfo?uniqueid=%s&uuid=%s", server->address, unique_id, uuid_str);

  PHTTP_DATA data = http_create_data();
  if (data == NULL) {
    ret = GS_OUT_OF_MEMORY;
    goto cleanup;
  }
  if (http_request(url, data) != GS_OK) {
    ret = GS_IO_ERROR;
    goto cleanup;
  }

  if (xml_search(data->memory, data->size, "currentgame", &currentGameText) != GS_OK) {
    goto cleanup;
  }

  if (xml_search(data->memory, data->size, "PairStatus", &pairedText) != GS_OK)
    goto cleanup;

  if (xml_search(data->memory, data->size, "appversion", &versionText) != GS_OK)
    goto cleanup;

  if (xml_search(data->memory, data->size, "state", &stateText) != GS_OK)
    goto cleanup;

  server->paired = pairedText != NULL && strcmp(pairedText, "1") == 0;
  server->currentGame = currentGameText == NULL ? 0 : atoi(currentGameText);
  char *versionSep = strstr(versionText, ".");
  if (versionSep != NULL) {
    *versionSep = 0;
  }
  server->serverMajorVersion = atoi(versionText);
  if (strstr(stateText, "_SERVER_AVAILABLE")) {
    // After GFE 2.8, current game remains set even after streaming
    // has ended. We emulate the old behavior by forcing it to zero
    // if streaming is not active.
    server->currentGame = 0;
  }
  ret = GS_OK;

  cleanup:
  if (data != NULL)
    http_free_data(data);

  if (pairedText != NULL)
    free(pairedText);

  if (currentGameText != NULL)
    free(currentGameText);

  if (versionText != NULL)
    free(versionText);

  return ret;
}
コード例 #13
0
ファイル: client.c プロジェクト: JerJohn15/moonlight-embedded
int gs_pair(PSERVER_DATA server, char* pin) {
  int ret = GS_OK;
  char* result = NULL;
  char url[4096];
  uuid_t uuid;
  char uuid_str[37];

  if (server->paired) {
    gs_error = "Already paired";
    return GS_WRONG_STATE;
  }

  if (server->currentGame != 0) {
    gs_error = "The computer is currently in a game. You must close the game before pairing";
    return GS_WRONG_STATE;
  }

  unsigned char salt_data[16];
  char salt_hex[33];
  RAND_bytes(salt_data, 16);
  bytes_to_hex(salt_data, salt_hex, 16);

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "http://%s:47989/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&phrase=getservercert&salt=%s&clientcert=%s", server->address, unique_id, uuid_str, salt_hex, cert_hex);
  PHTTP_DATA data = http_create_data();
  if (data == NULL)
    return GS_OUT_OF_MEMORY;
  else if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  if ((ret = xml_search(data->memory, data->size, "paired", &result)) != GS_OK)
    goto cleanup;

  if (strcmp(result, "1") != 0) {
    gs_error = "Pairing failed";
    ret = GS_FAILED;
    goto cleanup;
  }

  free(result);
  result = NULL;
  if ((ret = xml_search(data->memory, data->size, "plaincert", &result)) != GS_OK)
    goto cleanup;

  if (strlen(result)/2 > 8191) {
    gs_error = "Server certificate too big";
    ret = GS_FAILED;
    goto cleanup;
  }

  char plaincert[8192];
  for (int count = 0; count < strlen(result); count += 2) {
    sscanf(&result[count], "%2hhx", &plaincert[count / 2]);
  }
  plaincert[strlen(result)/2] = '\0';
  printf("%d / %d\n", strlen(result)/2, strlen(plaincert));

  unsigned char salt_pin[20];
  unsigned char aes_key_hash[32];
  AES_KEY enc_key, dec_key;
  memcpy(salt_pin, salt_data, 16);
  memcpy(salt_pin+16, pin, 4);

  int hash_length = server->serverMajorVersion >= 7 ? 32 : 20;
  if (server->serverMajorVersion >= 7)
    SHA256(salt_pin, 20, aes_key_hash);
  else
    SHA1(salt_pin, 20, aes_key_hash);

  AES_set_encrypt_key((unsigned char *)aes_key_hash, 128, &enc_key);
  AES_set_decrypt_key((unsigned char *)aes_key_hash, 128, &dec_key);

  unsigned char challenge_data[16];
  unsigned char challenge_enc[16];
  char challenge_hex[33];
  RAND_bytes(challenge_data, 16);
  AES_encrypt(challenge_data, challenge_enc, &enc_key);
  bytes_to_hex(challenge_enc, challenge_hex, 16);

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "http://%s:47989/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&clientchallenge=%s", server->address, unique_id, uuid_str, challenge_hex);
  if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  free(result);
  result = NULL;
  if ((ret = xml_search(data->memory, data->size, "paired", &result)) != GS_OK)
    goto cleanup;

  if (strcmp(result, "1") != 0) {
    gs_error = "Pairing failed";
    ret = GS_FAILED;
    goto cleanup;
  }

  free(result);
  result = NULL;
  if (xml_search(data->memory, data->size, "challengeresponse", &result) != GS_OK) {
    ret = GS_INVALID;
    goto cleanup;
  }

  char challenge_response_data_enc[48];
  char challenge_response_data[48];
  for (int count = 0; count < strlen(result); count += 2) {
    sscanf(&result[count], "%2hhx", &challenge_response_data_enc[count / 2]);
  }

  for (int i = 0; i < 48; i += 16) {
    AES_decrypt(&challenge_response_data_enc[i], &challenge_response_data[i], &dec_key);
  }

  char client_secret_data[16];
  RAND_bytes(client_secret_data, 16);

  char challenge_response[16 + 256 + 16];
  char challenge_response_hash[32];
  char challenge_response_hash_enc[32];
  char challenge_response_hex[65];
  memcpy(challenge_response, challenge_response_data + hash_length, 16);
  memcpy(challenge_response + 16, cert->signature->data, 256);
  memcpy(challenge_response + 16 + 256, client_secret_data, 16);
  if (server->serverMajorVersion >= 7)
    SHA256(challenge_response, 16 + 256 + 16, challenge_response_hash);
  else
    SHA1(challenge_response, 16 + 256 + 16, challenge_response_hash);

  for (int i = 0; i < 32; i += 16) {
    AES_encrypt(&challenge_response_hash[i], &challenge_response_hash_enc[i], &enc_key);
  }
  bytes_to_hex(challenge_response_hash_enc, challenge_response_hex, 32);

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "http://%s:47989/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&serverchallengeresp=%s", server->address, unique_id, uuid_str, challenge_response_hex);
  if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  free(result);
  result = NULL;
  if ((ret = xml_search(data->memory, data->size, "paired", &result)) != GS_OK)
    goto cleanup;

  if (strcmp(result, "1") != 0) {
    gs_error = "Pairing failed";
    ret = GS_FAILED;
    goto cleanup;
  }

  free(result);
  result = NULL;
  if (xml_search(data->memory, data->size, "pairingsecret", &result) != GS_OK) {
    ret = GS_INVALID;
    goto cleanup;
  }

  char pairing_secret[16 + 256];
  for (int count = 0; count < strlen(result); count += 2) {
    sscanf(&result[count], "%2hhx", &pairing_secret[count / 2]);
  }

  if (!verifySignature(pairing_secret, 16, pairing_secret+16, 256, plaincert)) {
    gs_error = "MITM attack detected";
    ret = GS_FAILED;
    goto cleanup;
  }

  unsigned char *signature = NULL;
  size_t s_len;
  if (sign_it(client_secret_data, 16, &signature, &s_len, privateKey) != GS_OK) {
      gs_error = "Failed to sign data";
      ret = GS_FAILED;
      goto cleanup;
  }

  char client_pairing_secret[16 + 256];
  char client_pairing_secret_hex[(16 + 256) * 2 + 1];
  memcpy(client_pairing_secret, client_secret_data, 16);
  memcpy(client_pairing_secret + 16, signature, 256);
  bytes_to_hex(client_pairing_secret, client_pairing_secret_hex, 16 + 256);

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "http://%s:47989/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&clientpairingsecret=%s", server->address, unique_id, uuid_str, client_pairing_secret_hex);
  if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  free(result);
  result = NULL;
  if ((ret = xml_search(data->memory, data->size, "paired", &result)) != GS_OK)
    goto cleanup;

  if (strcmp(result, "1") != 0) {
    gs_error = "Pairing failed";
    ret = GS_FAILED;
    goto cleanup;
  }

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "https://%s:47984/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&phrase=pairchallenge", server->address, unique_id, uuid_str);
  if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  free(result);
  result = NULL;
  if ((ret = xml_search(data->memory, data->size, "paired", &result)) != GS_OK)
    goto cleanup;

  if (strcmp(result, "1") != 0) {
    gs_error = "Pairing failed";
    ret = GS_FAILED;
    goto cleanup;
  }

  server->paired = true;

  cleanup:
  if (ret != GS_OK)
    gs_unpair(server);
  
  if (result != NULL)
    free(result);

  http_free_data(data);

  return ret;
}
コード例 #14
0
ファイル: client.c プロジェクト: JerJohn15/moonlight-embedded
static int load_server_status(PSERVER_DATA server) {

  uuid_t uuid;
  char uuid_str[37];

  int ret;
  char url[4096];
  int i;

  i = 0;
  do {
    char *pairedText = NULL;
    char *currentGameText = NULL;
    char *versionText = NULL;
    char *stateText = NULL;
    char *heightText = NULL;
    char *serverCodecModeSupportText = NULL;

    ret = GS_INVALID;

    uuid_generate_random(uuid);
    uuid_unparse(uuid, uuid_str);

    // Modern GFE versions don't allow serverinfo to be fetched over HTTPS if the client
    // is not already paired. Since we can't pair without knowing the server version, we
    // make another request over HTTP if the HTTPS request fails. We can't just use HTTP
    // for everything because it doesn't accurately tell us if we're paired.
    sprintf(url, "%s://%s:%d/serverinfo?uniqueid=%s&uuid=%s",
      i == 0 ? "https" : "http", server->address, i == 0 ? 47984 : 47989, unique_id, uuid_str);

    PHTTP_DATA data = http_create_data();
    if (data == NULL) {
      ret = GS_OUT_OF_MEMORY;
      goto cleanup;
    }
    if (http_request(url, data) != GS_OK) {
      ret = GS_IO_ERROR;
      goto cleanup;
    }

    if (xml_search(data->memory, data->size, "currentgame", &currentGameText) != GS_OK) {
      goto cleanup;
    }

    if (xml_search(data->memory, data->size, "PairStatus", &pairedText) != GS_OK)
      goto cleanup;

    if (xml_search(data->memory, data->size, "appversion", &versionText) != GS_OK)
      goto cleanup;

    if (xml_search(data->memory, data->size, "state", &stateText) != GS_OK)
      goto cleanup;

    if (xml_search(data->memory, data->size, "Height", &heightText) != GS_OK)
      goto cleanup;

    if (xml_search(data->memory, data->size, "ServerCodecModeSupport", &serverCodecModeSupportText) != GS_OK)
      goto cleanup;

    if (xml_search(data->memory, data->size, "gputype", &server->gpuType) != GS_OK)
      goto cleanup;

    if (xml_search(data->memory, data->size, "GfeVersion", &server->gfeVersion) != GS_OK)
      goto cleanup;

    // These fields are present on all version of GFE that this client supports
    if (!strlen(currentGameText) || !strlen(pairedText) || !strlen(versionText) || !strlen(stateText))
      goto cleanup;

    server->paired = pairedText != NULL && strcmp(pairedText, "1") == 0;
    server->currentGame = currentGameText == NULL ? 0 : atoi(currentGameText);
    server->supports4K = heightText != NULL && serverCodecModeSupportText != NULL && atoi(heightText) >= 2160;
    server->serverMajorVersion = atoi(versionText);
    if (strstr(stateText, "_SERVER_AVAILABLE")) {
      // After GFE 2.8, current game remains set even after streaming
      // has ended. We emulate the old behavior by forcing it to zero
      // if streaming is not active.
      server->currentGame = 0;
    }
    ret = GS_OK;

    cleanup:
    if (data != NULL)
      http_free_data(data);

    if (pairedText != NULL)
      free(pairedText);

    if (currentGameText != NULL)
      free(currentGameText);

    if (versionText != NULL)
      free(versionText);

    if (heightText != NULL)
      free(heightText);

    if (serverCodecModeSupportText != NULL)
      free(serverCodecModeSupportText);

    i++;
  } while (ret != GS_OK && i < 2);

  if (ret == GS_OK) {
    if (server->serverMajorVersion > MAX_SUPPORTED_GFE_VERSION) {
      gs_error = "Ensure you're running the latest version of Moonlight Embedded or downgrade GeForce Experience and try again";
      ret = GS_UNSUPPORTED_VERSION;
    } else if (server->serverMajorVersion < MIN_SUPPORTED_GFE_VERSION) {
      gs_error = "Moonlight Embedded requires a newer version of GeForce Experience. Please upgrade GFE on your PC and try again.";
      ret = GS_UNSUPPORTED_VERSION;
    }
  }

  return ret;
}
コード例 #15
0
ファイル: lwsd_conf.c プロジェクト: Qiware/tanlz
/******************************************************************************
 **函数名称: lwsd_conf_load_frwder
 **功    能: 加载转发配置
 **输入参数: 
 **     path: 配置文件路径
 **     log: 日志对象
 **输出参数:
 **     conf: 配置信息
 **返    回: 0:成功 !0:失败
 **实现描述: 提取配置文件中的数据
 **注意事项: 
 **作    者: # Qifeng.zou # 2015-06-25 22:43:12 #
 ******************************************************************************/
static int lwsd_conf_load_frwder(xml_tree_t *xml, lwsd_conf_t *lcf, log_cycle_t *log)
{
    xml_node_t *parent, *node;
    rtmq_proxy_conf_t *conf = &lcf->frwder;

    parent = xml_query(xml, ".LISTEND.FRWDER");
    if (NULL == parent) {
        log_error(log, "Didn't find invertd configuation!");
        return -1;
    }

    /* > 设置结点ID */
    conf->nid = lcf->nid;
    snprintf(conf->path, sizeof(conf->path), "%s", lcf->wdir);

    /* > 服务端IP */
    node = xml_search(xml, parent, "SERVER.IP");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SERVER.IP!");
        return -1;
    }

    snprintf(conf->ipaddr, sizeof(conf->ipaddr), "%s", node->value.str);

    node = xml_search(xml, parent, "SERVER.PORT");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SERVER.PORT!");
        return -1;
    }

    conf->port = str_to_num(node->value.str);

    /* > 鉴权信息 */
    node = xml_search(xml, parent, "AUTH.USR");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find AUTH.USR!");
        return -1;
    }

    snprintf(conf->auth.usr, sizeof(conf->auth.usr), "%s", node->value.str);

    node = xml_search(xml, parent, "AUTH.PASSWD");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find AUTH.PASSWD!");
        return -1;
    }

    snprintf(conf->auth.passwd, sizeof(conf->auth.passwd), "%s", node->value.str);

    /* > 线程数目 */
    node = xml_search(xml, parent, "THREAD-POOL.SEND_THD_NUM");  /* 发送线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find THREAD-POOL.SEND_THD_NUM!");
        return -1;
    }

    conf->send_thd_num = str_to_num(node->value.str);
    if (0 == conf->send_thd_num) {
        log_error(log, "THREAD-POOL.SEND_THD_NUM is zero!");
        return -1;
    }

    node = xml_search(xml, parent, "THREAD-POOL.WORK_THD_NUM");  /* 工作线程数 */
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find THREAD-POOL.WORK_THD_NUM!");
        return -1;
    }

    conf->work_thd_num = str_to_num(node->value.str);
    if (0 == conf->work_thd_num) {
        log_error(log, "THREAD-POOL.WORK_THD_NUM is zero!");
        return -1;
    }

    /* > 缓存大小配置 */
    node = xml_search(xml, parent, "BUFFER-POOL-SIZE.RECV");  /* 接收缓存(MB) */
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find BUFFER-POOL-SIZE.RECV!");
        return -1;
    }

    conf->recv_buff_size = str_to_num(node->value.str) * MB;
    if (0 == conf->recv_buff_size) {
        return -1;
    }

    /* > 接收队列 */
    node = xml_search(xml, parent, "RECVQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find RECVQ.MAX!");
        return -1;
    }

    conf->recvq.max = str_to_num(node->value.str);
    if (0 == conf->recvq.max) {
        log_error(log, "RECVQ.MAX is zero!");
        return -1;
    }

    node = xml_search(xml, parent, "RECVQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find RECVQ.SIZE!");
        return -1;
    }

    conf->recvq.size = str_to_num(node->value.str);
    if (0 == conf->recvq.size) {
        log_error(log, "RECVQ.SIZE is zero!");
        return -1;
    }

    /* > 发送队列 */
    node = xml_search(xml, parent, "SENDQ.MAX");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SENDQ.MAX!");
        return -1;
    }

    conf->sendq.max = str_to_num(node->value.str);
    if (0 == conf->sendq.max) {
        log_error(log, "SENDQ.MAX is zero!");
        return -1;
    }

    node = xml_search(xml, parent, "SENDQ.SIZE");
    if (NULL == node
        || 0 == node->value.len)
    {
        log_error(log, "Didn't find SENDQ.SIZE!");
        return -1;
    }

    conf->sendq.size = str_to_num(node->value.str);
    if (0 == conf->sendq.size) {
        log_error(log, "SENDQ.SIZE is zero!");
        return -1;
    }

    return 0;
}
コード例 #16
0
ファイル: client.c プロジェクト: pomkac/moonlight-embedded
int gs_pair(PSERVER_DATA server, char* pin) {
  int ret = GS_OK;
  char url[4096];
  uuid_t uuid;
  char uuid_str[37];

  if (server->paired) {
    gs_error = "Already paired";
    return GS_WRONG_STATE;
  }

  if (server->currentGame != 0) {
    gs_error = "The computer is currently in a game. You must close the game before pairing";
    return GS_WRONG_STATE;
  }

  unsigned char salt_data[16];
  char salt_hex[33];
  RAND_bytes(salt_data, 16);
  bytes_to_hex(salt_data, salt_hex, 16);

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "http://%s:47989/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&phrase=getservercert&salt=%s&clientcert=%s", server->address, unique_id, uuid_str, salt_hex, cert_hex);
  PHTTP_DATA data = http_create_data();
  if (data == NULL)
    return GS_OUT_OF_MEMORY;
  else if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  unsigned char salt_pin[20];
  unsigned char aes_key_hash[20];
  AES_KEY aes_key;
  memcpy(salt_pin, salt_data, 16);
  memcpy(salt_pin+16, salt_pin, 4);
  SHA1(salt_pin, 20, aes_key_hash);
  AES_set_encrypt_key((unsigned char *)aes_key_hash, 128, &aes_key);

  unsigned char challenge_data[16];
  unsigned char challenge_enc[16];
  char challenge_hex[33];
  RAND_bytes(challenge_data, 16);
  AES_encrypt(challenge_data, challenge_enc, &aes_key);
  bytes_to_hex(challenge_enc, challenge_hex, 16);

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "http://%s:47989/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&clientchallenge=%s", server->address, unique_id, uuid_str, challenge_hex);
  if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  char *result;
  if (xml_search(data->memory, data->size, "challengeresponse", &result) != GS_OK) {
    ret = GS_INVALID;
    goto cleanup;
  }

  char challenge_response_data_enc[48];
  char challenge_response_data[48];
  for (int count = 0; count < strlen(result); count++) {
    sscanf(&result[count], "%2hhx", &challenge_response_data_enc[count / 2]);
  }
  free(result);

  for (int i = 0; i < 48; i += 16) {
    AES_decrypt(&challenge_response_data_enc[i], &challenge_response_data[i], &aes_key);
  }

  char client_secret_data[16];
  RAND_bytes(client_secret_data, 16);

  char challenge_response[16 + 256 + 16];
  char challenge_response_hash[32];
  char challenge_response_hash_enc[32];
  char challenge_response_hex[33];
  memcpy(challenge_response, challenge_response_data + 20, 16);
  memcpy(challenge_response + 16, cert->signature->data, 256);
  memcpy(challenge_response + 16 + 256, client_secret_data, 16);
  SHA1(challenge_response, 16 + 256 + 16, challenge_response_hash);

  for (int i = 0; i < 32; i += 16) {
    AES_encrypt(&challenge_response_hash[i], &challenge_response_hash_enc[i], &aes_key);
  }
  bytes_to_hex(challenge_response_hash_enc, challenge_response_hex, 32);

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "http://%s:47989/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&serverchallengeresp=%s", server->address, unique_id, uuid_str, challenge_response_hex);
  if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  if (xml_search(data->memory, data->size, "pairingsecret", &result) != GS_OK) {
    ret = GS_INVALID;
    goto cleanup;
  }

  unsigned char *signature = NULL;
  size_t s_len;
  if (sign_it(client_secret_data, 16, &signature, &s_len, privateKey) != GS_OK) {
      gs_error = "Failed to sign data";
      ret = GS_FAILED;
      goto cleanup;
  }

  char client_pairing_secret[16 + 256];
  char client_pairing_secret_hex[(16 + 256) * 2 + 1];
  memcpy(client_pairing_secret, client_secret_data, 16);
  memcpy(client_pairing_secret + 16, signature, 256);
  bytes_to_hex(client_pairing_secret, client_pairing_secret_hex, 16 + 256);

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "http://%s:47989/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&clientpairingsecret=%s", server->address, unique_id, uuid_str, client_pairing_secret_hex);
  if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  uuid_generate_random(uuid);
  uuid_unparse(uuid, uuid_str);
  sprintf(url, "https://%s:47984/pair?uniqueid=%s&uuid=%s&devicename=roth&updateState=1&phrase=pairchallenge", server->address, unique_id, uuid_str);
  if ((ret = http_request(url, data)) != GS_OK)
    goto cleanup;

  server->paired = true;

  cleanup:
  http_free_data(data);

  return ret;
}
コード例 #17
0
ファイル: flt_worker.c プロジェクト: jinrenlab/tanlz
/******************************************************************************
 **函数名称: flt_worker_get_webpage_info
 **功    能: 获取网页信息
 **输入参数:
 **     path: 网页信息文件
 **输出参数:
 **     info: 网页信息
 **返    回: 0:成功 !0:失败
 **实现描述:
 **注意事项:
 **作    者: # Qifeng.zou # 2015.03.11 #
 ******************************************************************************/
static int flt_worker_get_webpage_info(
        const char *path, flt_webpage_info_t *info, log_cycle_t *log)
{
    xml_opt_t opt;
    xml_tree_t *xml;
    mem_pool_t *pool;
    xml_node_t *node, *fix;

    memset(&opt, 0, sizeof(opt));

    /* 1. 新建内存池 */
    pool = mem_pool_creat(4 * KB);
    if (NULL == pool) {
        log_error(log, "errmsg:[%d] %s!", errno, strerror(errno));
        return FLT_ERR;
    }

    /* 2. 新建XML树 */
    opt.log = log;
    opt.pool = pool;
    opt.alloc = (mem_alloc_cb_t)mem_pool_alloc;
    opt.dealloc = (mem_dealloc_cb_t)mem_pool_dealloc;

    xml = xml_creat(path, &opt);
    if (NULL == xml) {
        mem_pool_destroy(pool);
        log_error(log, "Create XML failed! path:%s", path);
        return FLT_ERR;
    }

    /* 2. 提取网页信息 */
    do {
        fix = xml_query(xml, ".WPI");
        if (NULL == fix) {
            log_error(log, "Get WPI mark failed!");
            break;
        }

        /* 获取URI字段 */
        node = xml_search(xml, fix, "URI");
        if (NULL == node) {
            log_error(log, "Get URI mark failed!");
            break;
        }

        snprintf(info->uri, sizeof(info->uri), "%s", node->value.str);

        /* 获取DEPTH字段 */
        node = xml_search(xml, fix, "URI.DEPTH");
        if (NULL == node) {
            log_error(log, "Get DEPTH mark failed!");
            break;
        }

        info->depth = atoi(node->value.str);

        /* 获取IP字段 */
        node = xml_search(xml, fix, "URI.IP");
        if (NULL == node) {
            log_error(log, "Get IP mark failed!");
            break;
        }

        snprintf(info->ip, sizeof(info->ip), "%s", node->value.str);

        /* 获取PORT字段 */
        node = xml_search(xml, fix, "URI.PORT");
        if (NULL == node) {
            log_error(log, "Get PORT mark failed!");
            break;
        }

        info->port = atoi(node->value.str);

        /* 获取HTML字段 */
        node = xml_search(xml, fix, "HTML");
        if (NULL == node) {
            log_error(log, "Get HTML mark failed!");
            break;
        }

        snprintf(info->html, sizeof(info->html), "%s", node->value.str);

        /* 获取HTML.SIZE字段 */
        node = xml_search(xml, fix, "HTML.SIZE");
        if (NULL == node) {
            log_error(log, "Get HTML.SIZE mark failed!");
            break;
        }

        info->size = atoi(node->value.str);
        if (info->size <= 0) {
            log_info(log, "Html size is zero!");
            break;
        }

        snprintf(info->fname, sizeof(info->fname), "%s", path);

        xml_destroy(xml);
        mem_pool_destroy(pool);
        return FLT_OK;
    } while(0);

    /* 3. 释放XML树 */
    xml_destroy(xml);
    mem_pool_destroy(pool);
    return FLT_ERR;
}