summaryrefslogblamecommitdiffstats
path: root/src/archive/microhttpd.c
blob: c75d71556a4829cd7c90e5c229f47cad059f9395 (plain) (tree)


















































                                                                                                                                  
#include <microhttpd.h>

// HTTP request handler
enum MHD_Result handle_request(void *cls, struct MHD_Connection *connection,
                               const char *url, const char *method,
                               const char *version, const char *upload_data,
                               size_t *upload_data_size, void **con_cls) {
  (void)version;
  (void)upload_data;
  (void)upload_data_size;
  (void)con_cls;
  struct MHD_Response *response;
  enum MHD_Result ret;

  if (strcmp(url, "/slider") == 0 && strcmp(method, "GET") == 0) {
    const char *value_str = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "value");
    if (value_str) {
      int value = atoi(value_str);
      handle_slider_change(cls, value);
    }
    response = MHD_create_response_from_buffer(0, "", MHD_RESPMEM_PERSISTENT);
    ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
    MHD_destroy_response(response);
    return ret;
  }

  if (strcmp(url, "/button") == 0 && strcmp(method, "GET") == 0) {
    handle_button_click(cls);
    response = MHD_create_response_from_buffer(0, "", MHD_RESPMEM_PERSISTENT);
    ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
    MHD_destroy_response(response);
    return ret;
  }

  response = MHD_create_response_from_buffer(strlen(html_content), (void *)html_content, MHD_RESPMEM_PERSISTENT);
  ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
  MHD_destroy_response(response);
  return ret;
}


  // Start the HTTP server
  server = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION, HTTP_PORT, NULL, NULL, &handle_request, (void *)synth, MHD_OPTION_END);
  if (server == NULL) {
    fprintf(stderr, "Failed to start server\n");
    return;
  }



  MHD_stop_daemon(server);