ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/UUlib.xs
Revision: 1.13
Committed: Sat May 26 15:14:10 2007 UTC (16 years, 11 months ago) by root
Branch: MAIN
CVS Tags: rel-1_11, rel-1_10, rel-1_12, rel-1_09
Changes since 1.12: +100 -116 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5     #include "uulib/fptools.h"
6 root 1.2 #include "uulib/uudeview.h"
7 root 1.1 #include "uulib/uuint.h"
8    
9     static int
10 root 1.8 not_here (char *s)
11 root 1.1 {
12 root 1.13 croak("%s not implemented", s);
13     return -1;
14 root 1.1 }
15    
16     static int
17 root 1.8 constant (char *name)
18 root 1.1 {
19 root 1.13 errno = 0;
20     switch (*name)
21     {
22     case 'A':
23     if (strEQ(name, "ACT_COPYING")) return UUACT_COPYING;
24     if (strEQ(name, "ACT_DECODING")) return UUACT_DECODING;
25     if (strEQ(name, "ACT_ENCODING")) return UUACT_ENCODING;
26     if (strEQ(name, "ACT_IDLE")) return UUACT_IDLE;
27     if (strEQ(name, "ACT_SCANNING")) return UUACT_SCANNING;
28     case 'F':
29     if (strEQ(name, "FILE_DECODED")) return UUFILE_DECODED;
30     if (strEQ(name, "FILE_ERROR")) return UUFILE_ERROR;
31     if (strEQ(name, "FILE_MISPART")) return UUFILE_MISPART;
32     if (strEQ(name, "FILE_NOBEGIN")) return UUFILE_NOBEGIN;
33     if (strEQ(name, "FILE_NODATA")) return UUFILE_NODATA;
34     if (strEQ(name, "FILE_NOEND")) return UUFILE_NOEND;
35     if (strEQ(name, "FILE_OK")) return UUFILE_OK;
36     if (strEQ(name, "FILE_READ")) return UUFILE_READ;
37     if (strEQ(name, "FILE_TMPFILE")) return UUFILE_TMPFILE;
38     break;
39     case 'M':
40     if (strEQ(name, "MSG_ERROR")) return UUMSG_ERROR;
41     if (strEQ(name, "MSG_FATAL")) return UUMSG_FATAL;
42     if (strEQ(name, "MSG_MESSAGE")) return UUMSG_MESSAGE;
43     if (strEQ(name, "MSG_NOTE")) return UUMSG_NOTE;
44     if (strEQ(name, "MSG_PANIC")) return UUMSG_PANIC;
45     if (strEQ(name, "MSG_WARNING")) return UUMSG_WARNING;
46     case 'O':
47     if (strEQ(name, "OPT_VERSION")) return UUOPT_VERSION;
48     if (strEQ(name, "OPT_FAST")) return UUOPT_FAST;
49     if (strEQ(name, "OPT_DUMBNESS")) return UUOPT_DUMBNESS;
50     if (strEQ(name, "OPT_BRACKPOL")) return UUOPT_BRACKPOL;
51     if (strEQ(name, "OPT_VERBOSE")) return UUOPT_VERBOSE;
52     if (strEQ(name, "OPT_DESPERATE")) return UUOPT_DESPERATE;
53     if (strEQ(name, "OPT_IGNREPLY")) return UUOPT_IGNREPLY;
54     if (strEQ(name, "OPT_OVERWRITE")) return UUOPT_OVERWRITE;
55     if (strEQ(name, "OPT_SAVEPATH")) return UUOPT_SAVEPATH;
56     if (strEQ(name, "OPT_IGNMODE")) return UUOPT_IGNMODE;
57     if (strEQ(name, "OPT_DEBUG")) return UUOPT_DEBUG;
58     if (strEQ(name, "OPT_ERRNO")) return UUOPT_ERRNO;
59     if (strEQ(name, "OPT_PROGRESS")) return UUOPT_PROGRESS;
60     if (strEQ(name, "OPT_USETEXT")) return UUOPT_USETEXT;
61     if (strEQ(name, "OPT_PREAMB")) return UUOPT_PREAMB;
62     if (strEQ(name, "OPT_TINYB64")) return UUOPT_TINYB64;
63     if (strEQ(name, "OPT_ENCEXT")) return UUOPT_ENCEXT;
64     if (strEQ(name, "OPT_REMOVE")) return UUOPT_REMOVE;
65     if (strEQ(name, "OPT_MOREMIME")) return UUOPT_MOREMIME;
66     if (strEQ(name, "OPT_DOTDOT")) return UUOPT_DOTDOT;
67     if (strEQ(name, "OPT_RBUF")) return UUOPT_RBUF;
68     if (strEQ(name, "OPT_WBUF")) return UUOPT_WBUF;
69     case 'R':
70     if (strEQ(name, "RET_CANCEL")) return UURET_CANCEL;
71     if (strEQ(name, "RET_CONT")) return UURET_CONT;
72     if (strEQ(name, "RET_EXISTS")) return UURET_EXISTS;
73     if (strEQ(name, "RET_ILLVAL")) return UURET_ILLVAL;
74     if (strEQ(name, "RET_IOERR")) return UURET_IOERR;
75     if (strEQ(name, "RET_NODATA")) return UURET_NODATA;
76     if (strEQ(name, "RET_NOEND")) return UURET_NOEND;
77     if (strEQ(name, "RET_NOMEM")) return UURET_NOMEM;
78     if (strEQ(name, "RET_OK")) return UURET_OK;
79     if (strEQ(name, "RET_UNSUP")) return UURET_UNSUP;
80     case 'B':
81     if (strEQ(name, "B64_ENCODED")) return B64ENCODED;
82     if (strEQ(name, "BH_ENCODED")) return BH_ENCODED;
83     case 'P':
84     if (strEQ(name, "PT_ENCODED")) return PT_ENCODED;
85     case 'Q':
86     if (strEQ(name, "QP_ENCODED")) return QP_ENCODED;
87     case 'U':
88     if (strEQ(name, "UU_ENCODED")) return UU_ENCODED;
89     case 'X':
90     if (strEQ(name, "XX_ENCODED")) return XX_ENCODED;
91     case 'Y':
92     if (strEQ(name, "YENC_ENCODED")) return YENC_ENCODED;
93 root 1.1 }
94 root 1.13
95     errno = EINVAL;
96     return 0;
97 root 1.1 }
98    
99 root 1.8 static void
100     uu_msg_callback (void *cb, char *msg, int level)
101 root 1.1 {
102     dSP;
103    
104 root 1.10 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
105 root 1.1
106 root 1.10 PUSHs (sv_2mortal (newSVpv (msg, 0)));
107     PUSHs (sv_2mortal (newSViv (level)));
108 root 1.1
109     PUTBACK; (void) perl_call_sv ((SV *)cb, G_VOID|G_DISCARD); SPAGAIN;
110     PUTBACK; FREETMPS; LEAVE;
111     }
112    
113 root 1.8 static int
114     uu_busy_callback (void *cb, uuprogress *uup)
115 root 1.1 {
116     dSP;
117     int count;
118     int retval;
119    
120 root 1.10 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 6);
121 root 1.1
122 root 1.10 PUSHs (sv_2mortal (newSViv (uup->action)));
123     PUSHs (sv_2mortal (newSVpv (uup->curfile, 0)));
124     PUSHs (sv_2mortal (newSViv (uup->partno)));
125     PUSHs (sv_2mortal (newSViv (uup->numparts)));
126     PUSHs (sv_2mortal (newSViv (uup->fsize)));
127     PUSHs (sv_2mortal (newSViv (uup->percent)));
128 root 1.1
129     PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
130    
131     if (count != 1)
132     croak ("busycallback perl callback returned more than one argument");
133    
134     retval = POPi;
135    
136     PUTBACK; FREETMPS; LEAVE;
137    
138     return retval;
139     }
140    
141 root 1.8 static char *
142     uu_fnamefilter_callback (void *cb, char *fname)
143 root 1.1 {
144     dSP;
145     int count;
146     static char *str;
147    
148 root 1.10 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 1);
149 root 1.1
150 root 1.10 PUSHs (sv_2mortal (newSVpv (fname, 0)));
151 root 1.1
152     PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
153    
154     if (count != 1)
155 root 1.13 croak ("fnamefilter perl callback MUST return a single filename exactly");
156 root 1.1
157 root 1.13 _FP_free (str); str = _FP_strdup (SvPV_nolen (TOPs));
158 root 1.1
159     PUTBACK; FREETMPS; LEAVE;
160    
161     return str;
162     }
163    
164 root 1.8 static int
165     uu_file_callback (void *cb, char *id, char *fname, int retrieve)
166 root 1.1 {
167     dSP;
168     int count;
169     int retval;
170     SV *xfname = newSVpv ("", 0);
171    
172 root 1.10 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 3);
173 root 1.1
174 root 1.10 PUSHs (sv_2mortal (newSVpv (id, 0)));
175     PUSHs (sv_2mortal (xfname));
176     PUSHs (sv_2mortal (newSViv (retrieve)));
177 root 1.1
178     PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
179    
180     if (count != 1)
181 root 1.13 croak ("filecallback perl callback must return a single return status");
182 root 1.1
183 root 1.13 strcpy (fname, SvPV_nolen (xfname));
184 root 1.1 retval = POPi;
185    
186     PUTBACK; FREETMPS; LEAVE;
187    
188     return retval;
189     }
190    
191 root 1.8 static char *
192     uu_filename_callback (void *cb, char *subject, char *filename)
193 root 1.5 {
194     dSP;
195     int count;
196    
197 root 1.13 ENTER; SAVETMPS; PUSHMARK (SP); EXTEND (SP, 2);
198 root 1.5
199 root 1.13 PUSHs (sv_2mortal(newSVpv(subject, 0)));
200     PUSHs (filename ? sv_2mortal(newSVpv(filename, 0)) : &PL_sv_undef);
201 root 1.5
202     PUTBACK; count = perl_call_sv ((SV *)cb, G_ARRAY); SPAGAIN;
203    
204     if (count > 1)
205 root 1.13 croak ("filenamecallback perl callback must return nothing or a single filename");
206 root 1.5
207     if (count)
208     {
209     _FP_free (filename);
210    
211 root 1.13 filename = SvOK (TOPs)
212     ? _FP_strdup (SvPV_nolen (TOPs))
213     : 0;
214 root 1.5 }
215    
216     PUTBACK; FREETMPS; LEAVE;
217    
218     return filename;
219     }
220    
221     static SV *uu_msg_sv, *uu_busy_sv, *uu_file_sv, *uu_fnamefilter_sv, *uu_filename_sv;
222 root 1.1
223     #define FUNC_CB(cb) (void *)(sv_setsv (cb ## _sv, func), cb ## _sv), func ? cb ## _callback : NULL
224    
225 root 1.8 static int
226     uu_info_file (void *cb, char *info)
227 root 1.1 {
228     dSP;
229     int count;
230     int retval;
231    
232     ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP,1);
233    
234     PUSHs(sv_2mortal(newSVpv(info,0)));
235    
236     PUTBACK; count = perl_call_sv ((SV *)cb, G_SCALAR); SPAGAIN;
237    
238     if (count != 1)
239     croak ("info_file perl callback returned more than one argument");
240    
241     retval = POPi;
242    
243     PUTBACK; FREETMPS; LEAVE;
244    
245     return retval;
246     }
247    
248     static int
249     uu_opt_isstring (int opt)
250     {
251     switch (opt)
252     {
253     case UUOPT_VERSION:
254     case UUOPT_SAVEPATH:
255     case UUOPT_ENCEXT:
256     return 1;
257     default:
258     return 0;
259     }
260     }
261    
262     static int uu_initialized;
263    
264     MODULE = Convert::UUlib PACKAGE = Convert::UUlib PREFIX = UU
265    
266     PROTOTYPES: ENABLE
267    
268     int
269 root 1.8 constant (name)
270 root 1.1 char * name
271    
272    
273     void
274 root 1.8 UUInitialize ()
275 root 1.1 CODE:
276     if (!uu_initialized)
277     {
278     int retval;
279    
280     if ((retval = UUInitialize ()) != UURET_OK)
281     croak ("unable to initialize uudeview library (%s)", UUstrerror (retval));
282    
283     uu_initialized = 1;
284     }
285    
286     void
287 root 1.8 UUCleanUp ()
288 root 1.1 CODE:
289     if (uu_initialized)
290     UUCleanUp ();
291    
292     uu_initialized = 0;
293    
294     SV *
295 root 1.8 UUGetOption (opt)
296 root 1.1 int opt
297     CODE:
298     {
299     if (opt == UUOPT_PROGRESS)
300     croak ("GetOption(UUOPT_PROGRESS) is not yet implemented");
301     else if (uu_opt_isstring (opt))
302     {
303     char cval[8192];
304    
305     UUGetOption (opt, 0, cval, sizeof cval);
306     RETVAL = newSVpv (cval, 0);
307     }
308     else
309     {
310     RETVAL = newSViv (UUGetOption (opt, 0, 0, 0));
311     }
312     }
313     OUTPUT:
314     RETVAL
315    
316     int
317 root 1.8 UUSetOption (opt, val)
318 root 1.1 int opt
319     SV * val
320     CODE:
321     {
322     STRLEN dc;
323    
324     if (uu_opt_isstring (opt))
325     RETVAL = UUSetOption (opt, 0, SvPV (val, dc));
326     else
327     RETVAL = UUSetOption (opt, SvIV (val), (void *)0);
328     }
329     OUTPUT:
330     RETVAL
331    
332     char *
333 root 1.8 UUstrerror (errcode)
334 root 1.1 int errcode
335    
336     void
337 root 1.8 UUSetMsgCallback (func = 0)
338 root 1.1 SV * func
339     CODE:
340 root 1.13 UUSetMsgCallback (FUNC_CB (uu_msg));
341 root 1.1
342     void
343 root 1.8 UUSetBusyCallback (func = 0,msecs = 1000)
344 root 1.1 SV * func
345     long msecs
346     CODE:
347 root 1.13 UUSetBusyCallback (FUNC_CB (uu_busy), msecs);
348 root 1.1
349     void
350 root 1.8 UUSetFileCallback (func = 0)
351 root 1.1 SV * func
352     CODE:
353 root 1.13 UUSetFileCallback (FUNC_CB (uu_file));
354 root 1.1
355     void
356 root 1.8 UUSetFNameFilter (func = 0)
357 root 1.1 SV * func
358     CODE:
359 root 1.13 UUSetFNameFilter (FUNC_CB (uu_fnamefilter));
360 root 1.1
361 root 1.5 void
362 root 1.8 UUSetFileNameCallback (func = 0)
363 root 1.5 SV * func
364     CODE:
365 root 1.13 UUSetFileNameCallback (FUNC_CB (uu_filename));
366 root 1.5
367 root 1.1 char *
368 root 1.8 UUFNameFilter (fname)
369 root 1.1 char * fname
370    
371     void
372 root 1.11 UULoadFile (fname, id = 0, delflag = 0, partno = -1)
373 root 1.1 char * fname
374     char * id
375     int delflag
376 root 1.11 int partno
377 root 1.1 PPCODE:
378     {
379     int count;
380    
381 root 1.10 XPUSHs (sv_2mortal (newSViv (UULoadFileWithPartNo (fname, id, delflag, partno, &count))));
382 root 1.1 if (GIMME_V == G_ARRAY)
383 root 1.10 XPUSHs (sv_2mortal (newSViv (count)));
384 root 1.1 }
385    
386     int
387 root 1.8 UUSmerge (pass)
388 root 1.1 int pass
389    
390     int
391     UUQuickDecode(datain,dataout,boundary,maxpos)
392     FILE * datain
393     FILE * dataout
394     char * boundary
395     long maxpos
396    
397     int
398     UUEncodeMulti(outfile,infile,infname,encoding,outfname,mimetype,filemode)
399     FILE * outfile
400     FILE * infile
401     char * infname
402     int encoding
403     char * outfname
404     char * mimetype
405     int filemode
406    
407     int
408     UUEncodePartial(outfile,infile,infname,encoding,outfname,mimetype,filemode,partno,linperfile)
409     FILE * outfile
410     FILE * infile
411     char * infname
412     int encoding
413     char * outfname
414     char * mimetype
415     int filemode
416     int partno
417     long linperfile
418    
419     int
420     UUEncodeToStream(outfile,infile,infname,encoding,outfname,filemode)
421     FILE * outfile
422     FILE * infile
423     char * infname
424     int encoding
425     char * outfname
426     int filemode
427    
428     int
429     UUEncodeToFile(infile,infname,encoding,outfname,diskname,linperfile)
430     FILE * infile
431     char * infname
432     int encoding
433     char * outfname
434     char * diskname
435     long linperfile
436    
437     int
438     UUE_PrepSingle(outfile,infile,infname,encoding,outfname,filemode,destination,from,subject,isemail)
439     FILE * outfile
440     FILE * infile
441     char * infname
442     int encoding
443     char * outfname
444     int filemode
445     char * destination
446     char * from
447     char * subject
448     int isemail
449    
450     int
451     UUE_PrepPartial(outfile,infile,infname,encoding,outfname,filemode,partno,linperfile,filesize,destination,from,subject,isemail)
452     FILE * outfile
453     FILE * infile
454     char * infname
455     int encoding
456     char * outfname
457     int filemode
458     int partno
459     long linperfile
460     long filesize
461     char * destination
462     char * from
463     char * subject
464     int isemail
465    
466     uulist *
467 root 1.8 UUGetFileListItem (num)
468 root 1.1 int num
469    
470 root 1.8 MODULE = Convert::UUlib PACKAGE = Convert::UUlib::Item
471    
472 root 1.1 int
473 root 1.8 rename (item, newname)
474 root 1.1 uulist *item
475     char * newname
476 root 1.8 CODE:
477     RETVAL = UURenameFile (item, newname);
478     OUTPUT:
479     RETVAL
480 root 1.1
481     int
482 root 1.8 decode_temp (item)
483 root 1.1 uulist *item
484 root 1.8 CODE:
485     RETVAL = UUDecodeToTemp (item);
486     OUTPUT:
487     RETVAL
488 root 1.1
489     int
490 root 1.8 remove_temp (item)
491 root 1.1 uulist *item
492 root 1.8 CODE:
493     RETVAL = UURemoveTemp (item);
494     OUTPUT:
495     RETVAL
496 root 1.1
497     int
498 root 1.8 decode (item, target = 0)
499 root 1.1 uulist *item
500     char * target
501 root 1.8 CODE:
502     RETVAL = UUDecodeFile (item, target);
503     OUTPUT:
504     RETVAL
505 root 1.1
506     void
507 root 1.8 info (item, func)
508 root 1.1 uulist *item
509     SV * func
510     CODE:
511 root 1.8 UUInfoFile (item,(void *)func, uu_info_file);
512 root 1.1
513     short
514     state(li)
515     uulist *li
516     CODE:
517     RETVAL = li->state;
518     OUTPUT:
519     RETVAL
520    
521     short
522     mode(li,newmode=0)
523     uulist *li
524     short newmode
525     CODE:
526     if (newmode)
527     li->mode = newmode;
528     RETVAL = li->mode;
529     OUTPUT:
530     RETVAL
531    
532     short
533     uudet(li)
534     uulist *li
535     CODE:
536     RETVAL = li->uudet;
537     OUTPUT:
538     RETVAL
539    
540     long
541     size(li)
542     uulist *li
543     CODE:
544     RETVAL = li->size;
545     OUTPUT:
546     RETVAL
547    
548     char *
549 root 1.8 filename (li, newfilename = 0)
550 root 1.1 uulist *li
551     char * newfilename
552     CODE:
553     if (newfilename)
554     {
555 root 1.4 _FP_free (li->filename);
556     li->filename = _FP_strdup (newfilename);
557 root 1.1 }
558     RETVAL = li->filename;
559     OUTPUT:
560     RETVAL
561    
562     char *
563 root 1.8 subfname (li)
564 root 1.1 uulist *li
565     CODE:
566     RETVAL = li->subfname;
567     OUTPUT:
568     RETVAL
569    
570     char *
571 root 1.8 mimeid (li)
572 root 1.1 uulist *li
573     CODE:
574     RETVAL = li->mimeid;
575     OUTPUT:
576     RETVAL
577    
578     char *
579 root 1.8 mimetype (li)
580 root 1.1 uulist *li
581     CODE:
582     RETVAL = li->mimetype;
583     OUTPUT:
584     RETVAL
585    
586     char *
587 root 1.8 binfile (li)
588 root 1.1 uulist *li
589     CODE:
590     RETVAL = li->binfile;
591     OUTPUT:
592     RETVAL
593    
594 root 1.8 # methods accessing internal data(!)
595 root 1.1
596     void
597 root 1.8 parts (li)
598 root 1.1 uulist *li
599     PPCODE:
600     {
601     struct _uufile *p = li->thisfile;
602    
603     while (p)
604     {
605     HV *pi = newHV ();
606    
607     hv_store (pi, "partno" , 6, newSViv (p->partno) , 0);
608    
609     if (p->filename)
610     hv_store (pi, "filename", 8, newSVpv (p->filename, 0) , 0);
611     if(p->subfname)
612     hv_store (pi, "subfname", 8, newSVpv (p->subfname, 0) , 0);
613     if(p->mimeid)
614     hv_store (pi, "mimeid" , 6, newSVpv (p->mimeid , 0) , 0);
615     if(p->mimetype)
616     hv_store (pi, "mimetype", 8, newSVpv (p->mimetype, 0) , 0);
617     if (p->data->subject)
618     hv_store (pi, "subject" , 7, newSVpv (p->data->subject,0), 0);
619     if (p->data->origin)
620     hv_store (pi, "origin" , 6, newSVpv (p->data->origin ,0), 0);
621     if (p->data->sfname)
622     hv_store (pi, "sfname" , 6, newSVpv (p->data->sfname ,0), 0);
623    
624     XPUSHs (sv_2mortal (newRV_noinc ((SV *)pi)));
625    
626     p = p->NEXT;
627     }
628     }
629    
630     BOOT:
631 root 1.13 uu_msg_sv = newSVsv (&PL_sv_undef);
632     uu_busy_sv = newSVsv (&PL_sv_undef);
633     uu_file_sv = newSVsv (&PL_sv_undef);
634     uu_fnamefilter_sv = newSVsv (&PL_sv_undef);
635     uu_filename_sv = newSVsv (&PL_sv_undef);
636 root 1.1