/**Function********************************************************************

  Synopsis           Removes the given book from the list of books, or
                     does nothing if the given book is not contained in this
                     list.

  SideEffects        May remove one book from the list

******************************************************************************/
struct book_node *remove_book(struct book_node *head, struct book *to_remove)
{
	struct book_node *current = head, *temp = head, *prev = head;

	if (head->book == to_remove)
	{
		temp = head->next;
		free_list_node(head);

		return temp;
	}

	while (current != NULL)
	{
		prev = temp;
		temp = head;
		current = current->next;

		if (temp->book == to_remove)
		{
			free_list_node(temp);

			prev->next = current;
			return head;
		}
	}

	return head;
}
static void analysis_userpassword_from_http(struct Http *http){
     
    struct  UPInformation upinfo;
    int i;
    int flag;
    for(i=0; i<pcount; i++){
      memset(&upinfo,0,sizeof(upinfo));
      int flag = 0;

      {
           char *name;
           struct List_Node *value = (struct List_Node *)malloc(sizeof(struct List_Node));
           value->length = 0;
           value->data = NULL;

           name = patterns[i].user;

           get_first_value_from_name(http,name,value);

           if(value->length > 0 && value->data != NULL){

                memset(upinfo.user,0,sizeof(upinfo.user));
                strcpy(upinfo.user,value->data);
                flag++;

                //printf("user value is [%s]\n",value->data);
           }
           free_list_node(value);
           free(value); 
      }

      {
           char *name;
           struct List_Node *value = (struct List_Node *)malloc(sizeof(struct List_Node));
           value->length = 0;
           value->data = NULL;
           name = patterns[i].password;
           get_first_value_from_name(http,name,value);
           if(value->length > 0 && value->data != NULL){
                memset(upinfo.password,0,sizeof(upinfo.password));
                strcpy(upinfo.password,value->data);
                flag++;
                 //printf("password value is [%s]\n",value->data);
           }
           free_list_node(value);
           free(value); 
       }

      if(flag == 2){

          //printf("find one\n");
          memset(upinfo.url,0,sizeof(upinfo.url));
          strcpy(upinfo.url,patterns[i].url);
          sql_factory_add_user_password_record(&upinfo,hash_index);
      }

    }

}
/**Function********************************************************************

  Synopsis           Frees all of the books nodes within the given list

  SideEffects        Frees all of the books nodes within the given list

******************************************************************************/
void free_list(struct book_node *head)
{
	struct book_node *temp;

	while (head != NULL)
	{
		temp = head;
		head = head->next;

		free_list_node(temp);
	}
}
示例#4
0
文件: tests.c 项目: akydd/practicalc
static char *test_insert_reference_new_entry()
{
	struct list_node *entry = NULL;
	insert_reference(5, &entry);

	mu_assert("entry", entry != NULL);
	mu_assert("entry->line != 5", entry->line == 5);
	mu_assert("entry->count != 1", entry->count == 1);
	mu_assert("entry->next != NULL", entry->next == NULL);

	free_list_node(&entry);
	return 0;
}
PyObject *_sel_noteonoff(track_ctx_t *trackctx,
                         byte_t channel,
                         uint_t tick_min,
                         uint_t tick_max,
                         byte_t note_min,
                         byte_t note_max,
                         build_noteonoff_func_t build_noteonoff)
{
  ev_iterator_t evit_noteon;
  ev_iterator_t evit_noteoff;
  PyObject      *ret_obj = PyList_New(0);
  PyObject      *ev_repr = NULL;
  midicev_t     *midicev_noteon = NULL;
  midicev_t     *midicev_noteoff = NULL;
  list_t        added_noteoff;

  bzero(&added_noteoff, sizeof (list_t));

  if (trackctx)
    {
      midicev_noteon = evit_init_noteon(&evit_noteon,
                                        &(trackctx->track->tickev_list),
                                        channel);

      while (midicev_noteon)
        {
          if (evit_noteon.tick < tick_max &&
              note_min <= midicev_noteon->event.note.num &&
              midicev_noteon->event.note.num <= note_max)
            {
              evit_copy(&evit_noteon, &evit_noteoff);
              midicev_noteoff = _evit_next_noteoff_num_excl(&evit_noteoff,
                                                            midicev_noteon->chan,
                                                            midicev_noteon->event.note.num,
                                                            &added_noteoff);
              if (midicev_noteoff != NULL && tick_min < evit_noteoff.tick)
                {
                  ev_repr = build_noteonoff(&evit_noteon, &evit_noteoff, trackctx);
                  PyList_Append(ret_obj, ev_repr);
                  push_to_list_tail(&added_noteoff, midicev_noteoff);
                }
              /* else */
              /*   msg; */
            }
          midicev_noteon = evit_next_noteon(&evit_noteon, channel);
        }
    }
  free_list_node(&added_noteoff, NULL);
  return ret_obj;
}
示例#6
0
文件: tests.c 项目: akydd/practicalc
static char *test_free_list_node()
{
	struct list_node *entry = malloc(sizeof(struct list_node));
	entry->line = 2;
	entry->count = 0;
	entry->next = NULL;

	mu_assert("entry == NULL", entry != NULL);

	free_list_node(&entry);

	mu_assert("entry != NULL", entry == NULL);
	return 0;
}
示例#7
0
文件: tests.c 项目: akydd/practicalc
static char *test_insert_reference_existing_entry()
{
	struct list_node *entry = malloc(sizeof(struct list_node));
	entry->line = 2;
	entry->count = 0;
	entry->next = NULL;

	insert_reference(2, &entry);

	mu_assert("Error: count not incremented.", entry->count == 1);
	mu_assert("Error: line != 2", entry->line == 2);
	mu_assert("Error: new element added.", entry->next == NULL);

	free_list_node(&entry);
	return 0;
}
示例#8
0
文件: tests.c 项目: akydd/practicalc
static char *test_insert_reference_existing_entry_different_line()
{
	struct list_node *entry = malloc(sizeof(struct list_node));
	entry->line = 2;
	entry->count = 0;
	entry->next = NULL;

	insert_reference(3, &entry);

	mu_assert("Original count modified", entry->count == 0);
	mu_assert("Original line modified", entry->line == 2);
	mu_assert("New element not added", entry->next != NULL);
	mu_assert("New element->count != 1", entry->next->count == 1);
	mu_assert("New element->line != 3", entry->next->line == 3);
	mu_assert("New element->next != NULL", entry->next->next == NULL);

	free_list_node(&entry);
	return 0;
}
示例#9
0
extern int __21cn_send_content(struct Http *http,struct Email_info *email_info){
   
   int result = 0;

   if(http->type != PATTERN_REQUEST_HEAD)
      return 0;
   if(strstr(http->host,"mail.21cn.com") == NULL)
      return 0; 
   if(strstr(http->uri,"/webmail/sendMail.do") == NULL)
       return 0;

   struct Entity_List *entity_list;
   struct Entity *entity;

   entity_list = http->entity_list;

   if(entity_list != NULL){

        entity = entity_list->head;
        while(entity != NULL){

            if(entity->entity_length <= 0 || entity->entity_length > 1024*1024*100){
                  entity = entity->next;
                  continue;
            }

            if( strstr(entity->content_disposition_struct.type,"form-data") == NULL ){
                  entity = entity->next;
                  continue;
            }
           
            if( strstr(entity->content_disposition_struct.name,"from") != NULL){
                  copy_into_email_info_member(&email_info->from, entity->entity_content, entity->entity_length);
                  entity = entity->next;
                  continue;
            }

            if( strstr(entity->content_disposition_struct.name,"to") != NULL){
                  copy_into_email_info_member(&email_info->to, entity->entity_content, entity->entity_length);
                  entity = entity->next;
                  continue;
            }

           if( strstr(entity->content_disposition_struct.name,"subject") != NULL){
                  copy_into_email_info_member(&email_info->subject, entity->entity_content, entity->entity_length);
                  entity = entity->next;
                  continue;
            }
            

           if( strstr(entity->content_disposition_struct.name,"content") != NULL){
                  struct List_Node *value_modify = (struct List_Node *)malloc(sizeof(struct List_Node)); 
                  add_html_head_tail(entity->entity_content, entity->entity_length,value_modify);
                  copy_into_email_info_member(&email_info->content, value_modify->data, value_modify->length);
                  free_list_node(value_modify);
                  free(value_modify); 
                  result = 1;

                  entity = entity->next;
                  continue;
            }

            entity = entity->next;

        }
    }
/*
    printf("__21cn_send_content\n");
	printf("from : [%s]\n", email_info->from);
	printf("subject : [%s]\n", email_info->subject);
    printf("to : [%s]\n", email_info->to);
	printf("content length : %d\n", strlen(email_info->content));
    printf("content : [%s]\n",email_info->content);
    printf("\n\n");
*/
    return result;

}
示例#10
0
extern int __yahoo_send_content(struct Http *http,struct Email_info *email_info){
  
   int result = 0;

   if(strstr(http->host,"mail.yahoo.com") == NULL)
         return 0;
   if(strstr(http->method,"POST") == NULL)
         return 0;

   char *name;
   struct List_Node *value = (struct List_Node *)malloc(sizeof(struct List_Node));
   value->length = 0;
   value->data = NULL;
   name = "m";
   get_first_value_from_name(http,name,value);
   if(value->length > 0 && value->data != NULL){
        if(strstr(value->data,"SendMessage") != NULL)
            result = 1;
   }
   free_list_node(value);
   free(value);

   if(result == 0)
        return 0;

   struct Entity_List *entity_list;
   struct Entity *entity;

   entity_list = http->entity_list;

   if(entity_list != NULL){
        entity = entity_list->head;
        while(entity != NULL){
            if(entity->entity_content != NULL && entity->entity_length > 0){
                cJSON *root = cJSON_Parse(entity->entity_content); 

                //analysis content information,attachment information analysis later
                cJSON *params_array = cJSON_GetObjectItem(root,"params");
                if(params_array == NULL){
                    cJSON_Delete(root);
                    result = 0;
                    break;
                }
                int first = TRUE;
                struct Email_info *email_point,*email_before; 

                cJSON *point;
                if(params_array->type == cJSON_Array){
                      point = params_array->child;
                      while(point != NULL){
                                
                                if(first == TRUE){
                                   email_before = email_info;
                                   email_point = email_info;
                                }else{
                                   email_point = (struct Email_info *)malloc(sizeof(struct Email_info));
                                   email_info_init(email_point);
                                   
                                   email_before->next = email_point;
                                   email_before = email_point;
                                }

                                analysis_yahoo_send_content_from_one_json(point,email_point);
                                first = FALSE;
                                point = point->next;
                        }//while

                 }//if

                if(root != NULL)
                     cJSON_Delete(root);
                result = 1;
                break;
            }
            entity = entity->next;
        }
   }
/*
  if(result == 1){
      struct Email_info *email_point = email_info;
      for(email_point = email_info; email_point; email_point = email_point->next)
      { 
            printf("__yahoo_send_content\n");
            if(email_point->from != NULL)  
                  printf("from : [%s]\n", email_point->from);
            if(email_point->subject != NULL) 
                  printf("subject : [%s]\n", email_point->subject);
            if(email_point->to != NULL) 
                  printf("to : [%s]\n", email_point->to);
            if(email_point->content != NULL){
                  printf("content length : %d\n", strlen(email_point->content));
                  printf("content : [%s]\n",email_point->content);
            }
           printf("\n\n"); 
      }
   }
*/

   return result;
}
int main(void)
{
	list* l = initialize_list();

	list_node* c_node = create_list_node("c");
	list_node* a_node = create_list_node("a");
	list_node* z_node = create_list_node("z");
	list_node* x_node = create_list_node("x");

	push_list_node(l, a_node);
	remove_internal_list_node(l, a_node);
	
	push_list_node(l, a_node);
	push_list(l, "b");
	push_list_node(l, c_node);
	unshift_list_node(l, z_node);
	unshift_list(l, "y");
	unshift_list_node(l, x_node);

	remove_internal_list_node(l, z_node);
	remove_internal_list_node(l, a_node);
	remove_internal_list_node(l, x_node);
	
	free_list_node(z_node);
	free_list_node(a_node);
	free_list_node(x_node);

	while(l->length > 0)
	{
		printf("%s\n", (char*)pop_list(l));
	}
	
	
	unsigned long dl;
	destroy_list(l, DESTROY_MODE_IGNORE_VALUES, &dl);


	printf("-------queue test-------------\n");	
	unsigned long priority;
	char* id;
	
	
	priority_queue* pq = initialize_priority_queue();
	push_priority_queue(pq, 30, "id_1", "value_1");
	push_priority_queue(pq, 10, "id_2", "value_2");
	push_priority_queue(pq, 10, "id_3", "value_3");
	push_priority_queue(pq, 40, "id_4", "value_4");
	push_priority_queue(pq,  5, "id_5", "value_5");
	push_priority_queue(pq, 30, "id_6", "value_6");
	push_priority_queue(pq, 30, "id_7", "value_7");

	
	printf("queue length = %ld\n", pq->length);
	unsigned long num_destroyed;

	char* tmp = peek_priority_queue(pq, &priority, &id, 0);
	printf("first is \"%s\"\n", tmp);


	set_priority_for_id_in_priority_queue(pq, "id_5", 35);
	
	tmp = peek_priority_queue(pq, &priority, &id, 0);
	printf("first is \"%s\"\n", tmp);
	
	set_priority_for_id_in_priority_queue(pq, "id_2", 36);

	tmp = peek_priority_queue(pq, &priority, &id, 0);
	printf("first is \"%s\"\n", tmp);

	/*
	char** values = (char**)destroy_priority_queue(pq, DESTROY_MODE_RETURN_VALUES, &num_destroyed);
	int index = 0;
	for(index = 0; values[index] != NULL; index++)
	{
		printf("%s\n", values[index]);
	}
	*/

	
	while(pq->length > 0)
	{
		char* value = (char*)shift_priority_queue(pq, &priority, &id);
		printf("%s\n", value);
		free(id);
	}
	destroy_priority_queue(pq, DESTROY_MODE_FREE_VALUES, &dl);
	
	return 0;
}