⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 .#webcam.c.1.19

📁 camE 1.9 for Linux - camE is an imlib2 webcam grabber, annotator, and uploader.
💻 19
📖 第 1 页 / 共 2 页
字号:
/* upload local to tmp then MV to remote */voidftp_upload1(char *local, char *remote, char *tmp){   char buf[2096];   FILE *infile;   CURLcode ret;   CURL *curl_handle;   struct stat st;   struct curl_slist *post_commands = NULL;   char *passwd_string, *url_string;   infile = fopen(local, "r");   if (!infile)   {      fprintf(stderr, "camE: Couldn't open temp file to upload it\n");      perror("ftp_upload(): ");      return;   }   fstat(fileno(infile), &st);   snprintf(buf, sizeof(buf), "rnfr %s", tmp);   post_commands = curl_slist_append(post_commands, buf);   snprintf(buf, sizeof(buf), "rnto %s", remote);   post_commands = curl_slist_append(post_commands, buf);   /* init the curl session */   curl_handle = curl_easy_init();   curl_easy_setopt(curl_handle, CURLOPT_INFILE, infile);   curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE, st.st_size);   passwd_string = gib_strjoin(":", ftp_user, ftp_pass, NULL);   curl_easy_setopt(curl_handle, CURLOPT_USERPWD, passwd_string);   /* set URL to save to */   url_string = gib_strjoin("/", "ftp:/", ftp_host, ftp_dir, tmp, NULL);   curl_easy_setopt(curl_handle, CURLOPT_URL, url_string);   /* no progress meter please */   curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);   /* shut up completely */   if (ftp_debug)      curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);   else      curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);   curl_easy_setopt(curl_handle, CURLOPT_POSTQUOTE, post_commands);   curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1);   /* get it! */   ret = curl_easy_perform(curl_handle);   /* TODO check error */   if (ret)   {      fprintf(stderr, "\ncamE: error sending via ftp: ");      log("EEEE error: ");      switch (ret)      {        case CURLE_URL_MALFORMAT:           fprintf(stderr, "Badly formatted ftp host or directory\n");           log("Badly formatted ftp host or directory\n");           break;        case CURLE_URL_MALFORMAT_USER:           fprintf(stderr, "Badly formatted ftp username\n");           log("Badly formatted ftp username\n");           break;        case CURLE_COULDNT_RESOLVE_PROXY:           fprintf(stderr, "Couldn't resolve proxy\n");           log("Couldn't resolve proxy\n");           break;        case CURLE_COULDNT_RESOLVE_HOST:           fprintf(stderr, "Unable to resolve ftp host\n");           log("Unable to resolve ftp host\n");           break;        case CURLE_COULDNT_CONNECT:           fprintf(stderr, "Unable to connect to ftp host\n");           log("Unable to connect to ftp host\n");           break;        case CURLE_FTP_WEIRD_SERVER_REPLY:           fprintf(stderr, "Wierd server reply detected\n");           log("Wierd server reply detected\n");           break;        case CURLE_FTP_ACCESS_DENIED:           fprintf(stderr, "Access denied to ftp upload\n");           log("Access denied to ftp upload\n");           break;        case CURLE_FTP_USER_PASSWORD_INCORRECT:           fprintf(stderr, "Incorrect password for ftp login\n");           log("Incorrect password for ftp login\n");           break;        case CURLE_FTP_WEIRD_PASS_REPLY:           fprintf(stderr, "Wierd password reply from server\n");           log("Wierd password reply from server\n");           break;        case CURLE_FTP_WEIRD_USER_REPLY:           fprintf(stderr, "Wierd user reply from server\n");           log("Wierd user reply from server\n");           break;        case CURLE_FTP_WEIRD_PASV_REPLY:           fprintf(stderr, "Wierd passive reply from server\n");           log("Wierd passive reply from server\n");           break;        case CURLE_FTP_CANT_GET_HOST:           fprintf(stderr, "No route to host\n");           log("No route to host\n");           break;        case CURLE_FTP_COULDNT_SET_BINARY:           fprintf(stderr, "Couldn't set binary mode\n");           log("Couldn't set binary mode\n");           break;        case CURLE_PARTIAL_FILE:           fprintf(stderr, "Only partial file uploaded\n");           log("Only partial file uploaded\n");           break;        case CURLE_FTP_WRITE_ERROR:           fprintf(stderr, "Write error\n");           log("Write error\n");           break;        case CURLE_FTP_QUOTE_ERROR:           fprintf(stderr, "Misquoted ftp command - check ftp config\n");           log("Misquoted ftp command - check ftp config\n");           break;        case CURLE_WRITE_ERROR:           fprintf(stderr, "Write error\n");           log("Write error\n");           break;        case CURLE_MALFORMAT_USER:	/* the user name is illegally specified */           fprintf(stderr, "Malformatted username\n");           log("Malformatted username\n");           break;        case CURLE_FTP_COULDNT_STOR_FILE:	/* failed FTP upload */           fprintf(stderr, "Couldn't STOR the file\n");           log("Couldn't STOR the file\n");           break;        case CURLE_READ_ERROR:	/* could open/read from file */           fprintf(stderr, "Couldn't open temp file\n");           log("Couldn't open temp file\n");           break;        case CURLE_OUT_OF_MEMORY:           fprintf(stderr, "Out of memory\n");           log("Out of memory\n");           break;        case CURLE_OPERATION_TIMEOUTED:	/* the timeout time was reached */           fprintf(stderr, "Upload timed out\n");           log("Upload timed out\n");           break;        case CURLE_FTP_PORT_FAILED:	/* FTP PORT operation failed */           fprintf(stderr, "ftp PORT failed\n");           log("ftp PORT failed\n");           break;        case CURLE_FILE_COULDNT_READ_FILE:           fprintf(stderr, "Couldn't read temp file\n");           log("Couldn't read temp file\n");           break;        default:           fprintf(stderr, "unknown error, attempting to continue\n");           log("unknown error, attempting to continue\n");           break;      }   }   /* cleanup curl stuff */   curl_easy_cleanup(curl_handle);   curl_slist_free_all(post_commands);   free(url_string);   free(passwd_string);   fclose(infile);}intmain(int argc, char *argv[]){   unsigned char *val;   Imlib_Image image;   char filename[100];   int width, height, i;   struct stat st;   pid_t childpid;   time_t start_shot;   time_t end_shot;   int just_shot = 0;   int new_delay;   /* fork and die */   if ((childpid = fork()) < 0)   {      fprintf(stderr, "fork (%s)\n", strerror(errno));      return (2);   }   else if (childpid > 0)      exit(0);          /* parent */   /* read config */   sprintf(filename, "%s/%s", getenv("HOME"), ".camErc");   fprintf(stderr, "reading config file: %s\n", filename);   cfg_parse_file(filename);   if (NULL != (val = cfg_get_str("ftp", "host")))      ftp_host = val;   if (NULL != (val = cfg_get_str("ftp", "user")))      ftp_user = val;   if (NULL != (val = cfg_get_str("ftp", "pass")))      ftp_pass = val;   if (NULL != (val = cfg_get_str("ftp", "dir")))      ftp_dir = val;   if (NULL != (val = cfg_get_str("ftp", "file")))      ftp_file = val;   if (NULL != (val = cfg_get_str("ftp", "tmp")))      ftp_tmp = val;   if (-1 != (i = cfg_get_int("ftp", "passive")))      ftp_passive = i;   if (-1 != (i = cfg_get_int("ftp", "debug")))      ftp_debug = i;   if (-1 != (i = cfg_get_int("ftp", "do")))      ftp_do = i;   if (-1 != (i = cfg_get_int("ftp", "timeout")))      ftp_timeout = i;   if (NULL != (val = cfg_get_str("scp", "target")))      scp_target = val;   if (NULL != (val = cfg_get_str("grab", "device")))      grab_device = val;   if (NULL != (val = cfg_get_str("grab", "text")))      grab_text = val;   if (NULL != (val = cfg_get_str("grab", "infofile")))      grab_infofile = val;   if (NULL != (val = cfg_get_str("grab", "action_pre_shot")))      action_pre_shot = val;   if (NULL != (val = cfg_get_str("grab", "action_post_shot")))      action_post_shot = val;   if (NULL != (val = cfg_get_str("grab", "action_post_upload")))      action_post_upload = val;   if (NULL != (val = cfg_get_str("grab", "archive")))      grab_archive = val;   if (NULL != (val = cfg_get_str("grab", "blockfile")))      grab_blockfile = val;   if (NULL != (val = cfg_get_str("grab", "uploadblockfile")))      upload_blockfile = val;   if (NULL != (val = cfg_get_str("grab", "postprocess")))      grab_postprocess = val;   if (NULL != (val = cfg_get_str("grab", "title_text")))      title_text = val;   if (NULL != (val = cfg_get_str("grab", "logfile")))      logfile = val;   if (NULL != (val = cfg_get_str("grab", "ttf_dir")))      ttf_dir = val;   if (NULL != (val = cfg_get_str("grab", "title_font")))      title_font = val;   if (NULL != (val = cfg_get_str("grab", "text_font")))      text_font = val;   if (NULL != (val = cfg_get_str("grab", "temp_file")))      temp_file = val;   if (NULL != (val = cfg_get_str("grab", "title_style")))      title_style_file = val;   if (NULL != (val = cfg_get_str("grab", "text_style")))      text_style_file = val;   if (NULL != (val = cfg_get_str("grab", "overlay_image")))      overlay_file = val;   if (-1 != (i = cfg_get_int("grab", "width")))      grab_width = i;   if (-1 != (i = cfg_get_int("grab", "height")))      grab_height = i;   if (-1 != (i = cfg_get_int("grab", "delay")))      grab_delay = i;   if (-1 != (i = cfg_get_int("grab", "correct")))      delay_correct = 1;   if (-1 != (i = cfg_get_int("grab", "percent")))      bw_percent = i;   if (-1 != (i = cfg_get_int("grab", "quality")))      grab_quality = i;   if (-1 != (i = cfg_get_int("grab", "input")))      grab_input = i;   if (-1 != (i = cfg_get_int("grab", "norm")))      grab_norm = i;   if (-1 != (i = cfg_get_int("grab", "text_r")))      text_r = i;   if (-1 != (i = cfg_get_int("grab", "text_g")))      text_g = i;   if (-1 != (i = cfg_get_int("grab", "text_b")))      text_b = i;   if (-1 != (i = cfg_get_int("grab", "text_a")))      text_a = i;   if (-1 != (i = cfg_get_int("grab", "title_r")))      title_r = i;   if (-1 != (i = cfg_get_int("grab", "title_g")))      title_g = i;   if (-1 != (i = cfg_get_int("grab", "title_b")))      title_b = i;   if (-1 != (i = cfg_get_int("grab", "title_a")))      title_a = i;   if (-1 != (i = cfg_get_int("grab", "bg_r")))      bg_r = i;   if (-1 != (i = cfg_get_int("grab", "bg_g")))      bg_g = i;   if (-1 != (i = cfg_get_int("grab", "bg_b")))      bg_b = i;   if (-1 != (i = cfg_get_int("grab", "bg_a")))      bg_a = i;   if (-1 != (i = cfg_get_int("grab", "close_dev")))      close_dev = i;   if (-1 != (i = cfg_get_int("grab", "lag_reduce")))      lag_reduce = i;   if (-1 != (i = cfg_get_int("grab", "overlay_x")))      overlay_x = i;   if (-1 != (i = cfg_get_int("grab", "overlay_y")))      overlay_y = i;   /* print config */   fprintf(stderr, "camE v0.6 - (c) 1999, 2000 Gerd Knorr, Tom Gilbert\n");   fprintf(stderr,           "grabber config: size %dx%d, input %d, norm %d, "           "jpeg quality %d\n", grab_width, grab_height, grab_input,           grab_norm, grab_quality);   if (ftp_do)      fprintf(stderr, "ftp config:\n  %s@%s:%s\n  %s => %s\n", ftp_user,              ftp_host, ftp_dir, ftp_tmp, ftp_file);   /* init everything */   grab_init();   imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT);   imlib_add_path_to_font_path(ttf_dir);   imlib_add_path_to_font_path(".");   imlib_context_set_operation(IMLIB_OP_COPY);   if (title_style_file)      title_style = gib_style_new_from_ascii(title_style_file);   if (text_style_file)      text_style = gib_style_new_from_ascii(text_style_file);   if (overlay_file)      overlay_im = imlib_load_image(overlay_file);   title_fn = imlib_load_font(title_font);   if (!title_fn)      fprintf(stderr, "can't load font %s\n", title_font);   text_fn = imlib_load_font(text_font);   if (!text_fn)      fprintf(stderr, "can't load font %s\n", text_font);   /* go! */   for (;;)   {      just_shot = 0;      end_shot = 0;      start_shot = 0;      if (grab_blockfile && (stat(grab_blockfile, &st) == -1))      {         time(&start_shot);         if (action_pre_shot)         {            log("running pre-shot action\n");            system(action_pre_shot);         }         log("* taking shot\n");         /* Prevent camera lag... */         image = grab_one(&width, &height);         imlib_context_set_image(image);         if (!image)         {            fprintf(stderr, "no image captured\n");            exit(2);         }         log("** shot taken\n");         if (action_post_shot)         {            log("running post-shot action\n");            system(action_post_shot);         }         if (overlay_im)            draw_overlay(image);         add_time_text(image, get_message(), width, height);         gib_imlib_save_image(image, temp_file);         do_postprocess(temp_file);         archive_jpeg(image);         if (ftp_do)         {            if (upload_blockfile && (stat(upload_blockfile, &st) == -1))            {               log("*** uploading via ftp\n");               ftp_upload1(temp_file, ftp_file, ftp_tmp);               log("shot uploaded\n");               if (action_post_upload)               {                  log("running post upload action\n");                  system(action_post_upload);               }            }         }         else if (scp_target)         {            char buf[4096];            if (upload_blockfile && (stat(upload_blockfile, &st) == -1))            {               log("uploading via scp\n");               snprintf(buf, sizeof(buf), "scp -BCq %s %s", temp_file,                        scp_target);               system(buf);               log("shot uploaded\n");               if (action_post_upload)               {                  log("running post upload action\n");                  system(action_post_upload);               }            }         }         gib_imlib_free_image_and_decache(image);         just_shot = 1;         time(&end_shot);      }      new_delay = grab_delay;      if (just_shot)      {         end_shot = end_shot - start_shot;         if (bw_percent < 100)            bw_res_change(end_shot);         if (delay_correct && end_shot)         {            new_delay -= end_shot;            if (new_delay < 0)               new_delay = 0;            log("Sleeping %d secs (corrected)\n", new_delay);         }         else         {            log("Sleeping %d secs\n", grab_delay);         }      }      if (new_delay > 0)         sleep(new_delay);   }   return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -