Exemplo n.º 1
0
static int parse_siit_json(cJSON *json)
{
	bool global_found = false;
	bool pool6_found = false;
	bool eamt_found = false;
	bool blacklist_found = false;
	bool pool6791_found = false;
	bool *globals_found;
	int error;

	error = send_ctrl_msg(SEC_INIT);
	if (error)
		return error;

	globals_found = create_globals_found_array();
	if (!globals_found) {
		log_err("Out of memory.");
		return -ENOMEM;
	}

	for (json = json->child; json; json = json->next) {
		if (strcasecmp("global", json->string) == 0) {
			check_duplicates(&global_found, "global");
			error = handle_global(json, globals_found);
		} else if (strcasecmp("pool6", json->string) == 0) {
			check_duplicates(&pool6_found, "pool6");
			error = handle_pool6(json);
		} else if (strcasecmp("eamt", json->string) == 0) {
			check_duplicates(&eamt_found, "eamt");
			error = handle_eamt(json);
		} else if (strcasecmp("blacklist", json->string) == 0) {
			check_duplicates(&blacklist_found, "blacklist");
			error = handle_addr4_pool(json, SEC_BLACKLIST);
		} else if (strcasecmp("pool6791", json->string) == 0) {
			check_duplicates(&pool6791_found, "pool6791");
			error = handle_addr4_pool(json, SEC_POOL6791);
		} else if (strcasecmp("file_type", json->string) == 0) {
			/* No code. */
		} else {
			log_err("I don't know what '%s' is; Canceling.",
					json->string);
			error = -EINVAL;
		}

		if (error) {
			free(globals_found);
			return error;
		}
	}
	free(globals_found);

	return send_ctrl_msg(SEC_COMMIT);
}
Exemplo n.º 2
0
static int parse_nat64_json(cJSON *json)
{
	bool global_found = false;
	bool pool6_found = false;
	bool pool4_found = false;
	bool bib_found = false;
	bool *globals_found;
	int error;

	error = send_ctrl_msg(SEC_INIT);
	if (error)
		return error;

	globals_found = create_globals_found_array();
	if (!globals_found) {
		log_err("Out of memory.");
		return -ENOMEM;
	}

	for (json = json->child; json; json = json->next) {
		if (strcasecmp("global", json->string) == 0) {
			check_duplicates(&global_found, "global");
			error = handle_global(json, globals_found);
		} else if (strcasecmp("pool6", json->string) == 0) {
			check_duplicates(&pool6_found, "pool6");
			error = handle_pool6(json);
		} else if (strcasecmp("pool4", json->string) == 0) {
			check_duplicates(&pool4_found, "pool4");
			error = handle_pool4(json);
		} else if (strcasecmp("bib", json->string) == 0) {
			check_duplicates(&bib_found, "bib");
			error = handle_bib(json);
		} else if (strcasecmp("file_type", json->string) == 0) {
			/* No code. */
		} else {
			log_err("I don't know what '%s' is; Canceling.",
					json->string);
			error = -EINVAL;
		}

		if (error) {
			log_info("Error: %d", error);
			free(globals_found);
			return error;
		}
	}
	free(globals_found);

	return send_ctrl_msg(SEC_COMMIT);
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: stas/-junk
int
add_dir(char *path)
{
   int position = 0;
   int len = strlen(path);

   if( check_duplicates(path) == 1 )
       return 0;
   // find a free position in fifo
   while(position < MAX_DIRS)
   {
       if(dirlist[position] == 0)
       {
           pthread_mutex_lock(&dirlist_acc[position]); 
           dirlist[position] = malloc( len+1 );
           if(dirlist[position] != 0)
           {
               strncpy(dirlist[position], path, len);
           }
           else
           {
               printf("add_dir: Could not allocate memory.\n");
               return 0;
           }
           pthread_mutex_unlock(&dirlist_acc[position]); 
           break;
       }
       position++;
   }
}
Exemplo n.º 4
0
static void
check_collisions(mmv_t *mmv)
{
    REPDICT *rd;
    size_t rd_size;

    if (mmv->nreps == 0) {
        return;
    }

    // Remember the size of this allocation
    rd_size = mmv->nreps * sizeof (REPDICT);
    rd = (REPDICT *) mmv_alloc(rd_size);
    init_repdict(mmv, rd);
    check_duplicates(mmv, rd);
    chgive(rd, rd_size);
}
Exemplo n.º 5
0
environment_list* insert_table(Node* node, environment_list* env, environment_list* previous, environment_list *outter_table){
	Node *aux;
	Node *aux2;
	table_element *temp;
	table_element *nodeFunc;
	switch (node->type){

		case VarDecl: 	;
						aux=node;
						while(aux!=NULL){
							aux2=aux->childs;
							Node *value=get_type(aux2);
							while(aux2->next!=NULL){
								check_duplicates(aux2,env->locals);
								lower(aux2->value.s);
								env->locals=insert_line(env->locals,aux2->value.s,check_type(value,env),"",_NULL_);
								aux2=aux2->next;
							}
							aux=aux->next;
						}
						return env;
		case FuncDecl:
		case FuncDef2:	
		case FuncDef:	;
						aux=node;
						while(aux!=NULL){
							if(aux->type==FuncDef)
								nodeFunc=insert_func(1,aux->childs,env,outter_table);
							else if(aux->type==FuncDef2)
								nodeFunc=insert_funcdef2(aux->childs,env,outter_table);
							else if(aux->type==FuncDecl)
								nodeFunc=insert_func(0,aux->childs,env,outter_table);

							if(env->locals==NULL){
								env->locals=nodeFunc;
							}
							else if(aux->type==FuncDef2){
								if(nodeFunc!=NULL){
									for(temp=env->locals;temp->next!=NULL;temp=temp->next){
										if(strcmp(temp->name,nodeFunc->name)==0){
											temp=nodeFunc;
											break;	
										}
									}
								}	
							}
							else{
								for(temp=env->locals;temp->next!=NULL;temp=temp->next);
								temp->next=nodeFunc;
							}

								aux=aux->next;
						}
						return env;			

		case Params:
		case VarParams:	;
						aux=node;
						while(aux!=NULL){
							aux2=aux->childs;
							char *flag;
							if(aux->type==Params) flag="param";
							else flag="varparam";
							Node *value=get_type(aux2);
							while(aux2->next!=NULL){
								check_duplicates(aux2,env->locals);
								lower(aux2->value.s);
								env->number_of_arguments++;
								env->locals=insert_line(env->locals,aux2->value.s,check_type(value,env),flag,_NULL_);
								aux2=aux2->next;
							}
							aux=aux->next;
						}

							return env;
		
		case IfElse:	;
						//check_statements(node->childs,"if",env);
						break;
		case While:		;
						//check_statements(node->childs,"while",env);
						break;
		case ValParam:	;
						//check_statements(node->childs,"val-paramstr",env);
						break;
		case Repeat:	;
						//check_statements(node->childs->next,"repeat-until",env);
						break;					
		case Assign:	;
						//check_expressions();
						break;
		
		case WriteLn:	;
						//check_writeln(node);
						break;
		case Call:	;
					check_number_of_arguments(node->childs,env);
					break;
		
		default: break;
	}
	
	if(node->childs){
		env = insert_table(node->childs,env,previous,outter_table);
	}
	if(node->next)
		env = insert_table(node->next, env,previous,outter_table);
		
	return env;
}
Exemplo n.º 6
0
//given a file extract blocks and check for duplicates
int extract_blocks(char* filename){

	//printf("Processing %s \n",filename);
    int fd = open(filename,O_RDONLY | O_LARGEFILE);


    
    uint64_t off=0;
    if(fd){

      struct stat st;
      stat(filename, &st);
      total_space+=st.st_size;
      
      //declare a block
      unsigned char block_read[READSIZE];
      bzero(block_read,sizeof(block_read));

      //read first block from file
      int aux = pread(fd,block_read,READSIZE,off);
      off+= READSIZE;

      //check if the file still has more blocks and if size <bzise discard
      //the last incomplete block
      while(aux>0){

      	//Process fixed size dups all sizes specified
         int curr_sizes_proc=0;
         while(curr_sizes_proc<nr_sizes_proc){

        	 int size_block=sizes_proc[curr_sizes_proc];
        	 int size_proced=0;
        	 unsigned char *block_proc;

           
        	 while(aux-size_proced>=size_block){

        		 block_proc=malloc(size_block);
        		 bzero(block_proc,size_block);

        		 memcpy(block_proc,&block_read[size_proced],size_block);

        		 //index the block and find duplicates
        		 check_duplicates(block_proc,size_block,curr_sizes_proc);

        		 free(block_proc);

        		 size_proced+=size_block;
        	 }


           if(aux-size_proced > 0){

	    
            incomplete_blocks[curr_sizes_proc]++;
            incomplete_space[curr_sizes_proc]+=aux-size_proced;


		//process the block anyway
		block_proc=malloc(aux-size_proced);
                bzero(block_proc,aux-size_proced);

                memcpy(block_proc,&block_read[size_proced],aux-size_proced);

                //index the block and find duplicates
                check_duplicates(block_proc,aux-size_proced,curr_sizes_proc);
                free(block_proc);

	
           }


        	 curr_sizes_proc++;
       	 }


       	 //process rabin chunks with avg size of 1K,4K,8K,16K
         //min size = avg size/2  and max size = avg size*2
         //Process fixed size dups for 1K,4K,8K,16K
       	 int curr_sizes_proc_rabin=0;
         while(curr_sizes_proc_rabin<nr_sizes_proc_rabin){

           rabin_polynomial_min_block_size=sizes_proc_rabin[curr_sizes_proc_rabin]/2;
           rabin_polynomial_max_block_size=sizes_proc_rabin[curr_sizes_proc_rabin]*2;
           rabin_polynomial_average_block_size=sizes_proc_rabin[curr_sizes_proc_rabin];
           rabin_sliding_window_size=30;

           struct rab_block_info *block;

           if(cur_block[curr_sizes_proc_rabin] == NULL) {

        	  //printf("Initializing rabin block %d\n",curr_sizes_proc_rabin);
              cur_block[curr_sizes_proc_rabin]=init_empty_block();
           }

           block=cur_block[curr_sizes_proc_rabin];

           int i;
           for(i=0;i<aux;i++) {
               	   char cur_byte=*((char *)(block_read+i));
                   char pushed_out=block->current_window_data[block->window_pos];
                   block->current_window_data[block->window_pos]=cur_byte;
                   block->cur_roll_checksum=(block->cur_roll_checksum*rabin_polynomial_prime)+cur_byte;
                   block->tail->polynomial=(block->tail->polynomial*rabin_polynomial_prime)+cur_byte;
                   block->cur_roll_checksum-=(pushed_out*polynomial_lookup_buf[rabin_sliding_window_size]);

                   block->window_pos++;
                   block->total_bytes_read++;
                   block->tail->length++;

                   if(block->window_pos == rabin_sliding_window_size) //Loop back around
                       block->window_pos=0;


                   //If we hit our special value or reached the max win size create a new block
                   if((block->tail->length >= rabin_polynomial_min_block_size && (block->cur_roll_checksum % rabin_polynomial_average_block_size) == rabin_polynomial_prime)|| block->tail->length == rabin_polynomial_max_block_size) {


                	   block->tail->start=block->total_bytes_read-block->tail->length;

                	   //insert hash in berkDB
                	   //index the block and find duplicates
                	   check_rabin_duplicates(cur_block[curr_sizes_proc_rabin]->tail,nr_sizes_proc+curr_sizes_proc_rabin);


                	   //free oldblock and polinomial
                	   //free(cur_block[curr_sizes_proc]->tail);
                	   cur_block[curr_sizes_proc_rabin]->tail=gen_new_polynomial(NULL,0,0,0);

                       //if(i==READSIZE-1)
                    	   //cur_block[curr_sizes_proc_rabin]->current_poly_finished=1;
                   }


           }

           curr_sizes_proc_rabin++;

         }

       	 //free this block from memory and process another
         //free(block_read);
         //block_read=malloc(sizeof(unsigned char)*READSIZE);
         aux = pread(fd,block_read,READSIZE,off);
         off+=READSIZE;



      }

    //zero the blocks a new file is being processed 
    int auxc=0;
    for(auxc=0;auxc<nr_sizes_proc_rabin;auxc++){

        struct rab_block_info *lastblock;
        lastblock = cur_block[auxc];

        if( lastblock->tail->length > 0){
            
	    if(lastblock->tail->length < sizes_proc_rabin[auxc]/2 ){
	        incomplete_blocks[nr_sizes_proc+auxc]++;
            	incomplete_space[nr_sizes_proc+auxc]+=lastblock->tail->length;
            }
	    //insert hash in berkDB
            //index the block and find duplicates
            check_rabin_duplicates(lastblock->tail,nr_sizes_proc+auxc);

	}

        cur_block[auxc]=NULL;
    } 

    close(fd);
    }
    else{
      fprintf(stderr,"error opening file %s\n",filename);
      exit(1);

    }

  return 0;

}
Exemplo n.º 7
0
int main(int argc, char** argv) 
{
    //Main Local Variable Declarations
    char temp_id[11];
    double temp_lat;
    double temp_long;
    struct observer *observer_start = NULL;
    char temp_obsid[11];
    char temp_mammal_type;
    double temp_bearing;
    double temp_range;
    struct sighting *sighting_start = NULL;
    char fileName[51];
    int flag = 0;
    char continueInput;
    
    //Loop through everything if input is false
    do
    {
        //Allows user to choose to continue or quit
        printf("Welcome to the Sea Mammal Sightings Analyzer!\n");
        printf("Type 'Y' to continue or 'N' to exit: \n");
        scanf(" %c", &continueInput);
        if(continueInput == 'Y' || continueInput == 'y')
        {
            //File Input. Example file: observers_3.txt  sightings_3.txt
            printf("Please enter the name of the observer file: ");
            //Read in user input
            scanf("%s", fileName);
            FILE* f1 = fopen(fileName, "r");

            //Error print if file problem
            if(f1 == NULL)
            {
                perror("Error opening file");
                return;
            }
            //Read in first line; input into dateTime structure
            fscanf(f1, "%d %d %d %d %d %d", &dateTime.date, &dateTime.month, 
                    &dateTime.year, &dateTime.hour, &dateTime.minute, &dateTime
                    .second);
            //Read in every line that has three elements; input into observer 
            //structure and insert into observer linked list
            while(fscanf(f1, "%4s %lf %lf", temp_id, &temp_lat, &temp_long) 
                    == 3)
            {
                struct observer *new_obs = make_observer(temp_id, temp_lat, 
                        temp_long);
                insert_observer(new_obs, &observer_start);
            }
            fclose(f1);
            //File input. Examples above
            printf("\nPlease enter the name of the mammal sighting file: ");
            //Read in user input
            scanf("%s", fileName);
            FILE* f2 = fopen(fileName, "r");
            //Read in every line that has four elements; input into sightings 
            //structure and insert into sightings linked list
            while(fscanf(f2, "%4s %c %lf %lf", temp_obsid, &temp_mammal_type, 
                    &temp_bearing, &temp_range) == 4)
            {
                struct sighting *new_sighting = make_sighting(temp_obsid, 
                        temp_mammal_type, temp_bearing, temp_range);
                insert_sighting(new_sighting, &sighting_start);
                //Increment sighting_count to keep track of number of sightings
                sighting_count++;
            }
            fclose(f2);
            
            //Print time and date
            printf("%d/%d/%d %d:%d:%d\n", dateTime.date, dateTime.month, 
                    dateTime.year, dateTime.hour, dateTime.minute, 
                    dateTime.second);
            
            //Commented out debugging functions
            //print_observer(&observer_start);
            //print_sighting(&sighting_start);
            
            //Mission 1 - All functions (including Linked List) are in 
            //feature1.h
            apply_mammal_locations(&observer_start, &sighting_start);
            print_locations(&sighting_start);
            
            //Loop through Feature 2 stuff if input is false
            do
            {
                printf("Type 'Y' to continue or 'N' to exit: \n");
                scanf(" %c", &continueInput);
                if(continueInput == 'Y' || continueInput == 'y')
                {
                    //Mission 2 - All functions are in feature2.h
                    set_true_location(&sighting_start);
                    print_locations_mission2(&sighting_start);
                    
                    //Loop through Feature 3 stuff if input is false
                    do
                    {
                        printf("Type 'Y' to continue or 'N' to exit: \n");
                        scanf(" %c", &continueInput);
                        if(continueInput == 'Y' || continueInput == 'y')
                        {
                            //Mission 3 - All functions are in feature3.h
                            check_pod(&sighting_start);
                            check_duplicates(&pod_start);
                            print_pods(&pod_start);
                            
                            //Allow user to exit program
                            printf("Press any key and return to exit\n"); 
                            scanf(" ", &continueInput);
                            printf("Thank you for using the Sea Mammal "
                                    "Sightings Analyzer\n");
                            //Exit Program
                            return (EXIT_SUCCESS);
                        }
                        else if(continueInput == 'N' || continueInput == 'n')
                        {
                            //Exit Program
                            printf("Thank you for using the Sea Mammal "
                                    "Sightings Analyzer\n");
                            return (EXIT_SUCCESS);
                        }
                        else
                        {
                            //Loop back to start; clear continueInput for scanf
                            printf("Please enter a valid character\n");
                            continueInput = 0;
                        }
                    //Loop forever
                    }while(1);
                }
                else if(continueInput == 'N' || continueInput == 'n')
                {
                    //Exit Program
                    printf("Thank you for using the Sea Mammal Sightings "
                            "Analyzer\n");
                    return (EXIT_SUCCESS);
                }
                else
                {
                    //Loop back to start; clear continueInput for scanf
                    printf("Please enter a valid character\n");
                    continueInput = 0;
                }
            //Loop forever
            }while(1);
        }
        else if(continueInput == 'N' || continueInput == 'n')
        {
            //Exit Program
            printf("Thank you for using the Sea Mammal Sightings Analyzer\n");
            return (EXIT_SUCCESS);
        }
        else
        {
            //Loop back to start; clear continueInput for scanf
            printf("Please enter a valid character\n");
            continueInput = 0;
        }
    //Loop forever
    }while(flag == 0);
    
    //Exit incase above code doesn't for some reason
    return (EXIT_SUCCESS);
}
Exemplo n.º 8
0
//given a file extract blocks and check for duplicates
int extract_blocks(char* filename){

	printf("Processing %s \n",filename);
    int fd = open(filename,O_RDONLY | O_LARGEFILE);
    uint64_t off=0;
    if(fd){

      //declare a block
      unsigned char block_read[READSIZE];
      bzero(block_read,sizeof(block_read));

      //read first block from file
      int aux = pread(fd,block_read,READSIZE,off);
      off+= READSIZE;

      //check if the file still has more blocks and if size <bzise discard
      //the last incomplete block
      while(aux>0){

      	//Process fixed size dups all sizes specified
         int curr_sizes_proc=0;
         while(curr_sizes_proc<nr_sizes_proc){

        	 int size_block=sizes_proc[curr_sizes_proc];
        	 int size_proced=0;
        	 unsigned char *block_proc;

        	 while(aux-size_proced>=size_block){

        		 block_proc=malloc(size_block);
        		 bzero(block_proc,size_block);

        		 memcpy(block_proc,&block_read[size_proced],size_block);

        		 //index the block and find duplicates
        		 check_duplicates(block_proc,size_block,curr_sizes_proc);

        		 free(block_proc);

        		 size_proced+=size_block;
        	 }

        	 curr_sizes_proc++;
       	 }

       	 //free this block from memory and process another
         //free(block_read);
         //block_read=malloc(sizeof(unsigned char)*READSIZE);
         aux = pread(fd,block_read,READSIZE,off);
         off+=READSIZE;

      }

      
    close(fd);
    }
    else{
      fprintf(stderr,"error opening file %s\n",filename);
      exit(1);

    }

  return 0;

}