Exemplo n.º 1
0
int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx,
                                                  AVFrame *frame, int nb_samples)
{
    BufferSinkContext *s = ctx->priv;
    AVFilterLink   *link = ctx->inputs[0];
    AVFrame *cur_frame;
    int ret = 0;
#ifdef IDE_COMPILE
	AVRational tmp;
#endif

    if (!s->audio_fifo) {
        int nb_channels = link->channels;
        if (!(s->audio_fifo = av_audio_fifo_alloc(link->format, nb_channels, nb_samples)))
            return AVERROR(ENOMEM);
    }

    while (ret >= 0) {
        if (av_audio_fifo_size(s->audio_fifo) >= nb_samples)
            return read_from_fifo(ctx, frame, nb_samples);

        if (!(cur_frame = av_frame_alloc()))
            return AVERROR(ENOMEM);
        ret = av_buffersink_get_frame_flags(ctx, cur_frame, 0);
        if (ret == AVERROR_EOF && av_audio_fifo_size(s->audio_fifo)) {
            av_frame_free(&cur_frame);
            return read_from_fifo(ctx, frame, av_audio_fifo_size(s->audio_fifo));
        } else if (ret < 0) {
            av_frame_free(&cur_frame);
            return ret;
        }

        if (cur_frame->pts != AV_NOPTS_VALUE) {
#ifdef IDE_COMPILE
			tmp.num = 1;
			tmp.den = link->sample_rate;
			s->next_pts = cur_frame->pts -
                          av_rescale_q(av_audio_fifo_size(s->audio_fifo),
                                       tmp, link->time_base);
#else
			s->next_pts = cur_frame->pts -
                          av_rescale_q(av_audio_fifo_size(s->audio_fifo),
                                       (AVRational){ 1, link->sample_rate },
                                       link->time_base);
#endif
		}

        ret = av_audio_fifo_write(s->audio_fifo, (void**)cur_frame->extended_data,
                                  cur_frame->nb_samples);
        av_frame_free(&cur_frame);
    }

    return ret;
}
Exemplo n.º 2
0
int fork_drop_and_exec(int keepperms, cap_t expected_caps)
{

	int pid;
	int ret = 0;
	char buf[200], *p;
	char *capstxt;
	cap_t actual_caps;
	static int seqno;

	pid = fork();
	if (pid < 0)
		tst_brkm(TFAIL | TERRNO, NULL, "%s: failed fork\n", __func__);
	if (pid == 0) {
		drop_root(keepperms);
		print_my_caps();
		sprintf(buf, "%d", seqno);
		ret = execlp(TSTPATH, TSTPATH, buf, NULL);
		capstxt = cap_to_text(expected_caps, NULL);
		snprintf(buf, 200, "failed to run as %s\n", capstxt);
		cap_free(capstxt);
		write_to_fifo(buf);
		tst_brkm(TFAIL, NULL, "%s: exec failed\n", __func__);
	} else {
		p = buf;
		while (1) {
			int c, s;
			read_from_fifo(buf);
			c = sscanf(buf, "%d", &s);
			if (c == 1 && s == seqno)
				break;
			tst_resm(TINFO,
				 "got a bad seqno (c=%d, s=%d, seqno=%d)", c, s,
				 seqno);
		}
		p = index(buf, '.');
		if (!p)
			tst_brkm(TFAIL, NULL,
				 "got a bad message from print_caps\n");
		p += 1;
		actual_caps = cap_from_text(p);
		if (cap_compare(actual_caps, expected_caps) != 0) {
			capstxt = cap_to_text(expected_caps, NULL);
			tst_resm(TINFO,
				 "Expected to run as .%s., ran as .%s..\n",
				 capstxt, p);
			tst_resm(TINFO, "those are not the same\n");
			cap_free(capstxt);
			ret = -1;
		}
		cap_free(actual_caps);
		seqno++;
	}
	return ret;
}
Exemplo n.º 3
0
int readSystemInput(char fifoFilename[]) {
		  int fd;
		  fd = open(fifoFilename, O_RDONLY);
		  while(sentinel == 1) {
	    	read_from_fifo(fd, var);
	    	printf("var: %s\n", var);
	    }
	    close(fd);
	    exit(0);
	    return 0;
}
Exemplo n.º 4
0
int av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **pbuf,
                               int nb_samples)
{
    BufferSinkContext *s = ctx->priv;
    AVFilterLink   *link = ctx->inputs[0];
    int ret = 0;

    if (!s->audio_fifo) {
        int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
        if (!(s->audio_fifo = av_audio_fifo_alloc(link->format, nb_channels, nb_samples)))
            return AVERROR(ENOMEM);
    }

    while (ret >= 0) {
        AVFilterBufferRef *buf;

        if (av_audio_fifo_size(s->audio_fifo) >= nb_samples)
            return read_from_fifo(ctx, pbuf, nb_samples);

        ret = av_buffersink_read(ctx, &buf);
        if (ret == AVERROR_EOF && av_audio_fifo_size(s->audio_fifo))
            return read_from_fifo(ctx, pbuf, av_audio_fifo_size(s->audio_fifo));
        else if (ret < 0)
            return ret;

        if (buf->pts != AV_NOPTS_VALUE) {
            s->next_pts = buf->pts -
                          av_rescale_q(av_audio_fifo_size(s->audio_fifo),
                                       (AVRational){ 1, link->sample_rate },
                                       link->time_base);
        }

        ret = av_audio_fifo_write(s->audio_fifo, (void**)buf->extended_data,
                                  buf->audio->nb_samples);
        avfilter_unref_buffer(buf);
    }

    return ret;
}
Exemplo n.º 5
0
int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx,
                                                  AVFrame *frame, int nb_samples)
{
    BufferSinkContext *s = ctx->priv;
    AVFilterLink   *link = ctx->inputs[0];
    int ret = 0;

    if (!s->audio_fifo) {
        int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
        if (!(s->audio_fifo = av_audio_fifo_alloc(link->format, nb_channels, nb_samples)))
            return AVERROR(ENOMEM);
    }

    while (ret >= 0) {
        if (av_audio_fifo_size(s->audio_fifo) >= nb_samples)
            return read_from_fifo(ctx, frame, nb_samples);

        ret = ff_request_frame(link);
        if (ret == AVERROR_EOF && av_audio_fifo_size(s->audio_fifo))
            return read_from_fifo(ctx, frame, av_audio_fifo_size(s->audio_fifo));
        else if (ret < 0)
            return ret;

        if (s->cur_frame->pts != AV_NOPTS_VALUE) {
            s->next_pts = s->cur_frame->pts -
                          av_rescale_q(av_audio_fifo_size(s->audio_fifo),
                                       (AVRational){ 1, link->sample_rate },
                                       link->time_base);
        }

        ret = av_audio_fifo_write(s->audio_fifo, (void**)s->cur_frame->extended_data,
                                  s->cur_frame->nb_samples);
        av_frame_free(&s->cur_frame);
    }

    return ret;
}
Exemplo n.º 6
0
int main(int argc, char** argv){
	if (argc != 2) {
		printf(ARGS_ERROR);
		return -1;
	}

	int fd;
	struct stat st;
	struct sigaction old_act; 
	struct sigaction act;
	act.sa_handler = SIG_IGN; //ignore the signal
	act.sa_flags = 0;
	if (sigemptyset(&act.sa_mask) == -1){ 
		printf(SIG_ERROR, "signals", strerror(errno));
		return -1;
	}

	while (1){
		while ((stat(argv[1], &st) == -1) && (errno == ENOENT)) sleep(1);
		if (stat(argv[1], &st) == -1){ // path exist, other error occurred 
			printf(ARG_ERROR, argv[1], strerror(errno));
			return -1;
		}
		if (!S_ISFIFO(st.st_mode)){ // It isn't fifo file
			printf(FIFO_ERROR, argv[1]);
			return -1;
		}
		fd = open(argv[1], O_RDONLY);
		if (fd == -1){
			printf(FUNC_ERROR, "open", strerror(errno));
			return -1;
		}
		if (replace_acts(&act, &old_act) == -1){
			close(fd);
			return -1;
		}
		if (read_from_fifo(fd) == -1){
			close(fd);
			return -1;
		}
		close(fd);
		if (replace_acts(&old_act, &act) == -1) return -1;
	}
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
    struct stat st;
    main_fifo_msg_t server_data;
    int counter;
    
    if (signal(SIGINT, sig_handler) == SIG_ERR);
    
    if(argc != 2){
		printf("You should give 2 parameters!\n");
		printf("Example usage: ./server [FIFO_NAME]\n");
		exit(0);
	} else {
		fifo_name1 = (char*)malloc(sizeof(char) * strlen(argv[1]) + 1);
		strcpy(fifo_name1, argv[1]);
	}
	printf("FIFO_NAME: %s\n", fifo_name1);

	fifo_id = open(fifo_name1, O_RDONLY);
    
    // if no fifos, create them
    if (stat(fifo_name1, &st) != 0)
        mkfifo(fifo_name1, 0666);
        
    //while'ı çek buraya
    while(1){
        sleep(5);
		read_from_fifo(fifo_id, &server_data);
	}
	
	// delete fifos
    unlink(fifo_name1);

    printf("server exit successfully\n");
    return EXIT_SUCCESS;
}  
Exemplo n.º 8
0
int proxy_server()
{
    int rx_bytes = 0, post_data_size = 0;
    int lsock = 0, csock = 0, client_data_size = 0;
    int result_size = 0, err_code = 0, id = 0;
    int addrlen = sizeof(struct sockaddr_in);
    struct sockaddr_in clientaddr;
    char *buffer = NULL, *post_data = NULL;
    char *host = NULL, *url = NULL;
    char *query = NULL, *fifo_file = NULL;
    char *get_data = NULL;
    char *client_data = NULL, *headers = NULL;
    char *server_ip = NULL;

    memset((void *) &clientaddr,0,addrlen);

    server_ip = config_get_server_ip();

    /* Create TCP socket */
    if((lsock = create_socket(server_ip,PROXY_PORT,SOCK_STREAM)) == SOCK_FAIL) {
        glog("Failed to create TCP socket for proxy server",LOG_ERROR_TYPE);
        if(server_ip) free(server_ip);
        return EXIT_FAILURE;
    }
    if(server_ip) free(server_ip);

    /* Infinite receive loop */
    while(1) {

        /* Accept incoming connection */
        if((csock = accept(lsock,(struct sockaddr *) &clientaddr,(socklen_t *) &addrlen)) < 0) {
            glog("Failed to accept TCP connection to proxy server",LOG_ERROR_TYPE);
            if(buffer) free(buffer);
            return EXIT_FAILURE;
        }

        if(!fork()) {
            /* Receive client request */
            if((buffer = receive(lsock,SOCK_STREAM,&rx_bytes,csock,&clientaddr)) == NULL) {
                glog("Failed to read data from client request sent to proxy server",LOG_ERROR_TYPE);
                exit(EXIT_FAILURE);
            }

            if(is_using_proxy(buffer)) {

                /* Get the target's IP address */
                host = get_host_name(buffer);

                /* Get the target URL path */
                url = get_url(buffer);

                /* Get POST data, if any */
                post_data = get_post_data(buffer,rx_bytes,&post_data_size);

                /* Get HTTP headers from request */
                headers = get_headers(buffer);

                /* If the CONSOLE_HOST is requested, then display the Web console interface */
                if(memcmp(host,CONSOLE_HOST,CONSOLE_HOST_SIZE) == 0) {
                    show_web_ui(csock,url);
                    close_socket(csock);
                } else {

                    /* Make sure the requested host is in our clients list */
                    query = sqlite3_mprintf("SELECT id FROM %s WHERE strftime('%%s',callback_time) >= strftime('%%s','now') AND ip = %Q LIMIT 1",CLIENTS_TABLE,host);
                    sql_exec(query,&result_size,&err_code);
                    sqlite3_free(query);

                    if(result_size > 0) {
                        /* Don't allow requests for filtered file extensions */
                        if(!is_url_filtered(url)) {

                            fifo_file = create_fifo(host);
                            if(!fifo_file) {
                                glog("Failed to create fifo file",LOG_ERROR_TYPE);
                            } else {
                                /* Insert query into queue table */
                                query = sqlite3_mprintf("INSERT INTO %s (fifo,host,url,headers,pdata,sent) VALUES (%Q,%Q,%Q,%Q,%Q,0)",QUEUE_TABLE,fifo_file,host,url,headers,post_data);
                                sql_exec(query,&result_size,&err_code);
                                sqlite3_free(query);
                                if(err_code != SQLITE_OK) {
                                    sql_log_error();
                                } else {

                                    /* When the client data has returned, the callback server will write the ID of the callback to the FIFO */
                                    id = read_from_fifo(fifo_file);

                                    /* Extract the data from the DB */
                                    get_data = sqlite3_mprintf("SELECT rdata FROM %s WHERE id = '%d'",QUEUE_TABLE,id);
                                    client_data = sql_exec(get_data,&client_data_size,&err_code);
                                    sqlite3_free(get_data);

                                    if(err_code != SQLITE_OK) {
                                        sql_log_error();
                                    } else {

                                        /* Write data to socket */
                                        if(write(csock,client_data,client_data_size) != client_data_size) {
                                            glog("Proxy socket write failed",LOG_ERROR_TYPE);
                                        }
                                    }
                                    if(client_data) free(client_data);

                                    /* Make sure the fifo gets deleted */
                                    destroy_fifo(fifo_file);
                                }
                            }
                        }
                    }
                }
            }

            /* Exit the child process */
            close_socket(csock);
            if(fifo_file) free(fifo_file);
            if(buffer) free(buffer);
            if(host) free(host);
            if(url) free(url);
            if(post_data) free(post_data);
            if(headers) free(headers);
            exit(EXIT_SUCCESS);
        }
    }

    /* Close up shop */
    close_socket(csock);
    close_socket(lsock);

    return EXIT_FAILURE;
}
Exemplo n.º 9
0
void server::handle_read_from_fifo(const boost::system::error_code& error, std::size_t)
{
	if(error) {
		if(error == boost::asio::error::operation_aborted)
			// This means fifo was closed by load_config() to open another fifo
			return;
		ERR_CS << "Error reading from fifo: " << error.message() << '\n';
		return;
	}

	std::istream is(&admin_cmd_);
	std::string cmd;
	std::getline(is, cmd);

	const control_line ctl = cmd;

	if(ctl == "shut_down") {
		LOG_CS << "Shut down requested by admin, shutting down...\n";
		throw server_shutdown("Shut down via fifo command");
	} else if(ctl == "readonly") {
		if(ctl.args_count()) {
			cfg_["read_only"] = read_only_ = utils::string_bool(ctl[1], true);
		}

		LOG_CS << "Read only mode: " << (read_only_ ? "enabled" : "disabled") << '\n';
	} else if(ctl == "flush") {
		LOG_CS << "Flushing config to disk...\n";
		write_config();
	} else if(ctl == "reload") {
		if(ctl.args_count()) {
			if(ctl[1] == "blacklist") {
				LOG_CS << "Reloading blacklist...\n";
				load_blacklist();
			} else {
				ERR_CS << "Unrecognized admin reload argument: " << ctl[1] << '\n';
			}
		} else {
			LOG_CS << "Reloading all configuration...\n";
			load_config();
			LOG_CS << "Reloaded configuration\n";
		}
	} else if(ctl == "setpass") {
		if(ctl.args_count() != 2) {
			ERR_CS << "Incorrect number of arguments for 'setpass'\n";
		} else {
			const std::string& addon_id = ctl[1];
			const std::string& newpass = ctl[2];
			config& campaign = get_campaign(addon_id);

			if(!campaign) {
				ERR_CS << "Add-on '" << addon_id << "' not found, cannot set passphrase\n";
			} else if(newpass.empty()) {
				// Shouldn't happen!
				ERR_CS << "Add-on passphrases may not be empty!\n";
			} else {
				set_passphrase(campaign, newpass);
				write_config();
				LOG_CS << "New passphrase set for '" << addon_id << "'\n";
			}
		}
	} else {
		ERR_CS << "Unrecognized admin command: " << ctl.full() << '\n';
	}

	read_from_fifo();
}