static cdk_error_t literal_encode (void *data, FILE * in, FILE * out) { literal_filter_t *pfx = data; cdk_pkt_literal_t pt; cdk_stream_t si; cdk_packet_t pkt; size_t filelen; cdk_error_t rc; _cdk_log_debug ("literal filter: encode\n"); if (!pfx || !in || !out) return CDK_Inv_Value; if (!pfx->filename) { pfx->filename = cdk_strdup ("_CONSOLE"); if (!pfx->filename) return CDK_Out_Of_Core; } rc = _cdk_stream_fpopen (in, STREAMCTL_READ, &si); if (rc) return rc; filelen = strlen (pfx->filename); cdk_pkt_new (&pkt); pt = pkt->pkt.literal = cdk_calloc (1, sizeof *pt + filelen); pt->name = (char *) pt + sizeof (*pt); if (!pt) { cdk_pkt_release (pkt); cdk_stream_close (si); return CDK_Out_Of_Core; } memcpy (pt->name, pfx->filename, filelen); pt->namelen = filelen; pt->name[pt->namelen] = '\0'; pt->timestamp = (u32) time (NULL); pt->mode = intmode_to_char (pfx->mode); pt->len = cdk_stream_get_length (si); pt->buf = si; pkt->old_ctb = 1; pkt->pkttype = CDK_PKT_LITERAL; pkt->pkt.literal = pt; rc = _cdk_pkt_write_fp (out, pkt); cdk_pkt_release (pkt); cdk_stream_close (si); return rc; }
static int literal_encode (void * opaque, FILE * in, FILE * out) { literal_filter_t * pfx = opaque; cdk_pkt_literal_t pt; cdk_stream_t si; CDK_PACKET pkt; size_t filelen; int rc; _cdk_log_debug ("literal filter: encode\n"); if (!pfx || !in || !out) return CDK_Inv_Value; if (!pfx->filename) { pfx->filename = cdk_strdup ("_CONSOLE"); if( !pfx->filename ) return CDK_Out_Of_Core; } si = _cdk_stream_fpopen (in, STREAMCTL_READ); if (!si) return CDK_Out_Of_Core; filelen = strlen (pfx->filename); pt = cdk_calloc (1, sizeof *pt + filelen - 1); if (!pt) return CDK_Out_Of_Core; memcpy (pt->name, pfx->filename, filelen); pt->namelen = filelen; pt->name[pt->namelen] = '\0'; pt->timestamp = _cdk_timestamp (); pt->mode = pfx->mode ? 't' : 'b'; pt->len = cdk_stream_get_length (si); pt->buf = si; cdk_pkt_init (&pkt); pkt.old_ctb = pfx->rfc1991? 1 : 0; pkt.pkttype = CDK_PKT_LITERAL; pkt.pkt.literal = pt; rc = _cdk_pkt_write_fp (out, &pkt); cdk_free (pt); cdk_stream_close (si); return rc; }