Пример #1
0
/* rename file after upload */
static void fetch_rename(fetch_curl_t *ft, const char *effective_url)
{
  char *name;
  char *destname;
  int rc;
  int fd;

  if (strncasecmp(ft->name, "AUTO", 4) != 0) /* NOTRANSLATE */
    return;

  name = fetch_get_filename(ft, effective_url);
  if (name == NULL)
    return;

  destname = mystrjoin(ft->uploaddir, name, '/');
  fd = open(destname, O_RDONLY | ADDED_OPEN_FLAGS);
  if (fd >= 0) {
    close(fd);
    outerror(OUTERROR_TYPE_WARN_LOUD, "File %s could not be moved to %s: %s",
             ft->name, name, strerror(EEXIST));
  } else {
    rc = rename(ft->fullname, destname);
    if (rc < 0) {
      outerror(OUTERROR_TYPE_WARN_LOUD, "File %s could not be moved to %s: %s",
               ft->name, name, strerror(errno));
    } else {
      a_respond(&(ft->u), "fetched: '%s'", destname);
    }
  }
  mydelete(destname);
  mydelete(name);
}
Пример #2
0
/* open file on disk for upload */
int l_setup_file(upload * const l, struct stat *stp)
{
  char *fullfile;
  int retval;

  updatecontext();

  if (l->uploaddir == NULL) {
    l_closeconn(l, "No uploaddir defined.", 0);
    return 1;
  }

  /* local file already exists? */
  fullfile = mystrjoin(l->uploaddir, l->file, '/');

  l->filedescriptor = open(fullfile,
                           O_WRONLY | O_CREAT | O_EXCL | ADDED_OPEN_FLAGS,
                           CREAT_PERMISSIONS );

  if ((l->filedescriptor < 0) && (errno == EEXIST)) {
    retval = stat(fullfile, stp);
    if (retval < 0) {
      outerror(OUTERROR_TYPE_WARN_LOUD, "Cant Stat Upload File '%s': %s",
               fullfile, strerror(errno));
      l_closeconn(l, "File Error, File couldn't be opened for writing", errno);
      mydelete(fullfile);
      return 1;
    }
    if (!S_ISREG(stp->st_mode) || (stp->st_size >= l->totalsize)) {
      l_closeconn(l, "File Error, That filename already exists", 0);
      mydelete(fullfile);
      return 1;
    }
    l->filedescriptor = open(fullfile, O_WRONLY | O_APPEND | ADDED_OPEN_FLAGS);
    if (l->filedescriptor >= 0) {
      l->resumesize = l->bytesgot = stp->st_size;
      if (l->resumed <= 0) {
        close(l->filedescriptor);
        mydelete(fullfile);
        return 2; /* RESUME */
      }
    }
  }
  if (l->filedescriptor < 0) {
    outerror(OUTERROR_TYPE_WARN_LOUD, "Cant Access Upload File '%s': %s",
             fullfile, strerror(errno));
    l_closeconn(l, "File Error, File couldn't be opened for writing", errno);
    mydelete(fullfile);
    return 1;
  }
  mydelete(fullfile);
  return 0;
}
Пример #3
0
int main(void) {
    char t1[] = "hello";
    char t2[] = " world";
    char t3[50];
    char t4[50];
    int n = strlen(t1);

    printf("%s%s\n", t1, t2);
    mystrjoin(t3, t1, t2);
    printf("%s\n", t3);
    strcpy(t4, t1);
    mystrcat(t1, t2);
    printf("%s\n", t1);
    strcat(t4, t2);
    printf("%s\n", t4);
    strcpy(t1 + n, " and goodbye");
    printf("%s\n", t1);
    return 0;
}
Пример #4
0
/* start a transfer now */
static void fetch_now(const userinput *const u, const char *uploaddir, char *name, char *url)
{
  off_t resumesize;
  fetch_curl_t *ft;
  char *fullfile;
  FILE *writefd;
  struct stat s;
  int retval;

  resumesize = 0;
  fullfile = mystrjoin(uploaddir, name, '/');
  writefd = fopen(fullfile, "w+x"); /* NOTRANSLATE */
  if ((writefd == NULL) && (errno == EEXIST)) {
    retval = stat(fullfile, &s);
    if (retval < 0) {
      outerror(OUTERROR_TYPE_WARN_LOUD, "Cant Stat Upload File '%s': %s",
               fullfile, strerror(errno));
      a_respond(u, "File Error, File couldn't be opened for writing");
      mydelete(fullfile);
      return;
    }
    resumesize = s.st_size;
    writefd = fopen(fullfile, "a+"); /* NOTRANSLATE */
  }
  if (writefd == NULL) {
    outerror(OUTERROR_TYPE_WARN_LOUD, "Cant Access Upload File '%s': %s",
             fullfile, strerror(errno));
    a_respond(u, "File Error, File couldn't be opened for writing");
    mydelete(fullfile);
    return;
  }

  updatecontext();
  ft = irlist_add(&fetch_trans, sizeof(fetch_curl_t));
  ft->u.method = u->method;
  if (u->snick != NULL) {
    ft->u.snick = mystrdup(u->snick);
  }
  ft->u.fd = u->fd;
  ft->u.chat = u->chat;
  ft->id = ++fetch_id;
  ft->net = gnetwork->net;
  ft->name = mystrdup(name);
  ft->url = mystrdup(url);
  ft->uploaddir = mystrdup(uploaddir);
  ft->fullname = fullfile;
  fullfile = NULL;
  ft->writefd = writefd;
  ft->resumesize = resumesize;
  ft->errorbuf = mymalloc(CURL_ERROR_SIZE);
  ft->errorbuf[0] = 0;
  ft->starttime = gdata.curtime;

  if (curl_fetch(u, ft)) {
    clean_fetch(ft);
    return;
  }

  a_respond(u, "fetch '%s' started", ft->name);
  ++fetch_started;
}