int c1s1::s1_create(c1s1* c1)
 {
     int ret = ERROR_SUCCESS;
     
     if (c1->schema == srs_schema_invalid) {
         ret = ERROR_RTMP_CH_SCHEMA;
         srs_error("create s1 failed. invalid schema=%d, ret=%d", c1->schema, ret);
         return ret;
     }
     
     destroy_blocks();
     schema = c1->schema;
     
     time = ::time(NULL);
     version = 0x01000504; // server s1 version
     
     if (schema == srs_schema0) {
         srs_key_block_init(&block0.key);
         srs_digest_block_init(&block1.digest);
         
         // directly generate the public key.
         // @see: https://github.com/winlinvip/simple-rtmp-server/issues/148
         if ((ret = openssl_generate_key(block0.key.key, 128)) != ERROR_SUCCESS) {
             srs_error("calc s1 key failed. ret=%d", ret);
             return ret;
         }
     } else {
         srs_digest_block_init(&block0.digest);
         srs_key_block_init(&block1.key);
         
         // directly generate the public key.
         // @see: https://github.com/winlinvip/simple-rtmp-server/issues/148
         if ((ret = openssl_generate_key(block1.key.key, 128)) != ERROR_SUCCESS) {
             srs_error("calc s1 key failed. ret=%d", ret);
             return ret;
         }
     }
     srs_verbose("calc s1 key success.");
         
     char* s1_digest = NULL;
     if ((ret = calc_s1_digest(s1_digest))  != ERROR_SUCCESS) {
         srs_error("calc s1 digest failed. ret=%d", ret);
         return ret;
     }
     srs_verbose("calc s1 digest success.");
     
     srs_assert(s1_digest != NULL);
     SrsAutoFree(char, s1_digest);
     
     if (schema == srs_schema0) {
         memcpy(block1.digest.digest, s1_digest, 32);
     } else {
         memcpy(block0.digest.digest, s1_digest, 32);
     }
     srs_verbose("copy s1 key success.");
     
     return ret;
 }
int c1s1::s1_create(c1s1* c1,u_int8_t *&shared_key)
{
    int ret = ERROR_SUCCESS;

    if (c1->schema == srs_schema_invalid) {
        ret = ERROR_RTMP_CH_SCHEMA;
        log_error("create s1 failed. invalid schema=%d, ret=%d", c1->schema, ret);
        return ret;
    }

    destroy_blocks();
    schema = c1->schema;

    time = ::time(NULL);
    version = 0x01000504; // server s1 version

    if (schema == srs_schema0) {
        srs_key_block_init(&block0.key);
        srs_digest_block_init(&block1.digest);
    } else {
        srs_digest_block_init(&block0.digest);
        srs_key_block_init(&block1.key);
    }

    if (schema == srs_schema0) {
        if ((ret = openssl_generate_key(c1->block0.key.key, block0.key.key, 128,shared_key)) != ERROR_SUCCESS) {
            log_error("calc s1 key failed. ret=%d", ret);
            return ret;
        }
    } else {
        if ((ret = openssl_generate_key(c1->block1.key.key, block1.key.key, 128,shared_key)) != ERROR_SUCCESS) {
            log_error("calc s1 key failed. ret=%d", ret);
            return ret;
        }
    }
    log_verbose("calc s1 key success.");

    char *s1_digest = NULL;
    if ((ret = calc_s1_digest(s1_digest))  != ERROR_SUCCESS) {
        log_error("calc s1 digest failed. ret=%d", ret);
        return ret;
    }
    log_verbose("calc s1 digest success.");

    mAssert(s1_digest != NULL);
    mAutoFreeArray(char, s1_digest);

    if (schema == srs_schema0) {
        memcpy(block1.digest.digest, s1_digest, 32);
    } else {
        memcpy(block0.digest.digest, s1_digest, 32);
    }
    log_verbose("copy s1 key success.");

    return ret;
}
int c1s1::c1_create(srs_schema_type _schema)
{
    int ret = ERROR_SUCCESS;

    if (_schema == srs_schema_invalid) {
        ret = ERROR_RTMP_CH_SCHEMA;
        log_error("create c1 failed. invalid schema=%d, ret=%d", _schema, ret);
        return ret;
    }

    destroy_blocks();

    time = ::time(NULL);
    // client c1 version
    char *_version = (char *)&version;
    _version[0] = 10;
    _version[1] = 0;
    _version[2] = 45;
    _version[3] = 2;

    if (_schema == srs_schema0) {
        srs_key_block_init(&block0.key);
        srs_digest_block_init(&block1.digest);
    } else {
        srs_digest_block_init(&block0.digest);
        srs_key_block_init(&block1.key);
    }

    schema = _schema;

    char *digest = NULL;

    if ((ret = calc_c1_digest(digest)) != ERROR_SUCCESS) {
        log_error("sign c1 error, failed to calc digest. ret=%d", ret);
        return ret;
    }

    mAssert(digest != NULL);
    mAutoFreeArray(char, digest);

    if (schema == srs_schema0) {
        memcpy(block1.digest.digest, digest, 32);
    } else {
        memcpy(block0.digest.digest, digest, 32);
    }

    return ret;
}
 int c1s1::c1_create(srs_schema_type _schema)
 {
     int ret = ERROR_SUCCESS;
     
     if (_schema == srs_schema_invalid) {
         ret = ERROR_RTMP_CH_SCHEMA;
         srs_error("create c1 failed. invalid schema=%d, ret=%d", _schema, ret);
         return ret;
     }
     
     destroy_blocks();
     
     // client c1 time and version
     time = ::time(NULL);
     version = 0x80000702; // client c1 version
     
     // generate signature by schema
     if (_schema == srs_schema0) {
         srs_key_block_init(&block0.key);
         srs_digest_block_init(&block1.digest);
     } else {
         srs_digest_block_init(&block0.digest);
         srs_key_block_init(&block1.key);
     }
     
     schema = _schema;
     
     // generate digest
     char* digest = NULL;
     
     if ((ret = calc_c1_digest(digest)) != ERROR_SUCCESS) {
         srs_error("sign c1 error, failed to calc digest. ret=%d", ret);
         return ret;
     }
     
     srs_assert(digest != NULL);
     SrsAutoFree(char, digest);
     
     if (schema == srs_schema0) {
         memcpy(block1.digest.digest, digest, 32);
     } else {
         memcpy(block0.digest.digest, digest, 32);
     }
     
     return ret;
 }
 int c1s1::parse(char* _c1s1, srs_schema_type _schema)
 {
     int ret = ERROR_SUCCESS;
     
     if (_schema == srs_schema_invalid) {
         ret = ERROR_RTMP_CH_SCHEMA;
         srs_error("parse c1 failed. invalid schema=%d, ret=%d", _schema, ret);
         return ret;
     }
     
     destroy_blocks();
     
     
     time = __srs_stream_read_4bytes(_c1s1);
     version = __srs_stream_read_4bytes(_c1s1 + 4); // client c1 version
     
     if (_schema == srs_schema0) {
         if ((ret = srs_key_block_parse(&block0.key, _c1s1 + 8)) != ERROR_SUCCESS) {
             srs_error("parse the c1 key failed. ret=%d", ret);
             return ret;
         }
         if ((ret = srs_digest_block_parse(&block1.digest, _c1s1 + 8 + 764)) != ERROR_SUCCESS) {
             srs_error("parse the c1 digest failed. ret=%d", ret);
             return ret;
         }
         srs_verbose("parse c1 key-digest success");
     } else if (_schema == srs_schema1) {
         if ((ret = srs_digest_block_parse(&block0.digest, _c1s1 + 8)) != ERROR_SUCCESS) {
             srs_error("parse the c1 key failed. ret=%d", ret);
             return ret;
         }
         if ((ret = srs_key_block_parse(&block1.key, _c1s1 + 8 + 764)) != ERROR_SUCCESS) {
             srs_error("parse the c1 digest failed. ret=%d", ret);
             return ret;
         }
         srs_verbose("parse c1 digest-key success");
     } else {
         ret = ERROR_RTMP_CH_SCHEMA;
         srs_error("parse c1 failed. invalid schema=%d, ret=%d", _schema, ret);
         return ret;
     }
     
     schema = _schema;
     
     return ret;
 }
示例#6
0
static int read_conllx(FILE* fp)
{
    int num_sent = 0;
    unsigned int line_num = 0;
    char buff[BUF_SIZE];
    const char* sep = "\t";
    char *t, *line, *tofree;
    size_t len;

    const char** seq = xmalloc(sizeof(char *) * CONLLX_TOKEN_NUM_FIELDS);
    struct blocks* blocks = new_blocks(256);
    struct sentence* sent = sentence_new();

    while (fgets(buff, sizeof(buff), fp)) {
        line_num++;
        if (buff[0] == '\n') {
            latex_print_dep_tree(sent);
            sentence_destroy(sent);
            sent = sentence_new();
            num_sent++;
            continue;
        }
        len = strnlen(buff, BUF_SIZE);
        tofree = line = strndup(buff, len-1);
        blocks_add_elem(blocks, tofree);

        int i = 0;
        while ((t = strsep(&line, sep)) != NULL) {
            seq[i] = t;
            i++;
        }
        sentence_add_token(sent, token_new(seq, CONLLX_TOKEN_NUM_FIELDS));
    }
    destroy_blocks(blocks);
    sentence_destroy(sent);
    free(seq);
    fprintf(stderr, "INFO: Number of sentences = %d\n", num_sent);

    return 0;
}
 c1s1::~c1s1()
 {
     destroy_blocks();
 }
示例#8
0
Carrier::~Carrier ()
{
    destroy_blocks(m_reps, 1 + item_dim());
    free_blocks(m_reps);
}