@@ -402,115 +402,3 @@ int send_image_to_lcd(const Config *config, const char *image_path,
402402
403403 return success ;
404404}
405-
406- /**
407- * @brief Register shutdown image with CC4's persistent LCD shutdown endpoint.
408- * @details Called once at daemon startup. Sends the shutdown image path to
409- * PUT /devices/{uid}/settings/lcd/lcd/shutdown-image so CoolerControl
410- * displays it automatically whenever the CC daemon itself stops.
411- * Gracefully skips if the endpoint is unavailable.
412- */
413- int register_shutdown_image_with_cc (const Config * config ,
414- const char * image_path ,
415- const char * device_uid )
416- {
417- if (!validate_upload_params (image_path , device_uid ))
418- return 0 ;
419-
420- if (!image_path || !image_path [0 ])
421- return 1 ;
422-
423- /* Verify the file exists before attempting to register */
424- FILE * f = fopen (image_path , "r" );
425- if (!f )
426- {
427- log_message (LOG_WARNING ,
428- "CC4 shutdown registration skipped: image not found: %s" ,
429- image_path );
430- return 0 ;
431- }
432- fclose (f );
433-
434- char upload_url [CC_URL_SIZE ];
435- int written = snprintf (upload_url , sizeof (upload_url ),
436- "%s/devices/%s/settings/lcd/lcd/shutdown-image" ,
437- config -> daemon_address , device_uid );
438- if (!validate_snprintf (written , sizeof (upload_url ), upload_url ))
439- return 0 ;
440-
441- /* Build JSON body matching LcdSettings schema */
442- json_t * body = json_object ();
443- if (!body )
444- {
445- log_message (LOG_ERROR , "Failed to create JSON object for shutdown image" );
446- return 0 ;
447- }
448-
449- json_object_set_new (body , "mode" , json_string ("image" ));
450- json_object_set_new (body , "image_file_processed" , json_string (image_path ));
451- json_object_set_new (body , "brightness" , json_integer (config -> lcd_brightness ));
452- json_object_set_new (body , "orientation" , json_integer (config -> lcd_orientation ));
453- json_object_set_new (body , "colors" , json_array ());
454-
455- char * json_str = json_dumps (body , JSON_COMPACT );
456- json_decref (body );
457- if (!json_str )
458- {
459- log_message (LOG_ERROR , "Failed to serialize shutdown image JSON" );
460- return 0 ;
461- }
462-
463- http_response response = {0 };
464- if (!cc_init_response_buffer (& response , 4096 ))
465- {
466- free (json_str );
467- return 0 ;
468- }
469-
470- curl_easy_setopt (cc_session .curl_handle , CURLOPT_URL , upload_url );
471- curl_easy_setopt (cc_session .curl_handle , CURLOPT_CUSTOMREQUEST , "PUT" );
472- curl_easy_setopt (cc_session .curl_handle , CURLOPT_POSTFIELDS , json_str );
473- curl_easy_setopt (
474- cc_session .curl_handle , CURLOPT_WRITEFUNCTION ,
475- (size_t (* )(const void * , size_t , size_t , void * ))write_callback );
476- curl_easy_setopt (cc_session .curl_handle , CURLOPT_WRITEDATA , & response );
477-
478- struct curl_slist * headers = NULL ;
479- headers = curl_slist_append (headers , "Content-Type: application/json" );
480- headers = curl_slist_append (headers , "User-Agent: CoolerDash/1.0" );
481- headers = curl_slist_append (headers , "Accept: application/json" );
482- headers = curl_slist_append (headers , cc_session .access_token );
483- curl_easy_setopt (cc_session .curl_handle , CURLOPT_HTTPHEADER , headers );
484-
485- CURLcode res = curl_easy_perform (cc_session .curl_handle );
486- long http_code = -1 ;
487- curl_easy_getinfo (cc_session .curl_handle , CURLINFO_RESPONSE_CODE , & http_code );
488-
489- int success = 0 ;
490- if (res == CURLE_OK && (http_code == 200 || http_code == 204 ))
491- {
492- log_message (LOG_STATUS ,
493- "Shutdown image registered with CC4 (HTTP %ld)" , http_code );
494- success = 1 ;
495- }
496- else if (res == CURLE_OK && http_code == 404 )
497- {
498- log_message (LOG_WARNING ,
499- "CC4 shutdown image endpoint not available (HTTP 404) "
500- "- requires CoolerControl 4.0 or later" );
501- }
502- else
503- {
504- log_message (LOG_WARNING ,
505- "Shutdown image registration failed: CURL %d, HTTP %ld" ,
506- res , http_code );
507- }
508-
509- cc_cleanup_response_buffer (& response );
510- if (headers )
511- curl_slist_free_all (headers );
512- free (json_str );
513- reset_curl_request_options ();
514-
515- return success ;
516- }
0 commit comments