| 1 |
|
| MODULE = PDF::Make PACKAGE = PDF::Make::Attachment |
| 2 |
|
| PROTOTYPES: ENABLE |
| 3 |
|
| |
| 4 |
|
| SV * |
| 5 |
|
| attach(class, doc, ...) |
| 6 |
|
| char *class |
| 7 |
|
| pdfmake_doc_t *doc |
| 8 |
|
| PREINIT: |
| 9 |
27 |
| const char *name = NULL; |
| 10 |
27 |
| const char *filename = NULL; |
| 11 |
27 |
| const char *mime = NULL; |
| 12 |
27 |
| const char *desc = NULL; |
| 13 |
27 |
| const char *path = NULL; |
| 14 |
27 |
| SV *data_sv = NULL; |
| 15 |
|
| pdfmake_attachment_t *att; |
| 16 |
|
| int i; |
| 17 |
|
| CODE: |
| 18 |
|
| PERL_UNUSED_VAR(class); |
| 19 |
128 |
▶ | for (i = 2; i < items - 1; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 2; i < items - 1; i += 2) { |
101 |
27 |
128 |
|
| 20 |
101 |
| const char *key = SvPV_nolen(ST(i)); |
| 21 |
101 |
| SV *val = ST(i + 1); |
| 22 |
127 |
▶ | if (strEQ(key, "name")) name = SvPV_nolen(val); |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(key, "name")) name = SvPV_nolen(val); |
26 |
75 |
101 |
|
| 23 |
97 |
▶ | else if (strEQ(key, "filename")) filename = SvPV_nolen(val); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "filename")) filename = SvPV_nolen(val); |
22 |
53 |
75 |
|
| 24 |
77 |
▶ | else if (strEQ(key, "mime")) mime = SvPV_nolen(val); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "mime")) mime = SvPV_nolen(val); |
24 |
29 |
53 |
|
| 25 |
32 |
▶ | else if (strEQ(key, "description")) desc = SvPV_nolen(val); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "description")) desc = SvPV_nolen(val); |
3 |
26 |
29 |
|
| 26 |
26 |
▶ | else if (strEQ(key, "path")) path = SvPV_nolen(val); |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "path")) path = SvPV_nolen(val); |
0 |
26 |
26 |
|
| 27 |
26 |
▶ | else if (strEQ(key, "data")) data_sv = val; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(key, "data")) data_sv = val; |
26 |
0 |
26 |
|
| 28 |
|
| } |
| 29 |
|
| |
| 30 |
27 |
▶ | if (!name) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!name) |
1 |
26 |
27 |
|
| 31 |
1 |
| croak("PDF::Make::Attachment: 'name' is required"); |
| 32 |
|
| |
| 33 |
26 |
▶ | if (path) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (path) { |
0 |
26 |
26 |
|
| 34 |
0 |
| att = pdfmake_doc_attach_file(doc, name, path); |
| 35 |
26 |
▶ | } else if (data_sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (data_sv) { |
25 |
1 |
26 |
|
| 36 |
|
| STRLEN len; |
| 37 |
25 |
| const uint8_t *data = (const uint8_t *)SvPV(data_sv, len); |
| 38 |
25 |
| att = pdfmake_doc_attach(doc, name, filename, data, len, mime, desc); |
| 39 |
|
| } else { |
| 40 |
1 |
| croak("PDF::Make::Attachment: 'path' or 'data' is required"); |
| 41 |
|
| } |
| 42 |
|
| |
| 43 |
25 |
▶ | if (!att) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!att) |
0 |
25 |
25 |
|
| 44 |
0 |
| croak("PDF::Make::Attachment: failed to attach '%s'", name); |
| 45 |
|
| |
| 46 |
25 |
| RETVAL = sv_newmortal(); |
| 47 |
25 |
| sv_setref_pv(RETVAL, "PDF::Make::Attachment", (void *)att); |
| 48 |
25 |
| SvREFCNT_inc(RETVAL); |
| 49 |
|
| OUTPUT: |
| 50 |
|
| RETVAL |
| 51 |
|
| |
| 52 |
|
| const char * |
| 53 |
|
| name(self) |
| 54 |
|
| pdfmake_attachment_t *self |
| 55 |
|
| CODE: |
| 56 |
23 |
| RETVAL = self->name; |
| 57 |
|
| OUTPUT: |
| 58 |
|
| RETVAL |
| 59 |
|
| |
| 60 |
|
| const char * |
| 61 |
|
| filename(self) |
| 62 |
|
| pdfmake_attachment_t *self |
| 63 |
|
| CODE: |
| 64 |
3 |
| RETVAL = self->filename; |
| 65 |
|
| OUTPUT: |
| 66 |
|
| RETVAL |
| 67 |
|
| |
| 68 |
|
| const char * |
| 69 |
|
| mime_type(self) |
| 70 |
|
| pdfmake_attachment_t *self |
| 71 |
|
| CODE: |
| 72 |
4 |
| RETVAL = self->mime_type; |
| 73 |
|
| OUTPUT: |
| 74 |
|
| RETVAL |
| 75 |
|
| |
| 76 |
|
| UV |
| 77 |
|
| size(self) |
| 78 |
|
| pdfmake_attachment_t *self |
| 79 |
|
| CODE: |
| 80 |
23 |
▶ | RETVAL = self->data_len; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = self->data_len; |
20 |
3 |
23 |
|
| 81 |
|
| OUTPUT: |
| 82 |
|
| RETVAL |
| 83 |
|
| |
| 84 |
|
| SV * |
| 85 |
|
| data(self) |
| 86 |
|
| pdfmake_attachment_t *self |
| 87 |
|
| CODE: |
| 88 |
23 |
▶ | if (self->data && self->data_len > 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (self->data && self->data_len > 0) { |
23 |
0 |
23 |
| if (self->data && self->data_len > 0) { |
23 |
0 |
23 |
|
| 89 |
23 |
| RETVAL = newSVpvn((const char *)self->data, self->data_len); |
| 90 |
|
| } else { |
| 91 |
0 |
| RETVAL = &PL_sv_undef; |
| 92 |
|
| } |
| 93 |
|
| OUTPUT: |
| 94 |
|
| RETVAL |
| 95 |
|
| |
| 96 |
|
| void |
| 97 |
|
| extract_to_file(self, path) |
| 98 |
|
| pdfmake_attachment_t *self |
| 99 |
|
| const char *path |
| 100 |
|
| CODE: |
| 101 |
0 |
▶ | if (pdfmake_attachment_extract_to_file(self, path) != PDFMAKE_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if (pdfmake_attachment_extract_to_file(self, path) != PDFMAKE_OK) |
0 |
0 |
0 |
|
| 102 |
0 |
| croak("PDF::Make::Attachment: extract failed"); |
| 103 |
|
| |
| 104 |
|
| UV |
| 105 |
|
| write_to_doc(self, doc) |
| 106 |
|
| pdfmake_attachment_t *self |
| 107 |
|
| pdfmake_doc_t *doc |
| 108 |
|
| CODE: |
| 109 |
0 |
| RETVAL = pdfmake_attachment_write(self, doc); |
| 110 |
0 |
▶ | if (RETVAL == 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (RETVAL == 0) |
0 |
0 |
0 |
|
| 111 |
0 |
| croak("PDF::Make::Attachment: write failed"); |
| 112 |
|
| OUTPUT: |
| 113 |
|
| RETVAL |
| 114 |
|
| |
| 115 |
|
| void |
| 116 |
|
| DESTROY(self) |
| 117 |
|
| pdfmake_attachment_t *self |
| 118 |
|
| CODE: |
| 119 |
|
| /* Attachment is owned by the document (stored in doc->attachments[]). |
| 120 |
|
| * Do NOT free here — the document frees its attachments in |
| 121 |
|
| * pdfmake_doc_free(). Freeing here would create a dangling pointer |
| 122 |
|
| * in the doc's attachment list. */ |
| 123 |
|
| PERL_UNUSED_VAR(self); |
| 124 |
|
| |
| 125 |
|
| BOOT: |
| 126 |
|
| { |
| 127 |
104 |
| HV *stash = gv_stashpv("PDF::Make::Attachment", GV_ADD); |
| 128 |
104 |
▶ | PDFMAKE_REGISTER_GETTER(stash, "name", pdfmake_attachment_t, name, PDFMAKE_FIELD_STRING); |
Branch: 2 branches
| Branch | True | False | Total |
| PDFMAKE_REGISTER_GETTER(stash, "name", pdfmake_attachment_t, name, PDFMAKE_FIELD_STRING); |
104 |
0 |
104 |
| PDFMAKE_REGISTER_GETTER(stash, "name", pdfmake_attachment_t, name, PDFMAKE_FIELD_STRING); |
104 |
0 |
104 |
|
| 129 |
104 |
▶ | PDFMAKE_REGISTER_GETTER(stash, "filename", pdfmake_attachment_t, filename, PDFMAKE_FIELD_STRING); |
Branch: 2 branches
| Branch | True | False | Total |
| PDFMAKE_REGISTER_GETTER(stash, "filename", pdfmake_attachment_t, filename, PDFMAKE_FIELD_STRING); |
104 |
0 |
104 |
| PDFMAKE_REGISTER_GETTER(stash, "filename", pdfmake_attachment_t, filename, PDFMAKE_FIELD_STRING); |
104 |
0 |
104 |
|
| 130 |
104 |
▶ | PDFMAKE_REGISTER_GETTER(stash, "mime_type", pdfmake_attachment_t, mime_type, PDFMAKE_FIELD_STRING); |
Branch: 2 branches
| Branch | True | False | Total |
| PDFMAKE_REGISTER_GETTER(stash, "mime_type", pdfmake_attachment_t, mime_type, PDFMAKE_FIELD_STRING); |
104 |
0 |
104 |
| PDFMAKE_REGISTER_GETTER(stash, "mime_type", pdfmake_attachment_t, mime_type, PDFMAKE_FIELD_STRING); |
104 |
0 |
104 |
|
| 131 |
104 |
▶ | PDFMAKE_REGISTER_GETTER(stash, "size", pdfmake_attachment_t, data_len, PDFMAKE_FIELD_UV); |
Branch: 2 branches
| Branch | True | False | Total |
| PDFMAKE_REGISTER_GETTER(stash, "size", pdfmake_attachment_t, data_len, PDFMAKE_FIELD_UV); |
104 |
0 |
104 |
| PDFMAKE_REGISTER_GETTER(stash, "size", pdfmake_attachment_t, data_len, PDFMAKE_FIELD_UV); |
104 |
0 |
104 |
|
| 132 |
|
| } |