Exemple #1
0
/**
 * Create an instance of the filter for a particular service
 * within MaxScale.
 * 
 * @param options	The options for this filter
 *
 * @return The instance data for this new instance
 */
static	FILTER	*
createInstance(char **options, FILTER_PARAMETER **params)
{
  MQ_INSTANCE	*my_instance;
  int paramcount = 0, parammax = 64, i = 0, x = 0, arrsize = 0;
  FILTER_PARAMETER** paramlist;  
  char** arr;
  char taskname[512];
  
  if ((my_instance = calloc(1, sizeof(MQ_INSTANCE))))
    {
      spinlock_init(&my_instance->rconn_lock);
      spinlock_init(&my_instance->msg_lock);
      uid_gen = 0;
      paramlist = malloc(sizeof(FILTER_PARAMETER*)*64);

      if((my_instance->conn = amqp_new_connection()) == NULL){


	return NULL;
      }
      my_instance->channel = 1;
      my_instance->last_rconn = time(NULL);
      my_instance->conn_stat = AMQP_STATUS_OK;
      my_instance->rconn_intv = 1;
      my_instance->port = 5672;
      my_instance->trgtype = TRG_ALL;
      my_instance->log_all = false;
      my_instance->strict_logging = true;

      for(i = 0;params[i];i++){
	if(!strcmp(params[i]->name,"hostname")){
	  my_instance->hostname = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"username")){
	  my_instance->username = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"password")){
	  my_instance->password = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"vhost")){
	  my_instance->vhost = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"port")){
	  my_instance->port = atoi(params[i]->value);
	}else if(!strcmp(params[i]->name,"exchange")){
	  my_instance->exchange = strdup(params[i]->value);  
	}else if(!strcmp(params[i]->name,"key")){
	  my_instance->key = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"queue")){
	  my_instance->queue = strdup(params[i]->value);
	}
	else if(!strcmp(params[i]->name,"ssl_client_certificate")){

	  my_instance->ssl_client_cert = strdup(params[i]->value);
	
	}else if(!strcmp(params[i]->name,"ssl_client_key")){

	  my_instance->ssl_client_key = strdup(params[i]->value);
	  
	}else if(!strcmp(params[i]->name,"ssl_CA_cert")){

	  my_instance->ssl_CA_cert = strdup(params[i]->value);

	}else if(!strcmp(params[i]->name,"exchange_type")){

	  my_instance->exchange_type = strdup(params[i]->value);

	}else if(!strcmp(params[i]->name,"logging_trigger")){
	  
	  arr = parse_optstr(params[i]->value,",",&arrsize);

	  for(x = 0;x<arrsize;x++){
	    if(!strcmp(arr[x],"source")){
	      my_instance->trgtype |= TRG_SOURCE;
	    }else if(!strcmp(arr[x],"schema")){
	      my_instance->trgtype |= TRG_SCHEMA;
	    }else if(!strcmp(arr[x],"object")){
	      my_instance->trgtype |= TRG_OBJECT;
	    }else if(!strcmp(arr[x],"all")){
	      my_instance->trgtype = TRG_ALL;
	    }else{
	      skygw_log_write(LOGFILE_ERROR,"Error: Unknown option for 'logging_trigger':%s.",arr[x]);
	    }
	  }

	  if(arrsize > 0){
	    free(arr);
	  }
	  arrsize = 0;
	  


	}else if(strstr(params[i]->name,"logging_")){

	  if(paramcount < parammax){
	    paramlist[paramcount] = malloc(sizeof(FILTER_PARAMETER));
	    paramlist[paramcount]->name = strdup(params[i]->name);
	    paramlist[paramcount]->value = strdup(params[i]->value);
	    paramcount++;
	  }	  
	  
	}

      }

      if(my_instance->trgtype & TRG_SOURCE){

        my_instance->src_trg = (SRC_TRIG*)malloc(sizeof(SRC_TRIG));
        my_instance->src_trg->user = NULL;
        my_instance->src_trg->host = NULL;
        my_instance->src_trg->usize = 0;
	my_instance->src_trg->hsize = 0;	

      }

      if(my_instance->trgtype & TRG_SCHEMA){

        my_instance->shm_trg = (SHM_TRIG*)malloc(sizeof(SHM_TRIG));
        my_instance->shm_trg->objects = NULL;
        my_instance->shm_trg->size = 0;

      }

      if(my_instance->trgtype & TRG_OBJECT){

        my_instance->obj_trg = (OBJ_TRIG*)malloc(sizeof(OBJ_TRIG));
        my_instance->obj_trg->objects = NULL;
        my_instance->obj_trg->size = 0;

      }

      for(i = 0;i<paramcount;i++){

	if(!strcmp(paramlist[i]->name,"logging_source_user")){
	    
	  if(my_instance->src_trg){
	    my_instance->src_trg->user = parse_optstr(paramlist[i]->value,",",&arrsize);
	    my_instance->src_trg->usize = arrsize;
	    arrsize = 0;
	  }

	}else if(!strcmp(paramlist[i]->name,"logging_source_host")){
	    
	  if(my_instance->src_trg){
	    my_instance->src_trg->host = parse_optstr(paramlist[i]->value,",",&arrsize);
	    my_instance->src_trg->hsize = arrsize;
	    arrsize = 0;
	  }

	}else if(!strcmp(paramlist[i]->name,"logging_schema")){
	    
	  if(my_instance->shm_trg){
	    my_instance->shm_trg->objects = parse_optstr(paramlist[i]->value,",",&arrsize);
	    my_instance->shm_trg->size = arrsize;
	    arrsize = 0;
	  }

	}else if(!strcmp(paramlist[i]->name,"logging_object")){
	    
	  if(my_instance->obj_trg){
	    my_instance->obj_trg->objects = parse_optstr(paramlist[i]->value,",",&arrsize);
	    my_instance->obj_trg->size = arrsize;
	    arrsize = 0;
	  }

	}else if(!strcmp(paramlist[i]->name,"logging_log_all")){
	  if(config_truth_value(paramlist[i]->value)){
	    my_instance->log_all = true;
	  }
	}else if(!strcmp(paramlist[i]->name,"logging_strict")){
	  if(!config_truth_value(paramlist[i]->value)){
	    my_instance->strict_logging = false;
	  }
	}
	free(paramlist[i]->name);
	free(paramlist[i]->value);
	free(paramlist[i]);
      }

      free(paramlist);
      
      if(my_instance->hostname == NULL){
	my_instance->hostname = strdup("localhost");	
      }
      if(my_instance->username == NULL){
	my_instance->username = strdup("guest");	
      }
      if(my_instance->password == NULL){
	my_instance->password = strdup("guest");	
      }
      if(my_instance->vhost == NULL){
	my_instance->vhost = strdup("/");	
      }
      if(my_instance->exchange == NULL){
	my_instance->exchange = strdup("default_exchange");	
      }
      if(my_instance->key == NULL){
	my_instance->key = strdup("key");
      }
      if(my_instance->exchange_type == NULL){
	my_instance->exchange_type = strdup("direct");
      }

      if(my_instance->ssl_client_cert != NULL &&
	 my_instance->ssl_client_key != NULL &&
	 my_instance->ssl_CA_cert != NULL){
	my_instance->use_ssl = true;
      }else{
	my_instance->use_ssl = false;
      }
      
      if(my_instance->use_ssl){
	amqp_set_initialize_ssl_library(0);/**Assume the underlying SSL library is already initialized*/
      }
      
      /**Connect to the server*/
      init_conn(my_instance);

      snprintf(taskname,511,"mqtask%d",atomic_add(&hktask_id,1));
      hktask_add(taskname,sendMessage,(void*)my_instance,5);

    }
  return (FILTER *)my_instance;
}
Exemple #2
0
/**
 * Create an instance of the filter for a particular service
 * within MaxScale.
 * 
 * @param options	The options for this filter
 *
 * @return The instance data for this new instance
 */
static	FILTER	*
createInstance(char **options, FILTER_PARAMETER **params)
{
  MQ_INSTANCE	*my_instance;
  
  if ((my_instance = calloc(1, sizeof(MQ_INSTANCE)))&& 
      (my_instance->rconn_lock = malloc(sizeof(SPINLOCK))))
    {
      spinlock_init(my_instance->rconn_lock);
      uid_gen = 0;
      my_instance->channel = 1;
      my_instance->last_rconn = time(NULL);
      my_instance->conn_stat = AMQP_STATUS_OK;
      my_instance->rconn_intv = 1;
      my_instance->port = 5672;

      int i;
      for(i = 0;params[i];i++){
	if(!strcmp(params[i]->name,"hostname")){
	  my_instance->hostname = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"username")){
	  my_instance->username = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"password")){
	  my_instance->password = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"vhost")){
	  my_instance->vhost = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"port")){
	  my_instance->port = atoi(params[i]->value);
	}else if(!strcmp(params[i]->name,"exchange")){
	  my_instance->exchange = strdup(params[i]->value);  
	}else if(!strcmp(params[i]->name,"key")){
	  my_instance->key = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"queue")){
	  my_instance->queue = strdup(params[i]->value);
	}
	else if(!strcmp(params[i]->name,"ssl_client_certificate")){
	  my_instance->ssl_client_cert = strdup(params[i]->value);
	}
	else if(!strcmp(params[i]->name,"ssl_client_key")){
	  my_instance->ssl_client_key = strdup(params[i]->value);
	}
	else if(!strcmp(params[i]->name,"ssl_CA_cert")){
	  my_instance->ssl_CA_cert = strdup(params[i]->value);
	}else if(!strcmp(params[i]->name,"exchange_type")){
	  my_instance->exchange_type = strdup(params[i]->value);
	}
      }
      
      if(my_instance->hostname == NULL){
	my_instance->hostname = strdup("localhost");	
      }
      if(my_instance->username == NULL){
	my_instance->username = strdup("guest");	
      }
      if(my_instance->password == NULL){
	my_instance->password = strdup("guest");	
      }
      if(my_instance->vhost == NULL){
	my_instance->vhost = strdup("/");	
      }
      if(my_instance->exchange == NULL){
	my_instance->exchange = strdup("default_exchange");	
      }
      if(my_instance->key == NULL){
	my_instance->key = strdup("key");
      }
      if(my_instance->exchange_type == NULL){
	my_instance->exchange_type = strdup("direct");
      }

      if(my_instance->ssl_client_cert != NULL &&
	 my_instance->ssl_client_key != NULL &&
	 my_instance->ssl_CA_cert != NULL){
	my_instance->use_ssl = 1;
      }
      
      if(my_instance->use_ssl){
	amqp_set_initialize_ssl_library(0);/**Assume the underlying SSL library is already initialized*/
      }

    }
  return (FILTER *)my_instance;
}