Exemplo n.º 1
0
static int post_file(newspost_data *data, file_entry *file_data, 
	  int filenumber, int number_of_files,
	  const char *filestring, char *data_buffer) {
	long number_of_bytes;
	int j, retval;
	int number_of_tries = 0;
	int parts_posted = 0;
	int number_of_parts = 
		get_number_of_encoded_parts(data, file_data);
	static int total_failures = 0;
	boolean posting_started = FALSE;
	Buff * subject = NULL;

	if(file_data->parts != NULL){
		if(file_data->parts[0] == TRUE) return NORMAL;
	}

	for (j = 1; j <= number_of_parts; j++) {

		if ((file_data->parts != NULL) &&
		    (file_data->parts[j] == FALSE))
			continue;

		subject = make_subject(subject, data, filenumber, number_of_files,
			     file_data->filename->data, j, number_of_parts,
			     filestring);
		
		number_of_bytes = get_encoded_part(data, file_data, j,
						   data_buffer);
		if (posting_started == FALSE) {
			ui_posting_file_start(data, file_data, 
				      number_of_parts, number_of_bytes);
			posting_started = TRUE;
		}
	
		ui_posting_part_start(file_data, j, number_of_parts,
				      number_of_bytes);

		retval = nntp_post(subject->data, data, data_buffer,
				   number_of_bytes, FALSE);

		if (retval == NORMAL) {
			ui_posting_part_done(file_data, j, number_of_parts,
					     number_of_bytes);
			parts_posted++;
		}
		else if (retval == POSTING_NOT_ALLOWED)
			return retval;
		else {
			if (number_of_tries < 5) {
				ui_nntp_posting_retry();
				sleep(5);
				number_of_tries++;
				continue;
			}
			else {
				total_failures++;
				if (total_failures == 5) {
					nntp_logoff();
					socket_close();
					ui_too_many_failures();
				}
			}
		}
		number_of_tries = 0;
	}
	buff_free(subject);

	ui_posting_file_done();
	return NORMAL;
}
Exemplo n.º 2
0
static int encode_and_post(newspost_data *data, SList *file_list,
			    SList *parfiles) {
	int number_of_parts;
	int number_of_files;
	int i;
	file_entry *file_data = NULL;
	int retval = NORMAL;
	char *data_buffer = 
		(char *) malloc(get_buffer_size_per_encoded_part(data));
	Buff *subject = NULL;
	Buff *text_buffer = NULL;

	/* create the socket */
	ui_socket_connect_start(data->address->data);
	retval = socket_create(data->address->data, data->port);
	if (retval < 0)
		return retval;

	ui_socket_connect_done();

	/* log on to the server */
	ui_nntp_logon_start(data->address->data);
	if (nntp_logon(data) == FALSE) {
		socket_close();
		return LOGON_FAILED;
	}
	ui_nntp_logon_done();

	if (data->text == TRUE) {
		file_data = file_list->data;
		/* post */
		text_buffer = read_text_file(text_buffer, file_data->filename->data);
		if(text_buffer != NULL)
			retval = nntp_post(data->subject->data, data, text_buffer->data,
					   text_buffer->length, TRUE);
	}
	else {
		/* post any sfv files... */
		if (data->sfv != NULL) {
			file_data = file_entry_alloc(file_data);
			file_data->filename = 
				buff_create(file_data->filename, "%s", data->sfv->data);
			if (stat(data->sfv->data, &file_data->fileinfo) == -1)
				ui_sfv_gen_error(data->sfv->data, errno);
			else {
				retval = post_file(data, file_data, 1, 1,
						   "SFV File", data_buffer);
				if (retval < 0)
					return retval;

				unlink(data->sfv->data);
			}
			free(file_data);
		}

		number_of_files = slist_length(file_list);

		/* if there's a prefix, post that */
		if (data->prefix != NULL) {
			ui_posting_prefix_start(data->prefix->data);

			file_data = (file_entry *) file_list->data;
			number_of_parts = 
				get_number_of_encoded_parts(data, file_data);
			subject = make_subject(subject, data, 1 , number_of_files,
				     file_data->filename->data, 0 , number_of_parts,
				     "File");

			text_buffer = read_text_file(text_buffer, data->prefix->data);
			if (text_buffer != NULL) {
				retval = nntp_post(subject->data, data, text_buffer->data, 
						   text_buffer->length, TRUE);
				if (retval == POSTING_NOT_ALLOWED)
					return retval;
				else if (retval == POSTING_FAILED) {
					/* dont bother retrying...
					   who knows what's in that file */
					ui_posting_prefix_failed();
					retval = NORMAL;
				}
				else if (retval == NORMAL)
					ui_posting_prefix_done();
			}
			else
				ui_posting_prefix_failed();

			buff_free(subject);
		}
	
		/* post the files */
		i = 1;
		while (file_list != NULL) {

			file_data = (file_entry *) file_list->data;

			retval = post_file(data, file_data, i, number_of_files,
					   "File", data_buffer);
			if (retval < 0)
				return retval;

			i++;
			file_list = slist_next(file_list);
		}

		/* post any par files */
		i = 1;
		file_list = parfiles;
		number_of_files = slist_length(parfiles);
		while (file_list != NULL) {

			file_data = (file_entry *) file_list->data;

			retval = post_file(data, file_data, i, number_of_files,
					   "PAR File", data_buffer);
			if (retval < 0)
				return retval;

			unlink(file_data->filename->data);
			buff_free(file_data->filename);
			free(file_data);
			i++;
			file_list = slist_next(file_list);
		}
		slist_free(parfiles);
	}

	nntp_logoff();
	socket_close();
	
	free(data_buffer);
	buff_free(text_buffer);

	return retval;
}
Exemplo n.º 3
0
/* Event handler for tool 'error-support' */
ATerm error_support_handler(int conn, ATerm term)
{
  ATerm in, out;
  /* We need some temporary variables during matching */
  char *s0, *s1;
  ATerm t0;

  if(ATmatch(term, "rec-eval(make-error(<str>,<term>))", &s0, &t0)) {
    return make_error(conn, s0, t0);
  }
  if(ATmatch(term, "rec-eval(get-area-end-line(<term>))", &t0)) {
    return get_area_end_line(conn, t0);
  }
  if(ATmatch(term, "rec-eval(get-location-filename(<term>))", &t0)) {
    return get_location_filename(conn, t0);
  }
  if(ATmatch(term, "rec-eval(has-location-area(<term>))", &t0)) {
    return has_location_area(conn, t0);
  }
  if(ATmatch(term, "rec-eval(get-summary-id(<term>))", &t0)) {
    return get_summary_id(conn, t0);
  }
  if(ATmatch(term, "rec-eval(get-error-description(<term>))", &t0)) {
    return get_error_description(conn, t0);
  }
  if(ATmatch(term, "rec-do(display-summary(<term>))", &t0)) {
    display_summary(conn, t0);
    return NULL;
  }
  if(ATmatch(term, "rec-eval(lower-summary(<term>))", &t0)) {
    return lower_summary(conn, t0);
  }
  if(ATmatch(term, "rec-eval(make-localized-subject(<str>,<term>))", &s0, &t0)) {
    return make_localized_subject(conn, s0, t0);
  }
  if(ATmatch(term, "rec-eval(get-summary-producer(<term>))", &t0)) {
    return get_summary_producer(conn, t0);
  }
  if(ATmatch(term, "rec-eval(get-error-subjects(<term>))", &t0)) {
    return get_error_subjects(conn, t0);
  }
  if(ATmatch(term, "rec-eval(make-subject(<str>))", &s0)) {
    return make_subject(conn, s0);
  }
  if(ATmatch(term, "rec-eval(get-subject-location(<term>))", &t0)) {
    return get_subject_location(conn, t0);
  }
  if(ATmatch(term, "rec-eval(get-area-offset(<term>))", &t0)) {
    return get_area_offset(conn, t0);
  }
  if(ATmatch(term, "rec-eval(get-area-begin-line(<term>))", &t0)) {
    return get_area_begin_line(conn, t0);
  }
  if(ATmatch(term, "rec-eval(add-filename-in-error(<str>,<term>))", &s0, &t0)) {
    return add_filename_in_error(conn, s0, t0);
  }
  if(ATmatch(term, "rec-eval(get-location-area(<term>))", &t0)) {
    return get_location_area(conn, t0);
  }
  if(ATmatch(term, "rec-eval(set-summary-id(<term>,<str>))", &t0, &s0)) {
    return set_summary_id(conn, t0, s0);
  }
  if(ATmatch(term, "rec-eval(has-subject-location(<term>))", &t0)) {
    return has_subject_location(conn, t0);
  }
  if(ATmatch(term, "rec-eval(get-area-end-column(<term>))", &t0)) {
    return get_area_end_column(conn, t0);
  }
  if(ATmatch(term, "rec-eval(make-summary(<str>,<str>,<term>))", &s0, &s1, &t0)) {
    return make_summary(conn, s0, s1, t0);
  }
  if(ATmatch(term, "rec-eval(get-summary-errors(<term>))", &t0)) {
    return get_summary_errors(conn, t0);
  }
  if(ATmatch(term, "rec-eval(get-subject-description(<term>))", &t0)) {
    return get_subject_description(conn, t0);
  }
  if(ATmatch(term, "rec-eval(get-area-length(<term>))", &t0)) {
    return get_area_length(conn, t0);
  }
  if(ATmatch(term, "rec-terminate(<term>)", &t0)) {
    rec_terminate(conn, t0);
    return NULL;
  }
  if(ATmatch(term, "rec-eval(get-area-begin-column(<term>))", &t0)) {
    return get_area_begin_column(conn, t0);
  }
  if(ATmatch(term, "rec-do(signature(<term>,<term>))", &in, &out)) {
    ATerm result = error_support_checker(conn, in);
    if(!ATmatch(result, "[]"))
      ATfprintf(stderr, "warning: not in input signature:\n\t%\n\tl\n", result);
    return NULL;
  }

  ATerror("tool error-support cannot handle term %t", term);
  return NULL; /* Silence the compiler */
}