First cut. Distintly raw around the edges:
* Assumes it will be running in /home/ali/wk/slashem/web.scripts
* Assumes cache directory will be in topdir
* No build system (simple compiling and linking against libxml2)
* No configure system (eg., tagsoup)
* Output XML untested
* Doesn't set bugzilla maintainer or exporter
* Handling of artifact priorities and resolution is suspect
2 * This program converts an attached file (which has previously been
3 * downloaded from sourceforge) into bugzilla-style XML.
14 static struct option long_options[] = {
21 static char *long_option_str(char opt)
25 for(i=0;long_options[i].name;i++)
26 if (long_options[i].val==opt)
28 sprintf(buf,", --%s",long_options[i].name);
34 #define long_option_str(opt) ""
39 fprintf(stderr,"Usage: xml_attached_file [OPTION] file\n");
41 fprintf(stderr," -t%s=MIME-type MIME type to use\n",
42 long_option_str('t'));
43 fprintf(stderr," -i%s=ID Attachment ID to use\n",
44 long_option_str('i'));
45 fprintf(stderr," -p%s Mark attachment as a patch\n",
46 long_option_str('p'));
50 /* Note that we limit line lengths to 76 characters following RFC 2045
51 * (bugzilla uses MIME::Base64). This isn't strictly compliant with RFC 4648.
53 static void base64_encode(FILE *in,FILE *out)
55 int ng=0; /* 76 characters == 19 groups */
57 unsigned char bytes[3];
58 const char alphabet[64]=
59 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
60 while ((nb=fread(bytes,1,3,in))==3)
67 putc(alphabet[bytes[0]>>2],out);
68 putc(alphabet[(bytes[0]<<4|bytes[1]>>4)&0x3F],out);
69 putc(alphabet[(bytes[1]<<2|bytes[2]>>6)&0x3F],out);
70 putc(alphabet[bytes[2]&0x3F],out);
76 putc(alphabet[bytes[0]>>2],out);
79 putc(alphabet[(bytes[0]<<4|bytes[1]>>4)&0x3F],out);
80 putc(alphabet[bytes[1]<<2&0x3F],out);
84 putc(alphabet[bytes[0]<<4&0x3F],out);
91 int main(int argc,char **argv)
102 c=getopt_long(argc,argv,"t:i:p",long_options,&option_index);
104 c=getopt(argc,argv,"t:i:p");
114 id=strtoul(optarg,NULL,10);
125 fp=fopen(argv[optind],"rb");
128 perror(argv[optind]);
134 printf("<attachment ispatch=\"%d\">\n",ispatch);
136 printf(" <attachid>%lu</attachid>\n",id);
138 printf(" <type>%s</type>\n",type);
139 printf(" <data encoding=\"base64\">\n");
140 base64_encode(fp,stdout);
141 printf("\n </data>\n");
142 printf("</attachment>\n");