- // create a link to keep track of last uploaded session for this card
- if (!defsession) makeSessionLink (request->plugin, name);
-
- return (jsonSession);
-}
-
-// push Json session object to disk
-PUBLIC json_object * sessionToDisk (AFB_session *session, AFB_request *request, char *name, json_object *jsonSession) {
- char filename [256];
- time_t rawtime;
- struct tm * timeinfo;
- int err, defsession;
- static json_object *response;
-
- // we should have a session name
- if (name == NULL) return (jsonNewMessage (AFB_FATAL,"session name missing &session=MySessionName"));
-
- // check for current session request
- defsession = (strcmp (name, AFB_DEFAULT_SESSION) ==0);
-
- // if directory for card's sessions does not exist create it
- response = checkCardDirExit (session, request);
- if (response != NULL) return response;
-
- // add cardname and file extension to session name
- strncpy (filename, request->plugin, sizeof(filename));
- strncat (filename, "/", sizeof(filename));
- if (defsession) strncat (filename, AFB_CURRENT_SESSION, sizeof(filename)-1);
- else strncat (filename, name, sizeof(filename)-1);
- strncat (filename, ".afb", sizeof(filename)-1);
-
-
- json_object_object_add(jsonSession, "jtype", json_object_new_string (AFB_SESSION_JTYPE));
-
- // add a timestamp and store session on disk
- time ( &rawtime ); timeinfo = localtime ( &rawtime );
- // A copy of the string is made and the memory is managed by the json_object
- json_object_object_add (jsonSession, "timestamp", json_object_new_string (asctime (timeinfo)));
-
-
- // do we have extra session info ?
- if (request->post) {
- static json_object *info, *jtype;
- const char *ajglabel;
-
- // extract session info from args
- info = json_tokener_parse (request->post);
- if (!info) {
- response = jsonNewMessage (AFB_FATAL,"sndcard=%s session=%s invalid json args=%s", request->plugin, name, request->post);
- goto OnErrorExit;
- }
-
- // info is a valid AFB_info type
- if (!json_object_object_get_ex (info, "jtype", &jtype)) {
- response = jsonNewMessage (AFB_EMPTY,"sndcard=%s session=%s No 'AFB_pluginT' args=%s", request->plugin, name, request->post);
- goto OnErrorExit;
- }
-
- // check type value is AFB_INFO_JTYPE
- ajglabel = json_object_get_string (jtype);
- if (strcmp (AFB_SESSION_JINFO, ajglabel)) {
- json_object_put (info); // release info json object
- response = jsonNewMessage (AFB_FATAL,"File [%s] jtype=[%s] != [%s] data=%s", filename, ajglabel, AFB_SESSION_JTYPE, request->post);
- goto OnErrorExit;
- }
-
- // this is valid info data for our session
- json_object_object_add (jsonSession, "info", info);
- }
-
- // Finally save session on disk
- err = json_object_to_file (filename, jsonSession);
- if (err < 0) {
- response = jsonNewMessage (AFB_FATAL,"Fail save session = [%s] to disk", filename);
- goto OnErrorExit;
- }
-
-
- // create a link to keep track of last uploaded session for this card
- if (!defsession) makeSessionLink (request->plugin, name);
-
- // we're donne let's return status message
- response = jsonNewMessage (AFB_SUCCESS,"Session= [%s] saved on disk", filename);
- json_object_put (jsonSession);
- return (response);
-
-OnErrorExit:
- json_object_put (jsonSession);
- return response;