예제 #1
0
void convert()
{
   int max=0,min=255,up=0,thres=128,last=0;
   int val,length1,length2;
   while(1) {
	length1=length2=0;
	while(1) {
		val=getc(in);
		if (val==EOF) return;
		if (val>max) max=val;
		if (val<last && up) { up=0; thres=(max+min)/2; min=255;}
		last=val;
		if (val>thres) length1++;
		else break;
	}
	while(1) {
		val=getc(in);
		if (val==EOF) return;
		if (val<min) min=val;
		if (val>last && !up) { up=1; thres=(max+min)/2; max=0; }
		last=val;
		if (val<thres) length2++;
		else break;
	}
	output_level(1);
	output_level(0);
	if (length1+length2>=THRESHOLD) output_level(0);
	if (length1+length2>10*THRESHOLD) output_silence((length1+length2)/9);
    }
}
예제 #2
0
int retrieve (Job *job)
{
    CURL *curl;
    CURLcode rc;
    FILE *outfp;
    JobOptions *opts;

    debug ("Retrieval process %d running job:", getpid());
    debug_dump_job (job);

    if (job->options.continue_from) {
        outfp = fopen (job->options.save_to, "a");
    } else {
        outfp = fopen (job->options.save_to, "w");
    }

    if (!outfp) {
        error_sys ("could not open `%s' for output",
                   job->options.save_to);
        return 1;
    }

    curl = curl_easy_init ();
    if (!curl) {
        error ("could not initialize libcurl");
        write_error_file (job, "could not initialize libcurl");
        fclose (outfp);
        return 1;
    }

    curl_easy_setopt (curl, CURLOPT_FILE, outfp);
    curl_easy_setopt (curl, CURLOPT_URL, job->source_url);
    curl_easy_setopt (
            curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
    curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, (void *)job);
    curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, job->error);
    curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0);

    if (job->options.continue_from) {
        curl_easy_setopt (curl, CURLOPT_RESUME_FROM,
                          (long)job->options.continue_from);
    }

    /* Now load the job's user-configurable parameters:
     */
    opts = &job->options;

    if (opts->proxy[0]) {
        curl_easy_setopt (curl, CURLOPT_PROXY, opts->proxy);
    }

    if (opts->follow) {
        curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_easy_setopt (curl, CURLOPT_MAXREDIRS, opts->follow);
    } else {
        curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 0);
    }

    if (opts->user_agent[0]) {
        curl_easy_setopt (curl, CURLOPT_USERAGENT, opts->user_agent);
    }

    if (opts->use_ascii) {
        curl_easy_setopt (curl, CURLOPT_TRANSFERTEXT, 1);
    }

    if (opts->referer[0]) {
        curl_easy_setopt (curl, CURLOPT_REFERER, opts->referer);
    }

    if (opts->include) {
        curl_easy_setopt (curl, CURLOPT_HEADER, 1);
    }

    if (opts->interface[0]) {
        curl_easy_setopt (curl, CURLOPT_INTERFACE, opts->interface);
    }

    if (opts->proxy_auth[0]) {
        curl_easy_setopt (curl, CURLOPT_PROXYUSERPWD, opts->proxy_auth);
    }

    if (opts->auth[0]) {
        curl_easy_setopt (curl, CURLOPT_USERPWD, opts->auth);
    }


    /* If wmget is verbose, set libcurl to verbose too...
     */
    if (output_level () > OL_NORMAL)
        curl_easy_setopt (curl, CURLOPT_VERBOSE, 1);


    /* Finally, perform the download:
     */
    job->status = J_RUNNING;
    rc = curl_easy_perform (curl);

    if (rc) {
        if (job->status == J_STOPPING) {
            info ("aborted by user");
            job->status = J_COMPLETE;

        } else {
            error (job->error);
            write_error_file (job, job->error);
            job->status = J_COMPLETE;
        }
    } else {
        job->status = J_COMPLETE;
    }

    curl_easy_cleanup (curl);
    fclose (outfp);

    if (rc)
        return 1;

    return 0;
}