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