X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fsession_file.c;h=bd5b827f41734abf8ceb3056c31c264b26d5ba63;hb=624503ae90a3583edd34fc28a62a037640984e36;hp=350cc3bda68b07517b84a3ac61cae3c871ba8aa3;hpb=c6805a02cca9b0b17392841bc1afea8beaf333ed;p=libsigrok.git diff --git a/src/session_file.c b/src/session_file.c index 350cc3bd..bd5b827f 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -74,7 +74,6 @@ SR_PRIV int sr_sessionfile_check(const char *filename) return SR_ERR; /* check "version" */ - version = 0; if (!(zf = zip_fopen(archive, "version", 0))) { sr_dbg("Not a sigrok session file: no version found."); return SR_ERR; @@ -107,12 +106,13 @@ SR_PRIV int sr_sessionfile_check(const char *filename) /** * Load the session from the specified filename. * - * @param filename The name of the session file to load. Must not be NULL. - * @param session The session to load the file into. Must not be NULL. + * @param filename The name of the session file to load. + * @param session The session to load the file into. * - * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, - * SR_ERR_MALLOC upon memory allocation errors, or SR_ERR upon - * other errors. + * @retval SR_OK Success + * @retval SR_ERR_MALLOC Memory allocation error + * @retval SR_ERR_DATA Malformed session file + * @retval SR_ERR This is not a session file */ SR_API int sr_session_load(const char *filename, struct sr_session **session) { @@ -155,9 +155,10 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) if ((ret = sr_session_new(session)) != SR_OK) return ret; + ret = SR_OK; capturefiles = g_ptr_array_new_with_free_func(g_free); sections = g_key_file_get_groups(kf, NULL); - for (i = 0; sections[i]; i++) { + for (i = 0; sections[i] && ret == SR_OK; i++) { if (!strcmp(sections[i], "global")) /* nothing really interesting in here yet */ continue; @@ -178,20 +179,34 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) } sr_dev_open(sdi); sr_session_dev_add(*session, sdi); + (*session)->owned_devs = g_slist_append( + (*session)->owned_devs, sdi); sdi->driver->config_set(SR_CONF_SESSIONFILE, g_variant_new_string(filename), sdi, NULL); sdi->driver->config_set(SR_CONF_CAPTUREFILE, g_variant_new_string(val), sdi, NULL); g_ptr_array_add(capturefiles, val); } else if (!strcmp(keys[j], "samplerate")) { + if (!sdi) { + ret = SR_ERR_DATA; + break; + } sr_parse_sizestring(val, &tmp_u64); sdi->driver->config_set(SR_CONF_SAMPLERATE, g_variant_new_uint64(tmp_u64), sdi, NULL); } else if (!strcmp(keys[j], "unitsize")) { + if (!sdi) { + ret = SR_ERR_DATA; + break; + } tmp_u64 = strtoull(val, NULL, 10); sdi->driver->config_set(SR_CONF_CAPTURE_UNITSIZE, g_variant_new_uint64(tmp_u64), sdi, NULL); } else if (!strcmp(keys[j], "total probes")) { + if (!sdi) { + ret = SR_ERR_DATA; + break; + } total_channels = strtoull(val, NULL, 10); sdi->driver->config_set(SR_CONF_NUM_LOGIC_CHANNELS, g_variant_new_uint64(total_channels), sdi, NULL); @@ -203,8 +218,10 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) sdi->channels = g_slist_append(sdi->channels, ch); } } else if (!strncmp(keys[j], "probe", 5)) { - if (!sdi) - continue; + if (!sdi) { + ret = SR_ERR_DATA; + break; + } enabled_channels++; tmp_u64 = strtoul(keys[j]+5, NULL, 10); /* sr_session_save() */ @@ -221,7 +238,7 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) g_strfreev(sections); g_key_file_free(kf); - return SR_OK; + return ret; } /**