static void save_picture(struct membuffer *b, struct picture *pic) { put_string(b, " <picture filename='"); put_quoted(b, pic->filename, true, false); put_string(b, "'"); if (pic->offset.seconds) { int offset = pic->offset.seconds; char sign = '+'; if (offset < 0) { sign = '-'; offset = -offset; } put_format(b, " offset='%c%u:%02u min'", sign, FRACTION(offset, 60)); } if (pic->latitude.udeg || pic->longitude.udeg) { put_degrees(b, pic->latitude, " gps='", " "); put_degrees(b, pic->longitude, "", "'"); } if (hashstring(pic->filename)) put_format(b, " hash='%s'", hashstring(pic->filename)); put_string(b, "/>\n"); }
static void write_benv(benv_des_t *bd) { FILE *fp; eplist_t *list, *e; benv_ent_t *bent; char *name; list = bd->elist; if (list->next == list) return; if ((fp = fopen(bd->name, "w")) == NULL) exit(_error(PERROR, "cannot open %s", bd->name)); for (e = list->next; e != list; e = e->next) { bent = (benv_ent_t *)e->item; name = bent->name; if (name) { if (bent->val) { (void) fprintf(fp, "%s %s ", bent->cmd, bent->name); put_quoted(fp, bent->val); (void) fprintf(fp, "\n"); } else { (void) fprintf(fp, "%s %s\n", bent->cmd, bent->name); } } else { (void) fprintf(fp, "%s\n", bent->cmd); } } (void) fclose(fp); }
/* * We're outputting utf8 in xml. * We need to quote the characters <, >, &. * * Technically I don't think we'd necessarily need to quote the control * characters, but at least libxml2 doesn't like them. It doesn't even * allow them quoted. So we just skip them and replace them with '?'. * * If we do this for attributes, we need to quote the quotes we use too. */ static void quote(struct membuffer *b, const char *text, int is_attribute) { int is_html = 0; put_quoted(b, text, is_attribute, is_html); }
// TODO: This looks like should be ported to C code. or a big part of it. bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected) { static const char errPrefix[] = "divelog.de-upload:"; if (!amount_selected) { report_error(tr("no dives were selected").toUtf8()); return false; } xsltStylesheetPtr xslt = NULL; struct zip *zip; xslt = get_stylesheet("divelogs-export.xslt"); if (!xslt) { qDebug() << errPrefix << "missing stylesheet"; return false; } int error_code; zip = zip_open(QFile::encodeName(QDir::toNativeSeparators(tempfile)), ZIP_CREATE, &error_code); if (!zip) { char buffer[1024]; zip_error_to_str(buffer, sizeof buffer, error_code, errno); report_error(tr("failed to create zip file for upload: %s").toUtf8(), buffer); return false; } /* walk the dive list in chronological order */ int i; struct dive *dive; for_each_dive (i, dive) { FILE *f; char filename[PATH_MAX]; int streamsize; const char *membuf; xmlDoc *transformed; struct zip_source *s; struct membuffer mb = { 0 }; /* * Get the i'th dive in XML format so we can process it. * We need to save to a file before we can reload it back into memory... */ if (selected && !dive->selected) continue; /* make sure the buffer is empty and add the dive */ mb.len = 0; struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid); if (ds) { put_format(&mb, "<divelog><divesites><site uuid='%8x' name='", dive->dive_site_uuid); put_quoted(&mb, ds->name, 1, 0); put_format(&mb, "'"); if (ds->latitude.udeg || ds->longitude.udeg) { put_degrees(&mb, ds->latitude, " gps='", " "); put_degrees(&mb, ds->longitude, "", "'"); } put_format(&mb, "/>\n</divesites>\n"); } save_one_dive_to_mb(&mb, dive); if (ds) { put_format(&mb, "</divelog>\n"); } membuf = mb_cstring(&mb); streamsize = strlen(membuf); /* * Parse the memory buffer into XML document and * transform it to divelogs.de format, finally dumping * the XML into a character buffer. */ xmlDoc *doc = xmlReadMemory(membuf, streamsize, "divelog", NULL, 0); if (!doc) { qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!"; report_error(tr("internal error").toUtf8()); goto error_close_zip; } free((void *)membuf); transformed = xsltApplyStylesheet(xslt, doc, NULL); xmlDocDumpMemory(transformed, (xmlChar **)&membuf, &streamsize); xmlFreeDoc(doc); xmlFreeDoc(transformed); /* * Save the XML document into a zip file. */ snprintf(filename, PATH_MAX, "%d.xml", i + 1); s = zip_source_buffer(zip, membuf, streamsize, 1); if (s) { int64_t ret = zip_add(zip, filename, s); if (ret == -1) qDebug() << errPrefix << "failed to include dive:" << i; } }