5 #include <jsoncpp/json/json.h>
8 #include <vdr/videodir.h>
9 #include <vdr/recording.h>
11 #include <vdr/timers.h>
15 int jsonserver_request_handler(struct mg_connection *conn)
17 Log* log = Log::getInstance();
18 const struct mg_request_info *request_info = mg_get_request_info(conn);
20 if (strcmp(request_info->uri, "/jsonserver")) return 0; // not for us
23 int wvrl = mg_get_var(request_info->query_string, strlen(request_info->query_string), "req", wvrequest, 20);
26 log->log("JSONServer", Log::ERR, "Could not decode req");
31 if (!strcmp(request_info->request_method, "OPTIONS"))
33 mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n");
34 mg_printf(conn, "%s", "Access-Control-Allow-Origin: *\r\n");
35 mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n");
43 if (!strcmp(request_info->request_method, "POST"))
45 const char* contentLength = mg_get_header(conn, "Content-Length");
46 int contentLengthI = atoi(contentLength);
47 log->log("JSONServer", Log::DEBUG, "POST data content length: %i", contentLengthI);
48 if (contentLengthI > 10000)
50 log->log("JSONServer", Log::DEBUG, "Length > 10000, rejecting");
54 if (contentLengthI > 0)
56 // FIXME - assume for now that all post data will be small enough to have arrived immediately
57 int bytesRead = mg_read(conn, postData, contentLengthI);
58 if (bytesRead != contentLengthI)
60 log->log("JSONServer", Log::DEBUG, "Could not read up to contentLength");
63 postData[contentLengthI] = '\0';
70 if (!strcmp(wvrequest, "reclist")) success = jsonserver_reclist(js);
71 else if (!strcmp(wvrequest, "recinfo")) success = jsonserver_recinfo(js, postData);
72 else if (!strcmp(wvrequest, "recdel")) success = jsonserver_recdel(js, postData);
73 else if (!strcmp(wvrequest, "recmove")) success = jsonserver_recmove(js, postData);
74 else if (!strcmp(wvrequest, "recstop")) success = jsonserver_recstop(js, postData);
75 else if (!strcmp(wvrequest, "channellist")) success = jsonserver_channellist(js);
76 else if (!strcmp(wvrequest, "channelschedule")) success = jsonserver_channelschedule(js, postData);
77 else if (!strcmp(wvrequest, "timerlist")) success = jsonserver_timerlist(js);
78 else if (!strcmp(wvrequest, "timerdel")) success = jsonserver_timerdel(js, postData);
79 else if (!strcmp(wvrequest, "timerset")) success = jsonserver_timerset(js, postData);
81 if (!success) return 0; // the specific handler failed badly
83 // Now js will be filled
85 Json::StyledWriter sw;
86 std::string jsonout = sw.write(js);
87 mg_printf(conn, "%s", "HTTP/1.0 200 OK\r\n");
88 mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n");
89 mg_write(conn, jsonout.c_str(), jsonout.length());
94 else if (event == MG_EVENT_LOG)
96 if (request_info->status_code == 400) // bad request
98 log->log("Mongoose", Log::DEBUG, "400 BAD REQUEST:");
99 log->log("Mongoose", Log::DEBUG, request_info->request_method);
100 log->log("Mongoose", Log::DEBUG, request_info->uri);
101 log->log("Mongoose", Log::DEBUG, request_info->http_version);
102 log->log("Mongoose", Log::DEBUG, request_info->query_string);
103 log->log("Mongoose", Log::DEBUG, request_info->log_message);
104 for (int i = 0; i < request_info->num_headers; i++)
106 log->log("Mongoose", Log::DEBUG, "%s: %s", request_info->http_headers[i].name, request_info->http_headers[i].value);
111 log->log("Mongoose", Log::DEBUG, request_info->log_message);
112 log->log("Mongoose", Log::DEBUG, request_info->uri);
117 // other events not handled:
118 // MG_HTTP_ERROR, MG_INIT_SSL
119 // Let mongoose do something with those
127 bool jsonserver_reclist(Json::Value& js)
129 Log* log = Log::getInstance();
130 log->log("JSONServer", Log::DEBUG, "reclist");
133 int Percent = VideoDiskSpace(&FreeMB);
134 int Total = (FreeMB / (100 - Percent)) * 100;
136 js["MBFree"] = FreeMB;
137 js["Percent"] = Percent;
140 Json::Value jsrecordings;
141 cRecordings Recordings;
143 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
146 oneRec["StartTime"] = (Json::UInt)recording->Start();
147 oneRec["Length"] = (Json::UInt)recording->LengthInSeconds();
148 oneRec["IsNew"] = recording->IsNew();
149 oneRec["Name"] = recording->Name();
150 oneRec["Filename"] = recording->FileName();
151 jsrecordings.append(oneRec);
153 js["Recordings"] = jsrecordings;
158 bool jsonserver_recinfo(Json::Value& js, const char* postData)
160 Log* log = Log::getInstance();
161 log->log("JSONServer", Log::DEBUG, "recinfo");
163 char reqfilename[1000];
164 int mgv1 = mg_get_var(postData, strlen(postData), "filename", reqfilename, 1000);
167 log->log("JSONServer", Log::ERR, "Could not decode filename");
168 js["Result"] = false;
169 js["Error"] = "Could not decode filename";
173 log->log("JSONServer", Log::DEBUG, "%s", reqfilename);
175 cRecordings Recordings;
176 Recordings.Load(); // probably have to do this
177 cRecording *recording = Recordings.GetByName(reqfilename);
181 log->log("JSONServer", Log::ERR, "recinfo found no recording");
182 js["Result"] = false;
186 js["IsNew"] = recording->IsNew();
187 js["LengthInSeconds"] = recording->LengthInSeconds();
188 js["FileSizeMB"] = recording->FileSizeMB();
189 js["Name"] = recording->Name() ? recording->Name() : Json::Value::null;
190 js["Priority"] = recording->Priority();
191 js["LifeTime"] = recording->Lifetime();
192 js["Start"] = (Json::UInt)recording->Start();
194 js["ResumePoint"] = 0;
195 cResumeFile ResumeFile(recording->FileName(), recording->IsPesRecording());
196 if (ResumeFile.Read() >= 0) js["ResumePoint"] = ResumeFile.Read();
198 js["CurrentlyRecordingStart"] = 0;
199 js["CurrentlyRecordingStop"] = 0;
200 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
203 js["CurrentlyRecordingStart"] = (Json::UInt)rc->Timer()->StartTime();
204 js["CurrentlyRecordingStop"] = (Json::UInt)rc->Timer()->StopTime();
207 const cRecordingInfo *info = recording->Info();
210 js["ChannelName"] = info->ChannelName() ? info->ChannelName() : Json::Value::null;
211 js["Title"] = info->Title() ? info->Title() : Json::Value::null;
212 js["ShortText"] = info->ShortText() ? info->ShortText() : Json::Value::null;
213 js["Description"] = info->Description() ? info->Description() : Json::Value::null;
215 const cComponents* components = info->Components();
218 js["Components"] = Json::Value::null;
222 Json::Value jscomponents;
224 tComponent* component;
225 for (int i = 0; i < components->NumComponents(); i++)
227 component = components->Component(i);
229 Json::Value oneComponent;
230 oneComponent["Stream"] = component->stream;
231 oneComponent["Type"] = component->type;
232 oneComponent["Language"] = component->language ? component->language : Json::Value::null;
233 oneComponent["Description"] = component->description ? component->description : Json::Value::null;
234 jscomponents.append(oneComponent);
237 js["Components"] = jscomponents;
245 bool jsonserver_recstop(Json::Value& js, const char* postData)
247 Log* log = Log::getInstance();
248 log->log("JSONServer", Log::DEBUG, "recstop");
250 char reqfilename[1000];
251 int mgv1 = mg_get_var(postData, strlen(postData), "filename", reqfilename, 1000);
254 log->log("JSONServer", Log::ERR, "Could not decode filename");
255 js["Result"] = false;
256 js["Error"] = "Could not decode filename";
260 log->log("JSONServer", Log::DEBUG, "%s", reqfilename);
262 cRecordings Recordings;
263 Recordings.Load(); // probably have to do this
264 cRecording *recording = Recordings.GetByName(reqfilename);
268 log->log("JSONServer", Log::ERR, "recstop found no recording");
269 js["Result"] = false;
273 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
276 log->log("JSONServer", Log::ERR, "recstop - not currently recording");
277 js["Result"] = false;
281 if (Timers.BeingEdited())
283 log->log("JSONServer", Log::ERR, "recstop - timers being edited elsewhere");
284 js["Result"] = false;
288 cTimer* timer = rc->Timer();
291 log->log("JSONServer", Log::ERR, "recstop - timer not found");
292 js["Result"] = false;
296 timer->ClrFlags(tfActive);
297 Timers.SetModified();
303 bool jsonserver_recdel(Json::Value& js, const char* postData)
305 Log* log = Log::getInstance();
306 log->log("JSONServer", Log::DEBUG, "recdel");
308 char reqfilename[1000];
309 int mgv1 = mg_get_var(postData, strlen(postData), "filename", reqfilename, 1000);
312 log->log("JSONServer", Log::ERR, "Could not decode filename");
313 js["Result"] = false;
314 js["Error"] = "Could not decode filename";
318 log->log("JSONServer", Log::DEBUG, "%s", reqfilename);
320 cRecordings Recordings;
321 Recordings.Load(); // probably have to do this
322 cRecording *recording = Recordings.GetByName(reqfilename);
326 js["Result"] = false;
327 js["Error"] = "Could not find recording to delete";
331 log->log("JSONServer", Log::DEBUG, "Deleting recording: %s", recording->Name());
332 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
335 js["Result"] = false;
336 js["Error"] = "This recording is still recording.. ho ho";
340 if (recording->Delete())
342 ::Recordings.DelByName(recording->FileName());
347 js["Result"] = false;
348 js["Error"] = "Failed to delete recording";
354 bool jsonserver_recmove(Json::Value& js, const char* postData)
356 Log* log = Log::getInstance();
357 log->log("JSONServer", Log::DEBUG, "recmove");
359 char sFileName[1000]; int mgv1 = mg_get_var(postData, strlen(postData), "filename", sFileName, 1000);
360 char sNewPath[1000]; int mgv2 = mg_get_var(postData, strlen(postData), "newpath", sNewPath, 1000);
362 if ( (mgv1 == -1) || (mgv2 == -1) || !strlen(sFileName) || !strlen(sNewPath) )
364 log->log("JSONServer", Log::ERR, "request mgvs: %i %i", mgv1, mgv2);
365 js["Result"] = false;
366 js["Error"] = "Bad request parameters";
370 cRecordings Recordings;
371 Recordings.Load(); // probably have to do this
372 cRecording* recording = Recordings.GetByName(sFileName);
376 log->log("JSONServer", Log::ERR, "Could not find recording to move");
377 js["Result"] = false;
378 js["Error"] = "Bad filename";
382 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
385 log->log("JSONServer", Log::ERR, "Could not move recording, it is still recording");
386 js["Result"] = false;
387 js["Error"] = "Cannot move recording in progress";
391 log->log("JSONServer", Log::DEBUG, "moving recording: %s", recording->Name());
392 log->log("JSONServer", Log::DEBUG, "moving recording: %s", recording->FileName());
393 log->log("JSONServer", Log::DEBUG, "to: %s", sNewPath);
395 const char* t = recording->FileName();
397 char* dateDirName = NULL; int k;
398 char* titleDirName = NULL; int j;
399 char* folderName = NULL; int m;
401 char* newContainer = NULL;
403 // Find the datedirname
404 for(k = strlen(t) - 1; k >= 0; k--)
408 log->log("JSONServer", Log::DEBUG, "l1: %i", strlen(&t[k+1]) + 1);
409 dateDirName = new char[strlen(&t[k+1]) + 1];
410 strcpy(dateDirName, &t[k+1]);
415 // Find the titledirname
417 for(j = k-1; j >= 0; j--)
421 log->log("JSONServer", Log::DEBUG, "l2: %i", k - j);
422 titleDirName = new char[k - j];
423 memcpy(titleDirName, &t[j+1], k - j - 1);
424 titleDirName[k - j - 1] = '\0';
429 // Find the foldername
431 log->log("JSONServer", Log::DEBUG, "j = %u, strlenvd = %u", j, strlen(VideoDirectory));
432 if (j > strlen(VideoDirectory)) // Rec is in a subfolder now
434 for(m = j-1; m >= 0; m--)
438 log->log("JSONServer", Log::DEBUG, "l3: %i", j - m);
439 folderName = new char[j - m];
440 memcpy(folderName, &t[m+1], j - m - 1);
441 folderName[j - m - 1] = '\0';
447 ExchangeChars(sNewPath, true);
449 log->log("JSONServer", Log::DEBUG, "datedirname: %s", dateDirName);
450 log->log("JSONServer", Log::DEBUG, "titledirname: %s", titleDirName);
451 log->log("JSONServer", Log::DEBUG, "viddir: %s", VideoDirectory);
452 if (folderName) log->log("JSONServer", Log::DEBUG, "folderName: %s", folderName);
453 log->log("JSONServer", Log::DEBUG, "EC: %s", sNewPath);
455 // Could be a new path - construct that first and test
456 newContainer = new char[strlen(VideoDirectory) + strlen(sNewPath) + strlen(titleDirName) + 1];
457 sprintf(newContainer, "%s%s", VideoDirectory, sNewPath);
458 log->log("JSONServer", Log::DEBUG, "NPT: %s", newContainer);
460 int statret = stat(newContainer, &dstat);
461 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
463 log->log("JSONServer", Log::DEBUG, "new path does not exist (1)");
464 int mkdirret = mkdir(newContainer, 0755);
467 delete[] dateDirName;
468 delete[] titleDirName;
469 if (folderName) delete[] folderName;
470 delete[] newContainer;
472 log->log("JSONServer", Log::ERR, "Failed to make new dir (1)");
473 js["Result"] = false;
474 js["Error"] = "Failed to create new directory (1)";
478 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR))) // Something exists but it's not a dir
480 delete[] dateDirName;
481 delete[] titleDirName;
482 if (folderName) delete[] folderName;
483 delete[] newContainer;
485 log->log("JSONServer", Log::ERR, "Something already exists? (1)");
486 js["Result"] = false;
487 js["Error"] = "Something already exists at the new path (1)";
491 // New path now created or was there already
493 sprintf(newContainer, "%s%s%s", VideoDirectory, sNewPath, titleDirName);
494 log->log("JSONServer", Log::DEBUG, "%s", newContainer);
496 statret = stat(newContainer, &dstat);
497 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
499 log->log("JSONServer", Log::DEBUG, "new dir does not exist (2)");
500 int mkdirret = mkdir(newContainer, 0755);
503 delete[] dateDirName;
504 delete[] titleDirName;
505 if (folderName) delete[] folderName;
506 delete[] newContainer;
508 log->log("JSONServer", Log::ERR, "Failed to make new dir (2)");
509 js["Result"] = false;
510 js["Error"] = "Failed to create new directory (2)";
514 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR))) // Something exists but it's not a dir
516 delete[] dateDirName;
517 delete[] titleDirName;
518 if (folderName) delete[] folderName;
519 delete[] newContainer;
521 log->log("JSONServer", Log::ERR, "Something already exists?");
522 js["Result"] = false;
523 js["Error"] = "Something already exists at the new path";
527 // Ok, the directory container has been made, or it pre-existed.
529 char* newDir = new char[strlen(newContainer) + 1 + strlen(dateDirName) + 1];
530 sprintf(newDir, "%s/%s", newContainer, dateDirName);
532 log->log("JSONServer", Log::DEBUG, "doing rename '%s' '%s'", t, newDir);
533 int renameret = rename(t, newDir);
536 // Success. Test for remove old dir containter
537 char* oldTitleDir = new char[k+1];
538 memcpy(oldTitleDir, t, k);
539 oldTitleDir[k] = '\0';
540 log->log("JSONServer", Log::DEBUG, "len: %i, cp: %i, strlen: %i, oldtitledir: %s", k+1, k, strlen(oldTitleDir), oldTitleDir);
541 rmdir(oldTitleDir); // can't do anything about a fail result at this point.
542 delete[] oldTitleDir;
544 // Test for remove old foldername
547 char* oldFolderName = new char[j+1];
548 memcpy(oldFolderName, t, j);
549 oldFolderName[j] = '\0';
550 log->log("JSONServer", Log::DEBUG, "len: %i, cp: %i, strlen: %i, oldfoldername: %s", j+1, j, strlen(oldFolderName), oldFolderName);
553 rmdir() deletes a directory, which must be empty.
554 ENOTEMPTY - pathname contains entries other than . and ..
555 So, should be safe to call rmdir on non-empty dir
557 rmdir(oldFolderName); // can't do anything about a fail result at this point.
558 delete[] oldFolderName;
561 ::Recordings.Update();
563 js["NewRecordingFileName"] = newDir;
567 log->log("JSONServer", Log::ERR, "Rename failed");
568 js["Result"] = false;
569 js["Error"] = "Move failed";
572 delete[] dateDirName;
573 delete[] titleDirName;
574 delete[] newContainer;
575 if (folderName) delete[] folderName;
581 bool jsonserver_channellist(Json::Value& js)
583 Log* log = Log::getInstance();
584 log->log("JSONServer", Log::DEBUG, "channellist");
586 Json::Value jschannels;
589 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
591 if (!channel->GroupSep())
593 log->log("JSONServer", Log::DEBUG, "name: '%s'", channel->Name());
595 if (channel->Vpid()) type = 1;
596 else if (channel->Apid(0)) type = 2;
599 Json::Value oneChannel;
600 oneChannel["Number"] = channel->Number();
601 oneChannel["Type"] = type;
602 oneChannel["Name"] = channel->Name();
603 #if VDRVERSNUM < 10703
604 oneChannel["VType"] = 2;
606 oneChannel["VType"] = channel->Vtype();
608 jschannels.append(oneChannel);
611 js["Channels"] = jschannels;
616 bool jsonserver_channelschedule(Json::Value& js, const char* postData)
618 Log* log = Log::getInstance();
619 log->log("JSONServer", Log::DEBUG, "channelschedule '%s'", postData);
621 char sChannelNumber[15]; int mgv1 = mg_get_var(postData, strlen(postData), "channelnumber", sChannelNumber, 15);
622 char sStartTime[15]; int mgv2 = mg_get_var(postData, strlen(postData), "starttime", sStartTime, 15);
623 char sDuration[15]; int mgv3 = mg_get_var(postData, strlen(postData), "duration", sDuration, 15);
625 if ( (mgv1 == -1) || (mgv2 == -1) || (mgv3 == -1) )
627 log->log("JSONServer", Log::ERR, "request mgvs: %i %i %i", mgv1, mgv2, mgv3);
628 js["Result"] = false;
629 js["Error"] = "Bad request parameters";
633 int channelNumber = atoi(sChannelNumber);
634 int startTime = atoi(sStartTime);
635 int duration = atoi(sDuration);
637 cChannel* channel = NULL;
638 for (channel = Channels.First(); channel; channel = Channels.Next(channel))
640 if (channel->GroupSep()) continue;
641 if (channel->Number() == channelNumber) break;
646 log->log("JSONServer", Log::ERR, "Could not find requested channel: %i", channelNumber);
647 js["Result"] = false;
648 js["Error"] = "Could not find channel";
652 cSchedulesLock MutexLock;
653 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
656 log->log("JSONServer", Log::ERR, "Could not find requested channel: %i", channelNumber);
657 js["Result"] = false;
658 js["Error"] = "Internal schedules error (1)";
661 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
664 log->log("JSONServer", Log::ERR, "Could not find requested channel: %i", channelNumber);
665 js["Result"] = false;
666 js["Error"] = "Internal schedules error (2)";
670 Json::Value jsevents;
672 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
675 if ((event->StartTime() + event->Duration()) < time(NULL)) continue;
677 if ((event->StartTime() + event->Duration()) <= startTime) continue;
679 if (event->StartTime() >= (startTime + duration)) continue;
681 Json::Value oneEvent;
682 oneEvent["ID"] = event->EventID();
683 oneEvent["Time"] = (Json::UInt)event->StartTime();
684 oneEvent["Duration"] = event->Duration();
685 oneEvent["Title"] = event->Title() ? event->Title() : "";
686 oneEvent["Description"] = event->Description() ? event->Description() : "";
687 jsevents.append(oneEvent);
690 js["Events"] = jsevents;
694 bool jsonserver_timerlist(Json::Value& js)
696 Log* log = Log::getInstance();
697 log->log("JSONServer", Log::DEBUG, "timerlist");
699 Json::Value jstimers;
702 int numTimers = Timers.Count();
704 for (int i = 0; i < numTimers; i++)
706 timer = Timers.Get(i);
707 Json::Value oneTimer;
708 oneTimer["Active"] = timer->HasFlags(tfActive);
709 oneTimer["Recording"] = timer->Recording();
710 oneTimer["Pending"] = timer->Pending();
711 oneTimer["Priority"] = timer->Priority();
712 oneTimer["Lifetime"] = timer->Lifetime();
713 oneTimer["ChannelNumber"] = timer->Channel()->Number();
714 oneTimer["StartTime"] = (int)timer->StartTime();
715 oneTimer["StopTime"] = (int)timer->StopTime();
716 oneTimer["Day"] = (int)timer->Day();
717 oneTimer["WeekDays"] = timer->WeekDays();
718 oneTimer["Name"] = timer->File();
719 jstimers.append(oneTimer);
722 js["Timers"] = jstimers;
726 bool jsonserver_timerdel(Json::Value& js, const char* postData)
728 Log* log = Log::getInstance();
729 log->log("JSONServer", Log::DEBUG, "timerdel");
731 char sdelChannel[15]; int mgv1 = mg_get_var(postData, strlen(postData), "delchannel", sdelChannel, 15);
732 char sdelWeekdays[15]; int mgv2 = mg_get_var(postData, strlen(postData), "delweekdays", sdelWeekdays, 15);
733 char sdelDay[15]; int mgv3 = mg_get_var(postData, strlen(postData), "delday", sdelDay, 15);
734 char sdelStart[15]; int mgv4 = mg_get_var(postData, strlen(postData), "delstart", sdelStart, 15);
735 char sdelStop[15]; int mgv5 = mg_get_var(postData, strlen(postData), "delstop", sdelStop, 15);
737 if ( (mgv1 == -1) || (mgv2 == -1) || (mgv3 == -1) || (mgv4 == -1) || (mgv5 == -1) )
739 log->log("JSONServer", Log::ERR, "request mgvs: %i %i %i %i %i", mgv1, mgv2, mgv3, mgv4, mgv5);
740 js["Result"] = false;
741 js["Error"] = "Bad request parameters";
745 int delChannel = atoi(sdelChannel);
746 int delWeekdays = atoi(sdelWeekdays);
747 int delDay = atoi(sdelDay);
748 int delStart = atoi(sdelStart);
749 int delStop = atoi(sdelStop);
752 for (ti = Timers.First(); ti; ti = Timers.Next(ti))
754 if ( (ti->Channel()->Number() == delChannel)
755 && ((ti->WeekDays() && (ti->WeekDays() == delWeekdays)) || (!ti->WeekDays() && (ti->Day() == delDay)))
756 && (ti->StartTime() == delStart)
757 && (ti->StopTime() == delStop) )
763 log->log("JSONServer", Log::ERR, "Could not find timer");
764 js["Result"] = false;
765 js["Error"] = "Could not find timer";
769 if (Timers.BeingEdited())
771 log->log("JSONServer", Log::ERR, "Unable to delete timer - timers being edited at VDR");
772 js["Result"] = false;
773 js["Error"] = "Timers being edited at VDR";
779 log->log("JSONServer", Log::ERR, "Unable to delete timer - timer is running");
780 js["Result"] = false;
781 js["Error"] = "Timer is running";
786 Timers.SetModified();
792 bool jsonserver_timerset(Json::Value& js, const char* postData)
794 Log* log = Log::getInstance();
795 log->log("JSONServer", Log::DEBUG, "timerset");
797 char sTimerString[1024]; int mgv1 = mg_get_var(postData, strlen(postData), "timerstring", sTimerString, 1024);
801 log->log("JSONServer", Log::ERR, "Could not get timerstring");
802 js["Result"] = false;
803 js["Error"] = "Bad request parameters";
807 log->log("JSONServer", Log::DEBUG, "'%s'", sTimerString);
808 cTimer *timer = new cTimer;
809 if (!timer->Parse(sTimerString))
812 js["Result"] = false;
813 js["Error"] = "Failed to parse timer request details";
817 cTimer *t = Timers.GetTimer(timer);
821 js["Result"] = false;
822 js["Error"] = "Timer already exists";
827 Timers.SetModified();