Exemplo n.º 1
0
int transcode(const char *path)
{
	int ret;

	//if the file is a ts file
	ret = judge_file_suffix(path); //0, the file is not a ts file
	if (!ret)
		return 0;

	ret = if_file_exist(path); // -1 error; 0 not exist; 1 exist;
	if (ret == -1)
		return -1;
	else if (ret == 0)
	{
		TransTask task;
		ret = get_name_info(path, &task); //get the information from the file name.
		if (ret == -1)
		{
			servlog(ERROR, "can't get the info from file name:%s", path);
			return -1;
		}

		servlog(INFO, "task->file_name:%s", task.file_name);
		

		if(trans_file(&task, path))
			servlog(INFO, "transcode the file success:%s", path);
		else
		{
			servlog(ERROR, "fail to transcode the file:%s", path);
			return -1;
		}
	}
	return 0;
}
Exemplo n.º 2
0
int filter_before_apply(FilterReplyResultBase * const rb,
                        const unsigned int nongeneric_items,
                        const char * const function,
                        const struct sockaddr_storage * const sa_local,
                        const socklen_t sa_local_len,
                        const struct sockaddr_storage * const sa_remote,
                        const socklen_t sa_remote_len)
{
    Filter * const filter = filter_get();
    const AppContext * const context = sixjack_get_context();    
    assert(filter->msgpack_packer != NULL);
    msgpack_packer * const msgpack_packer = filter->msgpack_packer;
    msgpack_packer_init(msgpack_packer, filter->msgpack_sbuffer,
                        msgpack_sbuffer_write);
    unsigned int items_count = nongeneric_items + 5U;
    if (rb->pre == false) {
        items_count += 2U;
    }
    if (sa_local != NULL) {
        items_count += 2U;
    }
    if (sa_remote != NULL) {
        items_count += 2U;
    }
    msgpack_pack_map(msgpack_packer, items_count);
    
    msgpack_pack_mstring(msgpack_packer, "version");
    msgpack_pack_unsigned_short(msgpack_packer, VERSION_MAJOR);
    
    msgpack_pack_mstring(msgpack_packer, "filter_type");
    msgpack_pack_cstring(msgpack_packer, rb->pre ? "PRE" : "POST");
    
    msgpack_pack_mstring(msgpack_packer, "pid");
    msgpack_pack_unsigned_int(msgpack_packer, context->pid);

    msgpack_pack_mstring(msgpack_packer, "function");
    msgpack_pack_cstring(msgpack_packer, function);

    msgpack_pack_mstring(msgpack_packer, "fd");
    msgpack_pack_int(msgpack_packer, rb->fd);

    if (rb->pre == false) {
        msgpack_pack_mstring(msgpack_packer, "return_value");
        msgpack_pack_int(msgpack_packer, *rb->ret);
        
        msgpack_pack_mstring(msgpack_packer, "errno");
        msgpack_pack_int(msgpack_packer, *rb->ret_errno);
    }
    
    char host[NI_MAXHOST];
    in_port_t port;    
    if (sa_local != NULL) {
        get_name_info(sa_local, sa_local_len, host, &port);
        msgpack_pack_mstring(msgpack_packer, "local_host");
        msgpack_pack_cstring_or_nil(msgpack_packer, host);
        msgpack_pack_mstring(msgpack_packer, "local_port");
        msgpack_pack_unsigned_short(msgpack_packer, (unsigned short) port);
    }
    if (sa_remote != NULL) {
        get_name_info(sa_remote, sa_remote_len, host, &port);
        msgpack_pack_mstring(msgpack_packer, "remote_host");
        msgpack_pack_cstring_or_nil(msgpack_packer, host);
        msgpack_pack_mstring(msgpack_packer, "remote_port");
        msgpack_pack_unsigned_short(msgpack_packer, (unsigned short) port);
    }
    return 0;
}
Exemplo n.º 3
0
string Utils::get_name_info(const SocketAddress& addr)
{
	auto addrp = reinterpret_cast<const struct sockaddr*>(&addr);
	return get_name_info(addrp);
}