This commit is contained in:
ccppi_production 2024-09-04 07:28:24 +00:00
commit 245ee35af5
3 changed files with 85 additions and 0 deletions

1
comile.sh Normal file
View File

@ -0,0 +1 @@
gcc main.c -lcurl -Wall -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include -ldbus-1

1
dep.C_INCLUDE_PATH Normal file
View File

@ -0,0 +1 @@
/usr/include/dbus-1.0/:/usr/lib/dbus-1.0/include/

83
main.c Normal file
View File

@ -0,0 +1,83 @@
#include<stdio.h>
#include<curl/curl.h>
#include<string.h>
#include<dbus/dbus.h>
int gotify_message(char *,char *,char *);
/*
*sytemctl show gotify-server | grep PID
* */
int main(void)
{
unsigned long uid;
int ret;
dbus_bool_t allow_user=0;
DBusConnection *connection=NULL;
DBusError error;
dbus_error_init(&error);
connection = dbus_bus_get(DBUS_BUS_SYSTEM,&error);
if(dbus_error_is_set(&error))
{
fprintf(stderr,"%s",error.message);
return -1;
}
printf("This is my unique dbus name: %s\n",dbus_bus_get_unique_name(connection));
dbus_connection_set_allow_anonymous(connection,allow_user);
printf("user auth dbus requ: %d\n",allow_user);
dbus_connection_list_registered(connection,"/",
if((ret=dbus_connection_get_unix_user(connection,&uid))==1)
{
printf("found USERID:%ld",uid);
}
else
{
printf("NO userID set in dbus session: %d\n",ret);
}
gotify_message("https://5ccppi.org:4433/message?token=ApPFbwayM5zDXf3","anothertitle","anothermessage");
return 0;
}
int gotify_message(char *url,char *title,char *message)
{
int ret;
CURL *curl;
CURLcode res;
char post_buffer[128];
curl = curl_easy_init();
ret = snprintf(post_buffer,sizeof(post_buffer),"title=%s&message=%s",title,message);
if(ret < sizeof(post_buffer))
{
printf("%s %d",post_buffer,ret);
if(curl)
{
curl_easy_setopt(curl,CURLOPT_URL,url);
curl_easy_setopt(curl,CURLOPT_POSTFIELDS,post_buffer);
curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,1L);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
fprintf(stderr,"curl_easy_perform failed: %s",curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
}
}
else{
printf("Error on string concelblalbla: %d",ret);
}
return 0;
}