Exemple #1
0
static int read_uidl(mailpop3 * f, carray * msg_tab)
{
  unsigned int indx;
  struct mailpop3_msg_info * msg;
  char * line;

  while (1) {
    char * uidl;

    line = read_line(f);
    if (line == NULL)
      goto err;
    
    if (mailstream_is_end_multiline(line))
      break;
    
    indx = strtol(line, &line, 10);

    if (!parse_space(&line))
      continue;

    uidl = strdup(line);
    if (uidl == NULL)
      continue;

    if (indx > carray_count(msg_tab)) {
      free(uidl);
      continue;
    }

    msg = carray_get(msg_tab, indx - 1);
    if (msg == NULL) {
      free(uidl);
      continue;
    }

    msg->msg_uidl = uidl;
  }
  
  return MAILPOP3_NO_ERROR;

 err:
  return MAILPOP3_ERROR_STREAM;
}
Exemple #2
0
static clist * read_articles_list(newsnntp * f)
{
  char * line;
  clist * articles_list;
  uint32_t * article_num;
  int r;

  articles_list = clist_new();
  if (articles_list == NULL)
    goto err;

  while (1) {
    line = read_line(f);
    if (line == NULL)
      goto free_list;

    if (mailstream_is_end_multiline(line))
      break;

    article_num = malloc(sizeof(* article_num));
    if (article_num == NULL)
      goto free_list;
    * article_num = atoi(line);

    r = clist_append(articles_list, article_num);
    if (r < 0) {
      free(article_num);
      goto free_list;
    }
  }

  return articles_list;

 free_list:
  articles_list_free(articles_list);
 err:
  return NULL;
}
Exemple #3
0
static clist * read_subscriptions_list(newsnntp * f)
{
  char * line;
  clist * subscriptions_list;
  char * group_name;
  int r;

  subscriptions_list = clist_new();
  if (subscriptions_list == NULL)
    goto err;

  while (1) {
    line = read_line(f);

    if (line == NULL)
      goto free_list;

    if (mailstream_is_end_multiline(line))
      break;

    group_name = strdup(line);
    if (group_name == NULL)
      goto free_list;

    r = clist_append(subscriptions_list, group_name);
    if (r < 0) {
      free(group_name);
      goto free_list;
    }
  }

  return subscriptions_list;

 free_list:
  subscriptions_list_free(subscriptions_list);
 err:
  return NULL;
}
Exemple #4
0
static clist * read_headers_list(newsnntp * f)
{
  char * line;
  clist * headers_list;
  char * header;
  int r;

  headers_list = clist_new();
  if (headers_list == NULL)
    goto err;

  while (1) {
    line = read_line(f);
    
    if (line == NULL)
      goto free_list;
    
    if (mailstream_is_end_multiline(line))
      break;
    
    header = strdup(line);
    if (header == NULL)
      goto free_list;

    r = clist_append(headers_list, header);
    if (r < 0) {
      free(header);
      goto free_list;
    }
  }

  return headers_list;

 free_list:
  headers_list_free(headers_list);
 err:
  return NULL;
}
Exemple #5
0
static int read_capa_resp(mailpop3 * f, clist ** result)
{
  char * line;
  int res;
  clist * list;
  int r;
  char * name;
  clist * param_list;

  list = clist_new();
  if (list == NULL) {
    res = MAILPOP3_NO_ERROR;
    goto err;
  }

  while (1) {
    char * next_token;
    char * param;
    struct mailpop3_capa * capa;

    line = read_line(f);
    if (line == NULL) {
      res = MAILPOP3_ERROR_STREAM;
      goto free_list;
    }
    
    if (mailstream_is_end_multiline(line))
      break;

    next_token = cut_token(line);
    name = strdup(line);
    if (name == NULL) {
      res = MAILPOP3_ERROR_MEMORY;
      goto free_list;
    }

    param_list = clist_new();
    if (param_list == NULL) {
      res = MAILPOP3_ERROR_MEMORY;
      goto free_capa_name;
    }

    while (next_token != NULL) {
      line = next_token;
      next_token = cut_token(line);
      param = strdup(line);
      if (param == NULL) {
	res = MAILPOP3_ERROR_MEMORY;
	goto free_param_list;
      }
      r = clist_append(param_list, param);
      if (r < 0) {
	free(param);
	res = MAILPOP3_ERROR_MEMORY;
	goto free_param_list;
      }
    }

    capa = mailpop3_capa_new(name, param_list);
    if (capa == NULL) {
      res = MAILPOP3_ERROR_MEMORY;
      goto free_param_list;
    }

    r = clist_append(list, capa);
    if (r < 0) {
      mailpop3_capa_free(capa);
      res = MAILPOP3_ERROR_MEMORY;
      goto free_list;
    }
  }

  * result = list;
  
  return MAILPOP3_NO_ERROR;

 free_param_list:
  clist_foreach(param_list, (clist_func) free, NULL);
  clist_free(param_list);
 free_capa_name:
  free(name);
 free_list:
  clist_foreach(list, (clist_func) mailpop3_capa_free, NULL);
  clist_free(list);
 err:
  return res;
}
Exemple #6
0
static clist * read_xover_resp_list(newsnntp * f)
{
  char * line;
  clist * xover_resp_list;
  struct newsnntp_xover_resp_item * n;
  clist * values_list;
  clistiter * current;
  uint32_t article;
  char * subject;
  char * author;
  char * date;
  char * message_id;
  char * references;
  size_t size;
  uint32_t line_count;
  clist * others;
  int r;
  
  xover_resp_list = clist_new();
  if (xover_resp_list == NULL)
    goto err;

  while (1) {
    char * p;
      
    line = read_line(f);

    if (line == NULL)
      goto free_list;

    if (mailstream_is_end_multiline(line))
      break;

    /* parse the data separated with \t */

    values_list = clist_new();
    if (values_list == NULL)
      goto free_list;

    while ((p = strchr(line, '\t')) != NULL) {
      * p = 0;
      p ++;

      r = clist_append(values_list, line);
      if (r < 0)
        goto free_values_list;
      line = p;
    }

    r = clist_append(values_list, line);
    if (r < 0)
      goto free_values_list;

    /* set the known data */
    current = clist_begin(values_list);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    article = 0;
    if (clist_content(current) != NULL) {
      article = atoi((char *) clist_content(current));
    }

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    subject = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    author = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    date = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    message_id = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    references = clist_content(current);

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    size = 0;
    if (clist_content(current) != NULL) {
      size = atoi((char *) clist_content(current));
    }

    current = clist_next(current);
    if (current == NULL) {
      clist_free(values_list);
      continue;
    }
    line_count = 0;
    if (clist_content(current) != NULL) {
      line_count = atoi((char *) clist_content(current));
    }

    current = clist_next(current);

    /* make a copy of the other data */
    others = clist_new();
    if (others == NULL) {
      goto free_values_list;
    }

    while (current) {
      char * val;
      char * original_val;

      original_val = clist_content(current);
      val = strdup(original_val);
      if (val == NULL) {
	clist_foreach(others, (clist_func) free, NULL);
	clist_free(others);
	goto free_list;
      }

      r = clist_append(others, val);
      if (r < 0) {
	goto free_list;
      }

      current = clist_next(current);
    }

    clist_free(values_list);

    n = xover_resp_item_new(article, subject, author, date, message_id,
			    references, size, line_count, others);
    if (n == NULL) {
      clist_foreach(others, (clist_func) free, NULL);
      clist_free(others);
      goto free_list;
    }

    r = clist_append(xover_resp_list, n);
    if (r < 0) {
      xover_resp_item_free(n);
      goto free_list;
    }
  }

  return xover_resp_list;

 free_list:
  newsnntp_xover_resp_list_free(xover_resp_list);
 err:
  return NULL;

 free_values_list:
  clist_foreach(values_list, (clist_func) free, NULL);
  clist_free(values_list);
  return NULL;
}
Exemple #7
0
static clist * read_groups_list(newsnntp * f)
{
  char * line;
  char * group_name;
  uint32_t first;
  uint32_t last;
  uint32_t count;
  int type;
  clist * groups_list;
  struct newsnntp_group_info * n;
  int r;

  groups_list = clist_new();
  if (groups_list == NULL)
    goto err;

  while (1) {
    char * p;
      
    line = read_line(f);
    if (line == NULL)
      goto free_list;

    if (mailstream_is_end_multiline(line))
      break;

    p = cut_token(line);
    if (p == NULL)
      continue;

    group_name = line;
    line = p;

    last = strtol(line, &line, 10);
    if (!parse_space(&line))
      continue;

    first = strtol(line, &line, 10);
    if (!parse_space(&line))
      continue;

    count = last - first + 1;

    type = * line;

    n = group_info_init(group_name, first, last, count, type);
    if (n == NULL)
      goto free_list;

    r = clist_append(groups_list, n);
    if (r < 0) {
      group_info_free(n);
      goto free_list;
    }
  }

  return groups_list;

 free_list:
  group_info_list_free(groups_list);
 err:
  return NULL;
}