Esempio n. 1
0
word FindProtocol(sword protocol, struct _proto *pro)
{
  char fname[PATHLEN], *p;
  long seekit;
  word ret=FALSE;
  int fd;
  
  /* Handle a user-specified protocol.max file */

  p=PRM(protocol_max);

  if (*p)
    strcpy(fname, p);
  else sprintf(fname, "%sprotocol.max", PRM(sys_path));
  
  if ((fd=shopen(fname, O_RDONLY | O_BINARY | O_NOINHERIT))==-1)
  {
    cant_open(fname);
    return FALSE;
  }
  
  seekit=sizeof(struct _proto)*protocol;

  if (lseek(fd, seekit, SEEK_SET)==seekit &&
      read(fd, (char *)pro, sizeof(struct _proto))==sizeof(struct _proto))
  {
    ret=TRUE;
  }
  
  close(fd);
  
  return ret;
}
Esempio n. 2
0
File: main.cpp Progetto: dendy/grim
int main( int argc, char ** argv )
{
	QApplication app( argc, argv );

	if ( argc < 2 )
		return usage();

	const QString fileName = QString::fromLocal8Bit( argv[1] );
	Grim::Archive archive( fileName );

	if ( !archive.open( Grim::Archive::ReadOnly | Grim::Archive::Block ) )
		return cant_open( fileName );

	if ( archive.isBroken() )
		return not_a_zip( fileName );

	printf( "Listing files in archive...\n\n" );

	for ( QDirIterator it( fileName, QDirIterator::Subdirectories ); it.hasNext(); )
	{
		it.next();
		printf( "%s\n", qPrintable( it.filePath() ) );
	}

	return 0;
}
Esempio n. 3
0
void Open_OpusXfer(FILE **xferinfo)
{
  char xname[PATHLEN];

  sprintf(xname, opusxfer_name, original_path, task_num);

  if ((*xferinfo=shfopen(xname, fopen_write, O_WRONLY|O_TRUNC|O_CREAT|O_NOINHERIT))==NULL)
    cant_open(xname);
}
Esempio n. 4
0
int IsInUserList(char *name, int show_us)
{
  struct _usr user;
  HUF huf;
  int rc;

  /* Try to open the user file */

  if ((huf=UserFileOpen(PRM(user_file), 0))==NULL)
  {
    cant_open(PRM(user_file));
    return FALSE;
  }

  rc=UserFileFind(huf, name, NULL, &user) ||
     UserFileFind(huf, NULL, name, &user);

  if (!show_us && (eqstri(name, usr.name) || eqstri(name, usr.alias)))
    rc=FALSE;

  UserFileClose(huf);

  return rc;
}
Esempio n. 5
0
void MaxWriteCtl(struct _proto *pro, word ul)
{
  FILE *ctl;
  char fname[PATHLEN];
  word n;
  long bd=steady_baud_l ? steady_baud_l : baud;

  FENTRY fent;

  /* Delete any preexisting log file */

  Parse_Outside_Cmd(pro->log, fname);
  unlink(fname);
  
  
  /* Handle the "%" translation characters */

  Parse_Outside_Cmd(pro->ctl, fname);
  
  if ((ctl=fopen(fname, fopen_write))==NULL)
  {
    cant_open(fname);
    return;
  }

  /* If we need to handle an Opus-style control file, do so now */

  if (pro->flag & P_OPUS)
  {
    if (local)
      fprintf(ctl, xctl_keyboard);
    else fprintf(ctl, xctl_port_baud, port+1, bd);

    if (!local)
      fprintf(ctl, xctl_modem,
              port+1, bd,
              prm.handshake_mask /* 3 */, prm.carrier_mask, baud);

    fprintf(ctl, xctl_time, timeleft());

    if (log_name && *log_name)
      fprintf(ctl, xctl_log, log_name);

    fprintf(ctl, xctl_msgs, MAS(mah, path));
    fprintf(ctl, xctl_uploads, FAS(fah, uppath));
    fprintf(ctl, xctl_downloads, FAS(fah, downpath));
    fprintf(ctl, xctl_help,  original_path);
  
    if (fah.heap)
    {
      if (*FAS(fah, filesbbs))
        fprintf(ctl, xctl_filesbbs, FAS(fah, filesbbs));
    }
  }

  /* Now write out the names of the files to send */

  for (n=0; GetFileEntry(n, &fent); n++)
  {
    fprintf(ctl, ul ? pro->ulstr : pro->dlstr, fent.szName);
    fputc('\n', ctl);
  }

  /* Close the control file */

  fclose(ctl);
}
Esempio n. 6
0
word MaxReadLog(struct _proto *pro, word doing_ul)
{
  FILE *log;

  #define LOGLEN 255
  char fname[PATHLEN];
  char line[LOGLEN];
  word gotfile=FALSE;
  char tempname[PATHLEN];

  FENTRY fent;

  /* Handle the "%" translation characters */

  Parse_Outside_Cmd(pro->log, fname);
  
  if ((log=fopen(fname, fopen_read))==NULL)
  {
    cant_open(fname);
    return FALSE;
  }

  while (fgets(line, LOGLEN, log))
  {
    char *ulstr, *dlstr, *got, *desc;
    word ul;
    word fn;
    
    /* Find the positions of the upload and download strings */

    dlstr=strstr(line, pro->dlkey);
    ulstr=strstr(line, pro->ulkey);

    if (ulstr==NULL && dlstr==NULL)
      continue;

    if (pro->flag & P_BI)
    {
      /* Use whichever token comes FIRST in the log line, since we might    *
       * see either.                                                        */
      
      ul=(ulstr && (dlstr==NULL || ulstr < dlstr));
      got=(ul ? ulstr : dlstr);
    }
    else
    {
      /* Otherwise, just get the one that was requested */

      ul=doing_ul;
      
      got=(ul ? ulstr : dlstr);

      if (!got)
        continue;
    }

    /* Now copy the filename, based on the word# we're supposed to get. */

    getword(got, fname, ctl_delim, pro->fnamword+1);

    /* Skip it if we didn't get anything */

    if (*fname=='\0')
      continue;
    
    /* Now figure out if we requested this file or not... */
    
    for (fn=0; GetFileEntry(fn, &fent); fn++)
      if (eqstri(No_Path(fent.szName), No_Path(fname)))
        break;

    if (fn==FileEntries())
      memset(&fent, 0, sizeof fent);
      
    /* Grab the description, if any */

    desc=pro->descword ? firstchar(got, ctl_delim, pro->descword) : NULL;

    if (desc)
      fent.szDesc=desc;

    /* If we're doing an upload, strip the path specification */

    if (ul)
    {
      strcpy(tempname, No_Path(fname));
      fent.szName=tempname;

      /* Now figure out the fully-qualified path/name of the file so
       * that we can get the correct size.
       */

      sprintf(fname, ss, FAS(fah, uppath), fent.szName);
    }
    else
    {
      fent.szName=fname;
    }

    /* Now get the size of this file */
    
    fent.ulSize = fsize(fent.szName);

    if (ul)
    {
      logit(log_ul, *pro->desc, FAS(fah, uppath), fent.szName);
      fent.fFlags |= FFLAG_GOT;
    }
    else
    {
      fent.fFlags |= FFLAG_SENT;
    }

    UpdFileEntry(fn, &fent);
    gotfile=TRUE;
  }

  fclose(log);

  /* If the transfer was successful, delete both the .CTL and .LOG files */

  if (gotfile)
  {
    Parse_Outside_Cmd(pro->log, fname);
    unlink(fname);

    Parse_Outside_Cmd(pro->ctl, fname);
    unlink(fname);
  }
  
  return gotfile;
}
Esempio n. 7
0
int RIP_SendFile(char *pszFile, int fDisplay)
{
  int   rc=TRUE;
  char *p2;

  if (!hasRIP())
    return SENDRIP_ERROR;

  logit("@rip_sendfile(%s,%s)", pszFile, fDisplay ? "true" : "false");

  /* Save current download tag list so that the user doesn't lose it */

  save_tag_list(NULL);
  Free_Filenames_Buffer(0);

  p2=pszFile;

  while (rc)
  {
    int   filegroup =0,
          forcesend =0;
    char *p1;

    p1=p2 + strspn(p2,cmd_delim);     /* This avoids use of strtok() */
    p2=p1 + strcspn(p1,cmd_delim);    /* which is not reentrant */

    if (*p2)
      *p2++ = '\0';

    if (!*p1)             /* At end of string */
      break;

    for (;;)
    {
      if (*p1=='@')       /* @filename is a list of files */
        ++filegroup;
      else if (*p1=='!')  /* !filename forces file(s) to be sent */
        ++forcesend;          /* even if we already know they have been */
      else
        break;
      ++p1;
    }

    /* Handle single file send */

    if (!filegroup)
    {
      int send_rc = sendrip(p1,fDisplay,forcesend);
      rc = (send_rc==SENDRIP_FILESENT || send_rc==SENDRIP_ALREADYHAS);
    }
    else
    {
      /* Handle multi-file send */

      FILE  *fp = shfopen(p1, fopen_read, O_RDONLY);

      if (fp==NULL)
      {
        cant_open(p1);
        rc=FALSE;
      }
      else
      {
        char  temp[PATHLEN];

        while (rc && fgets(temp,PATHLEN-1,fp)!=NULL)
        {
          char *s2;

          s2=temp;
          for (;;)
          {
            int force = forcesend;
            int send_rc;
            char *s1;

            s1=s2 + strspn(s2,cmd_delim);
            s2=s1 + strcspn(s1,cmd_delim);

            if (*s2)
              *s2++ = '\0';

            if (!*s1)
              break;

            if (*s1 == '!')
            {
              ++s1;
              ++force;
            }

            send_rc=sendrip(s1, fDisplay, force);
            rc = (send_rc==SENDRIP_FILESENT || send_rc==SENDRIP_ALREADYHAS);
          }
        }
        fclose(fp);
      }
    }
  }

  /* If we've got any files to send, send them all now */

  if (rc)
    ripsendbatch(fDisplay);

  /* Restore the user's download tag list */

  restore_tag_list(NULL,FALSE);

  return rc;
}
Esempio n. 8
0
static int near sendrip(char *pszFile, int fDisplay, int force)
{
  int sendit;
  long filesize;
  char temp[PATHLEN];

  if (!hasRIP())
    return SENDRIP_ERROR;

  logit("@sendrip(%s,%s,%d)", pszFile, fDisplay ? "true" : "false", force);

  /* Get qualified filename for file to send */

  strcpy(temp, rippath);
  Add_Trailing(temp, PATH_DELIM);
  strcat(temp, pszFile);

  /* See if it exists in the current RIP path */

  if ((filesize=fsize(temp))==-1L)
  {

    /* Ok, then try the default RIP path */

    strcpy(temp, PRM(rippath));
    Add_Trailing(temp, PATH_DELIM);
    strcat(temp, pszFile);

    if ((filesize=fexist(temp))==-1)
    {

      /* Report it as an error and quit */

      cant_open(temp);
      return SENDRIP_FILENOTEXIST;
    }
  }

  sendit=!ripfilesent(temp);

  /* Query remote if send is forced or file hasn't
   * yet been sent in this session
   */

  if (force || sendit)
  {
    int hasit=RIP_HasFile(pszFile,&filesize);

    if (hasit==-1)
      return SENDRIP_ERROR;    /* RIP query aborted without success */

    if (!hasit)
      sendit=TRUE;
    else
    {

      /* If we know that the remote has the file, add it to our list
       * of "sent" files. Path must also be added to ensure that the
       * same icon will be sent in case rippath changes during session
       */

      addripfile(temp);
      sendit=FALSE;
    }

  }

  /* If remote already has the file and display is true
   * Then simply tell the remote system to display it
   */

  if (!sendit)
  {
    if (fDisplay)
    {

      /* Send any files "batched" for sending prior this now
       * to ensure that the display order remains the same
       */

      if (!FileEntries() || (sendit=ripsendbatch(fDisplay)))
      {
        /* "play RIP scene" - note: icons are NOT supported here */
        /* You must send icons in batch without playback, then   */
        /* use them within RIP scenes                            */

        Printf("\r!|1R00000000%s\n", pszFile);
        sendit=TRUE;
      }
    }
  }

  /* We need to send them the file
   * Just queue it for now
   */

  else
  {

    /* Send all batched so far if we've run out of space */

    if (CanAddFileEntry() || (sendit=ripsendbatch(fDisplay)))
    {
      AddFileEntry(temp, FFLAG_NOBYTES, filesize);
      sendit=TRUE;
    }
  }

  return sendit ? SENDRIP_FILESENT : SENDRIP_ALREADYHAS;
}