Example #1
0
static int filter_recurse(struct snapraid_filter* filter, struct snapraid_filter** reason, const char* const_path, int is_dir)
{
	char path[PATH_MAX];
	char* name;
	unsigned i;

	pathcpy(path, sizeof(path), const_path);

	/* filter for all the directories */
	name = path;
	for (i = 0; path[i] != 0; ++i) {
		if (path[i] == '/') {
			/* set a terminator */
			path[i] = 0;

			/* filter the directory */
			if (filter_apply(filter, reason, path, name, 1) != 0)
				return filter->direction;

			/* restore the slash */
			path[i] = '/';

			/* next name */
			name = path + i + 1;
		}
	}

	/* filter the final file */
	if (filter_apply(filter, reason, path, name, is_dir) != 0)
		return filter->direction;

	return 0;
}
Example #2
0
int INTERPOSE(socket)(int domain, int type, int protocol)
{
    __real_socket_init();
    const bool bypass_filter = getenv("SIXJACK_BYPASS") != NULL;
    int ret = 0;
    int ret_errno = 0;    
    bool bypass_call = false;
    FilterReplyResultBase rb = {
        .pre = true, .ret = &ret, .ret_errno = &ret_errno, .fd = -1
    };
    if (bypass_filter == false && (rb.filter = filter_get()) &&
        filter_apply(&rb, &domain, &type, &protocol)
        == FILTER_REPLY_BYPASS) {
        bypass_call = true;
    }
    if (bypass_call == false) {
        ret = __real_socket(domain, type, protocol);
        ret_errno = errno;
    }
    if (bypass_filter == false) {
        rb.fd = ret;
        rb.pre = false;
        filter_apply(&rb, &domain, &type, &protocol);
    }
    errno = ret_errno;
    
    return ret;
}
bool Layer_list_model::import_from_bundle(Bundle& bundle) {
	unsigned n = bundle.size();
	for (unsigned i = 0; i < n && i < layers.size(); i++) {
		unsigned layer_index = 0;
		QString layer_name = bundle.layer_name(i);
		QByteArray layer_state = bundle.layer_state(i);
		while (layer_index < layers.size() && layer_name != layers[layer_index]->get_name()) {
			layer_index++;
		}
		if (layer_index==layers.size()) continue;
		swap_in_layers(i, layer_index);
#ifdef INVALIDATE_CACHE_AT_COLOR_CHANGE
		layers[i]->invalidate_cache();/// \todo why do I need this for colors? it should work without invalidating with the display lists
#endif
		layers[i]->restoreState(bundle.layer_state(i));
	}
	// deactivate 
	for (unsigned i=0; i < layers.size(); i++) {
		bool found = false;
		QString name_from_layers = layers[i]->get_name();
		for (int j=0; j<bundle.size(); j++)
			if (name_from_layers == bundle.layer_name(j)) found = true;
		if (!found) layers[i]->set_active(false);
	}
	filter_apply(filter_text, show_only_active);
	emit dataChanged(QModelIndex(), QModelIndex());
	emit layers_reordered();
	return true;
}
Example #4
0
ssize_t INTERPOSE(recvmsg)(int fd, struct msghdr *msg, int flags)
{
    __real_recvmsg_init();
    const bool bypass_filter =
        getenv("SIXJACK_BYPASS") != NULL || is_socket(fd) == false;        
    struct sockaddr_storage sa_local, *sa_local_ = &sa_local;
    socklen_t sa_local_len;
    get_sock_info(fd, &sa_local_, &sa_local_len, NULL, NULL);
    int ret = 0;
    int ret_errno = 0;    
    bool bypass_call = false;
    size_t nbyte = (size_t) 0U;
    struct iovec * const vecs = msg->msg_iov;
    size_t i_vecs = 0U;
    while (i_vecs < (size_t) msg->msg_iovlen) {
        assert(SIZE_MAX - nbyte >= vecs[i_vecs].iov_len);
        nbyte += vecs[i_vecs].iov_len;
        i_vecs++;
    }
    size_t new_nbyte = nbyte;
    FilterReplyResultBase rb = {
        .pre = true, .ret = &ret, .ret_errno = &ret_errno, .fd = fd
    };
    if (bypass_filter == false && (rb.filter = filter_get()) &&
        filter_apply(&rb, sa_local_, sa_local_len, msg,
                     &new_nbyte, &flags)
        == FILTER_REPLY_BYPASS) {
        bypass_call = true;
    }
    if (bypass_call == false) {
        ssize_t ret_ = __real_recvmsg(fd, msg, flags);
        ret_errno = errno;
        ret = (int) ret_;
        assert((ssize_t) ret_ == ret);
    }
    if (bypass_filter == false) {
        new_nbyte = ret;
        rb.pre = false;
        filter_apply(&rb, sa_local_, sa_local_len, msg,
                     &new_nbyte, &flags);
    }
    errno = ret_errno;
    
    return ret;
}
Example #5
0
int
main(int argc, char* argv[])
{
	try {
		const toptions& options = toptions::parse(argc, argv);

		surface surf(make_neutral_surface(
				IMG_Load(options.input_filename.c_str())));

		if(!surf) {
			std::cerr << "Error: Failed to load input file »"
					<< options.input_filename
					<< "«.\n";

			return EXIT_FAILURE;
		}

		std::vector<surface> surfaces;
		if(options.count != 1) {
			for(int i = 1; i < options.count; ++i) {
				// make_neutral_surface make a deep-copy of the image.
				surfaces.push_back(make_neutral_surface(surf));
			}
		}
		surfaces.push_back(surf);

		const clock_t begin = options.time ? get_begin_time() : 0;

		for(int i = 0; i < options.count; ++i) {
			BOOST_FOREACH(const std::string& filter, options.filters) {
				filter_apply(surfaces[i], filter);
			}
		}

		if(options.time) {
			const clock_t end = std::clock();
			std::cout << "Applying the filters took "
					<<  end - begin
					<< " ticks, "
					<< static_cast<double>(end - begin) / CLOCKS_PER_SEC
					<< " seconds.\n";
		}

		if(!options.output_filename.empty()) {
			save_image(surfaces[0], options.output_filename);
		}

	} catch(const texit& exit) {
		return exit.status;
	} catch(exploder_failure& err) {
		std::cerr << "Error: Failed with error »" << err.message << "«.\n";
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
Example #6
0
ssize_t INTERPOSE(read)(int fd, void *buf, size_t nbyte)
{
    __real_read_init();
    const bool bypass_filter =
        getenv("SIXJACK_BYPASS") != NULL || is_socket(fd) == false;
    struct sockaddr_storage sa_local, *sa_local_ = &sa_local;
    struct sockaddr_storage sa_remote, *sa_remote_ = &sa_remote;
    socklen_t sa_local_len, sa_remote_len;
    get_sock_info(fd, &sa_local_, &sa_local_len, &sa_remote_, &sa_remote_len);
    int ret = 0;
    int ret_errno = 0;    
    bool bypass_call = false;
    size_t new_nbyte = nbyte;
    FilterReplyResultBase rb = {
        .pre = true, .ret = &ret, .ret_errno = &ret_errno, .fd = fd
    };    
    if (bypass_filter == false && (rb.filter = filter_get()) &&
        filter_apply(&rb, sa_local_, sa_local_len,
                     sa_remote_, sa_remote_len, NULL, &new_nbyte)
        == FILTER_REPLY_BYPASS) {
        bypass_call = true;
    }
    if (bypass_call == false) {
        ssize_t ret_ = __real_read(fd, buf, new_nbyte);
        ret_errno = errno;        
        ret = (int) ret_;
        assert((ssize_t) ret_ == ret);
    }
    if (bypass_filter == false) {
        rb.pre = false;
        filter_apply(&rb, sa_local_, sa_local_len,
                     sa_remote_, sa_remote_len, buf, &new_nbyte);
    }
    errno = ret_errno;
    
    return ret;
}
Example #7
0
int
filter_test_channel(const mdf_t *const mdf,
                    const filter_t *const filter,
                    const cn_block_t *const cn_block)
{
  uint32_t can_id, can_channel;
  ce_block_t *ce_block;
  char *message;
  char *signal_name = cn_get_long_name(mdf, cn_block);
  int test;

  /* message info */
  ce_block = ce_block_get(mdf, cn_block->link_extensions);
  ce_get_message_info(ce_block, &message, &can_id, &can_channel);
  
  test = (filter_apply(filter, can_channel, message, signal_name) != NULL);

  free(message);
  free(signal_name);
  return test;
}
Example #8
0
void hf_commit_creation (gpointer data) {
//	Commit the filter
	filter_dialog_struct *fds;
	hf_wrapper_struct *hfw;
	hfw = (hf_wrapper_struct *) data;
//	printf("HFW, HFW->creation_mode in hf_commit_creation: %d, %d\n",data,hfw->creation_mode);
// printf("HFW->window->window: %d->%d\n",hfw->window,hfw->window->window);
	hfw->creation_mode = FALSE;  // Supposed to be done in hf_wrapper_copy...
//	hfw->hf_options->current_calculation = NULL;
	hfw->apply_filter = FALSE;

//	Backup the filter definition and nullify it - we 1st commit the HF without the filter
	if (hfw->hf_options->fd_struct) {
		set_filter_defaults (hfw->hf_options->fd_struct);
	}
	
	record_action(hfw, hfw->hf_options->last_creation_action);
	if (hfw->hf_options->fd_struct) {
		fds = hfw->hf_options->fd_struct;
		if (fds->current_filter) {
		    filter_apply(hfw->hf_struct,
			fds->current_filter,
			hfw->hf_options->dist_matrix,
			fds->revert_filter,
			fds->filter_level,
			fds->merge_oper);
//	Now we commit the HF with the filter
		record_action(hfw,_("Shape filter"));

		}
	}
//	If we are in the shape filter subdialog in the tools dialog:
	if (hfw->hf_options->img)
		hfw->hf_options->fd_struct = hfw->hf_options->img->fd_struct;
	else
		hfw->hf_options->fd_struct = NULL;

//	"expose_event" seems required to display the cursor ?
	emit_expose_event(hfw->area);
}
bool Layer_list_model::dropMimeData(const QMimeData *data, Qt::DropAction action,
	int row, int column, const QModelIndex &parent) {

	if (action == Qt::IgnoreAction)
		return true;

	if (!data->hasFormat("application/mesecina.layer"))
		return false;

	if (column > 0)
		return false;

	unsigned beginRow; 
	// adapt so that this beginRow is refering to the layer's beginRow although comes originally from the filtered_layers
	// and then the drag and drop works with filtering, as well.

	if (row != -1)
		beginRow = row;
	else if (parent.isValid())
		beginRow = parent.row();
	else
		beginRow = rowCount(QModelIndex());

	QByteArray encodedData = data->data("application/mesecina.layer");
	QDataStream stream(&encodedData, QIODevice::ReadOnly);

	unsigned idx;
	stream >> idx;
	if (idx<beginRow && row == -1 && parent.isValid()) beginRow++;

	QString this_name = filtered_layers[idx]->get_name();

	for (unsigned i=0; i<layers.size(); i++) {
		if (layers[i]->get_name()== this_name) {
			idx = i;
			i = static_cast<int>(layers.size());
		}
	}

	if (beginRow < filtered_layers.size()) {
		QString this_name = filtered_layers[beginRow]->get_name();
		for (unsigned i=0; i<layers.size(); i++) {
			if (layers[i]->get_name()== this_name) {
				beginRow = i;
				i = static_cast<int>(layers.size());
			}
		}
	} else {
		beginRow = static_cast<int>(layers.size());
	}
	
	unsigned i;	std::vector<Managable_layer*>::iterator l_it = layers.begin();
	for (i=0; i != beginRow; l_it++, i++);
	layers.insert(l_it, layers[idx]);

	if (i<idx) idx++;
	l_it = layers.begin();
	for (i=0; i != idx; l_it++, i++);
	layers.erase(l_it);

	emit layers_reordered();
	filter_apply(filter_text, show_only_active);

	return true;
}
void Statistics_table_model::process_filter() {
	filter_apply(filter_text);
}
Example #11
0
static void
mat_write_signal(const mdf_t *const mdf, 
                 const uint32_t can_channel,
                 const uint32_t number_of_records,
                 const uint16_t channel_type,
                 const char *const message_name,
                 const char *const signal_name,
                 const double *const timeValue,
                 const filter_t *const filter,
                 const void *const cbData)
{
  char *filter_signal_name_in;
  char *filter_message_name_in;
  char *filter_name_out;
  size_t dims[2];
  mdftomat_t *const mdftomat = (mdftomat_t *)cbData;

  dims[0] = number_of_records;
  dims[1] = 2;

  if(   ((can_channel != 0) && (channel_type == 0)) /* Vector CAN */
     || ((can_channel == 0) && (channel_type == 0)) /* DIM */ ) {
    if(mdf->verbose_level >= 2) {
       uint32_t ir;
       printf("ch=%lu n=%lu m=%s s=%s\n",
              (unsigned long)can_channel,
              (unsigned long)number_of_records,
              message_name,
              signal_name);
      if(mdf->verbose_level >= 3) {
       for(ir=0;ir<number_of_records;ir++) {
          printf("%g %g\n",timeValue[ir],timeValue[ir+number_of_records]);
       }
      }
    }
    /* sanitize variable name */
    filter_signal_name_in = sanitize_name(signal_name);
    filter_message_name_in = sanitize_name(message_name);
    filter_name_out = filter_apply(filter, can_channel,
                                   filter_message_name_in,
                                   filter_signal_name_in);
    if(mdf->verbose_level >= 2) {
      printf("    CNBLOCK can_ch=%lu\n"
             "            message      = %s\n"
             "            signal_name  = %s\n"
             "            filter_input = %s\n"
             "            filter_output= %s\n",
             (unsigned long)can_channel, filter_message_name_in,
             signal_name, filter_signal_name_in,
             (filter_name_out!=NULL)?filter_name_out:"<rejected by filter>" );
      if(filter_name_out != NULL) {
        printf("+ %d %s %s %s\n",
               can_channel,
               filter_message_name_in,
               filter_signal_name_in,
               filter_name_out );
      }
    }
    free(filter_signal_name_in);
    free(filter_message_name_in);

    if(filter_name_out != NULL) {
      matvar_t *matvar;
      int rv;

      /* write matlab variable */
      matvar = Mat_VarCreate(filter_name_out, MAT_C_DOUBLE, MAT_T_DOUBLE,
                             2, dims, (double *)timeValue, 0);
      rv = Mat_VarWrite(mdftomat->mat, matvar, mdftomat->compress);
      assert(rv == 0);
      Mat_VarFree(matvar);
      free(filter_name_out);
    }
  }
}
Example #12
0
/**
 * Advertise a route to a given peer:
 *
 *   - do not redistribute a route learned through iBGP to an
 *     iBGP peer BUT in this case, redistribute the best eBGP route
 *
 *   !! THE ABOVE RULE SHOULD BE MOVED BEFORE INSERTION IN ADJ-RIB-OUT !!
 *
 *   - avoid sending to originator peer
 *   - avoid sending to a peer in AS-Path (SSLD)
 *   - check standard communities (NO_ADVERTISE and NO_EXPORT)
 *   - apply redistribution communities
 *   - strip non-transitive extended communities
 *   - update Next-Hop (next-hop-self)
 *   - prepend AS-Path (if redistribution to an external peer)
 */
int qos_advertise_to_peer(SBGPRouter * pRouter, SPeer * pPeer, SRoute * pRoute)
{
  SRoute * pNewRoute= NULL;
  int iExternalSession= (pRouter->uNumber != pPeer->uRemoteAS);

  AS_LOG_DEBUG(pRouter, " > qos_advertise_peer\n");

  // If this route was learned through an iBGP session, do not
  // redistribute it to an internal peer
  if ((route_peer_get(pRoute)->uRemoteAS == pRouter->uNumber) &&
      (!iExternalSession))
    return -1;

  // Do not redistribute to peer that has announced this route
  if (pPeer->tAddr == pRoute->tNextHop)
     return -1;

  // Avoid loop creation (SSLD, Sender-Side Loop Detection)
  if ((iExternalSession) &&
      (route_path_contains(pRoute, pPeer->uRemoteAS)))
    return -1;

  // Do not redistribute to other peers
  if (route_comm_contains(pRoute, COMM_NO_ADVERTISE))
    return -1;

  // Do not redistribute outside confederation (here AS)
  if ((iExternalSession) &&
      (route_comm_contains(pRoute, COMM_NO_EXPORT)))
    return -1;

  // Copy the route. This is required since the call to
  // as_ecomm_red_process can alter the route's attribute !!
  route_copy_count++;
  pNewRoute= route_copy(pRoute);

  // Check output filter and redistribution communities
  if (as_ecomm_red_process(pPeer, pNewRoute)) {

    route_ecomm_strip_non_transitive(pNewRoute);

    if (filter_apply(pPeer->pOutFilter, pRouter, pNewRoute)) {

      // The route's next-hop is this router (next-hop-self)
      route_nexthop_set(pNewRoute, pRouter->pNode->tAddr);

      // Append AS-Number if exteral peer (eBGP session)
      if (iExternalSession)
	route_path_append(pNewRoute, pRouter->uNumber);
      
      LOG_DEBUG("*** AS%d advertise to AS%d ***\n",
		pRouter->uNumber, pPeer->uRemoteAS);

      peer_announce_route(pPeer, pNewRoute);
      return 0;
    }
  }

  route_destroy_count++;
  route_destroy(&pNewRoute);

  return -1;
}