TReK ANSI-C  5.3.3
All ANSI-C APIs
texting_example/main.c
// ////////////////////////////////////////////////////////////////////////////
//
// Example program initializes the email library using an imaginary
// email account and attempts to send a text to an imaginary group of cell
// phone numbers. The configuration is saved in a file and the configuration
// file is then used to send a second text to an imaginary group of cell
// phone numbers. This program does not actually send a text. A real email
// account and group are required to actually send a text.
//
// ////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "trek_error.h"
#include <sys/timeb.h>
#include <string.h>
#include "ds_shared.h"
#ifdef __linux__
#include <unistd.h>
#else
#include <Windows.h>
#endif
// ////////////////////////////////////////////////////////////////////////////
//
// PrintTheMessage controls how messages are processed and displayed to
// the user.
//
// ////////////////////////////////////////////////////////////////////////////
void PrintTheMessage(message_struct_type *mess_struct_ptr)
{
printf("%s%s\n", GetMessageCategoryAsPaddedString(mess_struct_ptr->category),
mess_struct_ptr->message);
}
// ////////////////////////////////////////////////////////////////////////////
//
// Example program initializes the email library using an imaginary
// email account and attempts to send a text to an imaginary group of cell
// phone numbers. The configuration is saved in a file and the configuration
// file is then used to send a second text to an imaginary group of cell
// phone numbers. This program does not actually send a text. A real email
// account and group are required to actually send a text..
//
// ////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
char smtp_server_address[50];
char email_account_username[50];
char email_account_password[50];
char email_address[50];
char email_name[50];
boolean_type verify_cert_authorities;
boolean_type generate_curl_debug_messages;
char text_to_cell_phone_number[50];
char text_to_cell_phone_carrier[50];
char group_name[50];
char text[50];
strcpy(smtp_server_address, "smtp.gmail.com");
strcpy(email_account_username, "mrsock@gmail.com");
strcpy(email_account_password, "liveandprosper");
strcpy(email_address, "mrsock@gmail.com");
strcpy(email_name, "Mr Sock");
verify_cert_authorities = FALSE_OR_NO;
generate_curl_debug_messages = TRUE_OR_YES;
// Register the PrintMessage callback function prior to InitializeToolkitEmail to
// process error messages that may be generated during initialization
RegisterMessage(&PrintTheMessage);
// Intializes the email and texting library using input parameters. This function creates the
// texting thread.
if (InitializeToolkitEmail(smtp_server_address, email_account_username, email_account_password,
email_address, email_name, verify_cert_authorities, generate_curl_debug_messages) == SUCCESS)
{
// Adds "to" cell phone number to a list of cell phone numbers and associate the number with a
// group name.
strcpy(text_to_cell_phone_number, "123-456-7890");
strcpy(text_to_cell_phone_carrier, "T-MOBILE");
strcpy(group_name, "dogs rule");
if (AddTextToCellPhoneNumber(text_to_cell_phone_number, text_to_cell_phone_carrier, group_name) == SUCCESS)
{
strcpy(text_to_cell_phone_number, "2345678901");
strcpy(text_to_cell_phone_carrier, "AT&T");
// Add second cell phone number and associate the number with a group name.
if (AddTextToCellPhoneNumber(text_to_cell_phone_number, text_to_cell_phone_carrier, group_name) == SUCCESS)
{
// Create the text message.
strcpy(text, "Dogs are smarter than cats.");
// Sends the text to the designated cell phone numbers associated with the group name.
if (SendText(text, group_name) != SUCCESS)
{
printf("Error Failed to SendText.\n");
return 0;
}
}
else
{
printf("Error Failed to AddTextToCellPhoneNumber.\n");
return 0;
}
}
else
{
printf("Error Failed to AddTextToCellPhoneNumber.\n");
return 0;
}
}
else
{
printf("Error Failed to InitializeToolkitEmail.\n");
return 0;
}
// Sleep 10 second prior to exiting.
#ifdef __linux__
sleep(10);
#else
Sleep(10000);
#endif
char config_pathname[256];
char home_path[256];
if (TCAACGetHomeDirectory(home_path, sizeof(home_path)) != SUCCESS)
{
return(FAIL);
}
sprintf(config_pathname, "%s/email_config.txt", home_path);
// Save the configuration in a file
SaveToolkitEmailConfig(config_pathname);
// Now send a text using the configuration file
if (InitToolkitEmail(config_pathname, "liveandprosper") != SUCCESS)
{
printf("Error Failed to InitToolkitEmail.\n");
}
// Create the text message.
strcpy(text, "Dogs are smarter than cats.");
// Sends the text to the designated cell phone numbers associated with the group name.
if (SendText(text, group_name) != SUCCESS)
{
printf("Error Failed to SendEmail.\n");
return 0;
}
// Sleep 10 second prior to exiting.
#ifdef __linux__
sleep(10);
#else
Sleep(10000);
#endif
return 0;
}
Message codes and structure definition for the Device Service library.
boolean_type
Boolean enumeration.
Definition: ds_shared.h:104
@ FALSE_OR_NO
False.
Definition: ds_shared.h:105
@ TRUE_OR_YES
True.
Definition: ds_shared.h:106
Structure of parameters needed for message support.
Definition: trek_toolkit_common_api_ansi_c.h:74
char message[MAX_MESSAGE_SIZE]
Message.
Definition: trek_toolkit_common_api_ansi_c.h:77
enum message_category category
Message category (e.g., MSG_CAT_ERROR, MSG_CAT_ERROR_ALERT, MSG_CAT_WARNING, MSG_CAT_WARNING_ALERT,...
Definition: trek_toolkit_common_api_ansi_c.h:76
An ANSI C Data Service API.
int EXPORT_THIS_TOOLKIT_DS_C_FUNCTION DSCleanUp()
Initiates a graceful shutdown of the Device Service library and all supporting device libraries,...
Definition: toolkit_ds_api_ansi_c.cpp:3843
int EXPORT_THIS_TOOLKIT_DS_C_FUNCTION RegisterMessage(void(*function_ptr)(message_struct_type *message_struct_ptr))
Register a callback function to receive and process messages issued by the DS library.
Definition: toolkit_ds_api_ansi_c.cpp:3951
An ANSI C email device API.
int EXPORT_THIS_TOOLKIT_EMAIL_DEVICE_C_FUNCTION InitToolkitEmail(const char *config_pathname, const char *email_account_password)
Intializes the email and texting library using parameters read from a configuration file.
Definition: toolkit_email_device_api_ansi_c.cpp:72
int EXPORT_THIS_TOOLKIT_EMAIL_DEVICE_C_FUNCTION AddTextToCellPhoneNumber(const char *text_to_cell_phone_number, const char *text_to_cell_phone_carrier, const char *text_to_group_name)
Adds "text to" cell phone numbers to a list of cell phone numbers and associates the cell phone numbe...
Definition: toolkit_email_device_api_ansi_c.cpp:570
int EXPORT_THIS_TOOLKIT_EMAIL_DEVICE_C_FUNCTION SendText(const char *text, const char *cell_phone_number_or_group_name)
Sends a text to the designated cell_phone_number or group of recipients. The maximum length of a text...
Definition: toolkit_email_device_api_ansi_c.cpp:1368
int EXPORT_THIS_TOOLKIT_EMAIL_DEVICE_C_FUNCTION InitializeToolkitEmail(const char *smtp_server_address, const char *email_account_username, const char *email_account_password, const char *email_address, const char *email_name, boolean_type verify_cert_authorities, boolean_type generate_curl_debug_messages)
Intializes the email and texting library using input parameters.
Definition: toolkit_email_device_api_ansi_c.cpp:256
int EXPORT_THIS_TOOLKIT_EMAIL_DEVICE_C_FUNCTION SaveToolkitEmailConfig(const char *config_pathname)
Saves the email and texting configuration parameters in a text file.
Definition: toolkit_email_device_api_ansi_c.cpp:1458
Command codes for TReK.
#define SUCCESS
The function completed successfully.
Definition: trek_error.h:8
#define FAIL
The function failed for an unknown reason.
Definition: trek_error.h:9
The commonly shared macros, structures and functions.
int EXPORT_THIS_TREK_TOOLKIT_COMMON_API_FUNCTION TCAACGetHomeDirectory(char *directory_buffer, int buffer_size)
Gets the path to the users home directory.
Definition: trek_toolkit_common_api_ansi_c.cpp:142
const char EXPORT_THIS_TREK_TOOLKIT_COMMON_API_FUNCTION * GetMessageCategoryAsPaddedString(enum message_category input)
Converts an enumerated message category value into its equivalent character string with padded spaces...
Definition: trek_toolkit_common_api_ansi_c.cpp:90