/src/ckl.h

https://github.com/ggreer/ckl · C Header · 105 lines · 68 code · 15 blank · 22 comment · 0 complexity · 3b7b8704dd817002298ccfdff4d0d1dd MD5 · raw file

  1. /*
  2. * Licensed to Cloudkick, Inc under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * Cloudkick licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #ifndef _ckl_h_
  18. #define _ckl_h_
  19. #include <string.h>
  20. #include <unistd.h>
  21. #include <stdlib.h>
  22. #include <ctype.h>
  23. #include <curl/curl.h>
  24. #include <curl/types.h>
  25. #include <curl/easy.h>
  26. #ifndef HOST_NAME_MAX
  27. #define HOST_NAME_MAX 255
  28. #endif
  29. typedef struct ckl_transport_t {
  30. CURL *curl;
  31. const char *append_url;
  32. struct curl_slist *headerlist;
  33. struct curl_httppost *formpost;
  34. struct curl_httppost *lastptr;
  35. } ckl_transport_t;
  36. typedef struct ckl_conf_t {
  37. int script_mode;
  38. int quiet;
  39. const char *endpoint;
  40. const char *secret;
  41. const char *oauth_key;
  42. const char *oauth_secret;
  43. const char *name;
  44. } ckl_conf_t;
  45. typedef struct ckl_msg_t {
  46. time_t ts;
  47. const char *username;
  48. const char *hostname;
  49. const char *msg;
  50. const char *script_log;
  51. } ckl_msg_t;
  52. typedef struct ckl_script_t {
  53. const char *shell;
  54. FILE *fd;
  55. char *path;
  56. } ckl_script_t;
  57. /* util functions */
  58. void ckl_error_out(const char *msg);
  59. void ckl_nuke_newlines(char *p);
  60. int ckl_tmp_file(char **path, FILE **fd);
  61. const char *ckl_hostname();
  62. /* transport fucntions */
  63. int ckl_transport_init(ckl_transport_t *t, ckl_conf_t *conf);
  64. void ckl_transport_free(ckl_transport_t *t);
  65. int ckl_transport_msg_send(ckl_transport_t *t,
  66. ckl_conf_t *conf,
  67. ckl_msg_t* m);
  68. int ckl_transport_list(ckl_transport_t *t,
  69. ckl_conf_t *conf,
  70. int count);
  71. int ckl_transport_detail(ckl_transport_t *t,
  72. ckl_conf_t *conf,
  73. const char *slug);
  74. /* script functions */
  75. int ckl_script_init(ckl_script_t *s, ckl_conf_t *conf);
  76. int ckl_script_record(ckl_script_t *s, ckl_msg_t *msg);
  77. void ckl_script_free(ckl_script_t *s);
  78. /* configuration functions */
  79. int ckl_conf_init(ckl_conf_t *conf);
  80. void ckl_conf_free(ckl_conf_t *conf);
  81. /* msg functions */
  82. int ckl_msg_init(ckl_msg_t *msg);
  83. void ckl_msg_free(ckl_msg_t *m);
  84. /* editor functions */
  85. int ckl_editor_find(const char **output);
  86. int ckl_editor_setup_file(char **path, FILE **fd);
  87. int ckl_editor_fill_file(ckl_conf_t *conf, ckl_msg_t *m, FILE *fd);
  88. int ckl_editor_edit(const char* editor, const char *path);
  89. int ckl_editor_read_file(ckl_msg_t *m, const char *path);
  90. #endif