コード例 #1
0
BOOL CAppOctetStream::AppendPart(LPCTSTR szContent, 
								 LPCTSTR szParameters, 
								 int nEncoding, 
								 BOOL bPath, 
								 CString & sDestination)
{
	CStdioFile fAttachment;

	// This class handles only file attachments, so
	// it ignores the bPath parameter.
	if( szContent == NULL )
		return FALSE;
	if( !fAttachment.Open( szContent, (CFile::modeRead | CFile::shareDenyWrite | CFile::typeBinary) ) )
		return FALSE;
	sDestination += build_sub_header( szContent,
								      szParameters,
									  nEncoding,
									  TRUE );
	attach_file( &fAttachment, CMIMEMessage::BASE64, sDestination );
	fAttachment.Close();
	return TRUE;
}
コード例 #2
0
ファイル: chelper.c プロジェクト: queer1/forge
main (int argc, char **argv) {
  char *params[10], *lodevice;
  char *prefix, *fname, *mountpoint;
  pid_t pid, cluster_size=0;
  int status,opt=0,q=0;
  long size=0;

#ifdef PATH  
  if (strlen(PATH) > MAX_PATH_LENGTH) {
    fprintf(stderr, "too long PATH\n");
    exit(1);
  }
  prefix = malloc(sizeof(char)*strlen(PATH)+1);
  if (prefix == NULL) {
    perror(PNAME);
    exit(1);
  }
  strcpy (prefix,PATH);
#else
#error "must define PATH"
#endif

#ifdef MOUNTPOINT
  if (strlen(MOUNTPOINT) > MAX_PATH_LENGTH) {
    fprintf(stderr, "too long MOUNTPOINT\n");
    exit(1);
  }
  mountpoint = malloc(sizeof(char)*strlen(MOUNTPOINT)+1);
  if (mountpoint == NULL) {
    perror(PNAME);
    exit(1);
  }
  strcpy (mountpoint,MOUNTPOINT);
  sanitize_path(mountpoint);
#else
#error "must define MOUNTPOINT"
#endif

  if (argc < 2) {
    fprintf(stderr,"Usage: %s [create fstype size cluster_size name [clean | random] filename | attach fstype filename | detach]\n", PNAME);
    exit(1);
  }

  if (strcmp(argv[1], "create") == 0) {
    if (argc < 2) {
      fprintf(stderr,"Usage: %s create ntfs|FAT16 ...\n", PNAME);
      exit(1);
    }
    if (strcmp(argv[2], "ntfs") == 0) {
      if (argc != 8) {
	fprintf(stderr,"Usage: %s create fstype size cluster_size name [clean | random] filename\n", PNAME);
	exit(1);
      }
      /* freopen("/dev/null","w",stderr);*/
      if (strlen(argv[3]) > 12) {
	fprintf(stderr,"Too long size parameter\n");
	exit(1);
      }
      size = calculate_size(argv[3]);
      if (strlen(argv[7]) > MAX_PATH_LENGTH) {
	fprintf(stderr, "Too long parameter %s\n", argv[7]);
	exit(1);
      }
      fname = malloc(sizeof(char)*strlen(argv[7])+1);
      if (fname == NULL) {
	perror(PNAME);
	exit(1);
      }
      strcpy(fname, argv[7]);
      if ((atoi(argv[4]) < 1 || atoi (argv[4]) > 32) || atoi(argv[4]) & 1) {
	fprintf(stderr,"Cluster size must be a multiple of 2 and max 32\n");
	exit(1);
      }
      cluster_size = atoi(argv[4])*512;

      /* Generally we could be more allowing here but use the same routine
	 for reasons of pure laziness. 
	 Technically only white space, ?, *, " and ' should be really 
	 frowned upon here 
      */
      sanitize_path(argv[5]);
      if (strlen(argv[5]) > 20) {
	fprintf(stderr, "too long parameter %s", argv[5]);
	exit(1);
      }
      if (strcmp(argv[6], "random") == 0) {
	create_file(prefix, fname, size, C_RANDOM);
      } 
      else {
	create_file(prefix, fname, size, C_ZERO);
      }
      create_ntfs_filesystem(prefix, fname, argv[5], cluster_size);
      exit(0);
    }
    if ((strcmp(argv[2], "FAT16") == 0) || (strcmp(argv[2],"FAT32") == 0) || (strcmp(argv[2], "FAT12") == 0) || 
	(strcmp(argv[2], "GENERICFAT") == 0)) {
      if (argc != 9) {
	fprintf(stderr,"Usage: %s create FAT16|FAT12|FAT32 size cluster_size sector_size name [clean | random] filename\n", PNAME);
	exit(1);
      }
      /* freopen("/dev/null","w",stderr);*/
      if (strlen(argv[3]) > 12) {
	fprintf(stderr,"Too long size parameter\n");
	exit(1);
      }
      size = calculate_size(argv[3]);
      if (strlen(argv[8]) > MAX_PATH_LENGTH) {
	fprintf(stderr, "Too long parameter %s\n", argv[8]);
	exit(1);
      }
      fname = malloc(sizeof(char)*strlen(argv[7])+1);
      if (fname == NULL) {
	perror(PNAME);
	exit(1);
      }
      strcpy(fname, argv[8]);
      if ((atoi(argv[4]) < 1 || atoi (argv[4]) > 32) || atoi(argv[4]) & 1) {
	fprintf(stderr,"Cluster size must be a multiple of 2 and max 32\n");
	exit(1);
      }
      cluster_size = atoi(argv[4])*512;
      if ((atoi(argv[5]) < 512 || atoi (argv[5]) > 32768) || (atoi(argv[5]) & (atoi(argv[5])-1))) {
	fprintf(stderr,"Sector size must be a multiple of 512, max 32768 and a power of two\n");
	exit(1);
      }
      /* Generally we could be more allowing here but use the same routine
	 for reasons of pure laziness. 
	 Technically only white space, ?, *, " and ' should be really 
	 frowned upon here 
      */
      sanitize_path(argv[6]);
      if (strlen(argv[6]) > 11) {
	fprintf(stderr, "too long parameter %s (max 11 chars)\n", argv[6]);
	exit(1);
      }

      if (strcmp(argv[7], "random") == 0) {
	create_file(prefix, fname, size, C_RANDOM);
      } 
      else {
	create_file(prefix, fname, size, C_ZERO);
      }

      create_fat_filesystem(prefix, argv[2], fname, argv[6], atoi(argv[5]),argv[4]);
      exit(0);
    }
    else {
      fprintf(stderr, "Unknown file system type %s\n", argv[2]);
      exit(1);
    }
  }    


  
  /* Attach */
  if (strcmp(argv[1], "attach") == 0) {
    if (argc != 4) {
      fprintf(stderr,"Usage: %s attach fstype filename\n", PNAME);
      exit(1);
    }
    if (strlen(argv[3]) > MAX_PATH_LENGTH) {
      fprintf(stderr, "Too long parameter %s\n", argv[3]);
      exit(1);
    }
    fname = malloc(sizeof(char)*strlen(argv[3])+1);
    if (fname == NULL) {
      perror(PNAME);
      exit(1);
    }
    strcpy(fname, argv[3]);
    lodevice = attach_file(prefix,fname);
    if (lodevice) {
      if (strcmp(argv[2],"ntfs") == 0) {
	q = mount_ntfs_filesystem(lodevice);
	if (q != 0) 
	  detach_device(lodevice);
	exit(q);
      }
      if (strncmp(argv[2], "FAT",3 ) == 0) {
	q = mount_fat_filesystem(lodevice);
	if (q != 0)
	  detach_device(lodevice);
	exit(q);
      }
      else {
	fprintf(stderr, "unknown file system type %s\n", argv[2]);
	detach_device(lodevice);
	exit(1);
      }
    }
    else
      fprintf (stderr, "Cannot find loopback device\n");
    exit(0);
  }
  
  /* detach */
  if (strcmp(argv[1], "detach") == 0) {
    freopen("/dev/null","w",stderr);
    exit(detach_image());
  }
  fprintf(stderr,"Usage: %s [create fstype size cluster_size name [clean | random] filename | attach fstype filename | detach]\n", PNAME);  
  exit(1);
}
コード例 #3
0
ファイル: attrach.c プロジェクト: Cyberpuke/Attrach
int main( int ac, char* av[])
{

    int c;

    if (ac == 1)
        error_exit(ATTRACH_ERR_USAGE);

    while (1) 
    {
        int option_index = 0;
        static struct option long_options[] = {
            {"verbose", 0, 0, 'v'},
            {"attribute", 1, 0, 'a'},
            {"version", 0, 0, 'V'},
            {"help", 0, 0, 'h'},
            {0, 0, 0, 0}
        };
        c = getopt_long (ac, av, "va:Vh",
                long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
            case 'V':
                show_version();
                exit(0);
                break;
            case 'a':
                strcpy(attribute_name, optarg);
                break;
            case 'h':
                show_usage();
                exit(0);
                break;
            case 'v':
                verbose_flag = ATTRACH_VERBOSE_ON;
                break;
            default:
                /* invalid switch, so failing */
                error_exit(ATTRACH_ERR_SWITCH);
        }
    }

    if (!strcmp(av[optind], "attach")){
        if (ac - optind != 3)
            error_exit(ATTRACH_ERR_USAGE);

        if (attach_file(av[optind+1], av[optind+2])) {
            printf("made it\n");
            error_exit(ATTRACH_ERR_ATTACH);
        }
    } else if (!strcmp(av[optind], "get")) {
        if (ac - optind != 3)
            error_exit(ATTRACH_ERR_USAGE);

        if (retrieve_file(av[optind+1], av[optind+2])) {
            error_exit(ATTRACH_ERR_RETRIEVE);
        }
    } else if (!strcmp(av[optind], "remove")) {
        if (ac - optind != 2)
            error_exit(ATTRACH_ERR_USAGE);

        if (remove_attribute(av[optind+1])) {
            error_exit(ATTRACH_ERR_REMOVE);
        }
    } else {
        show_usage(); 
        exit(1);
    }

    return 0;
}