Example #1
0
//==========================================================================================================
// Return the value of last_* variable
//==========================================================================================================
string ScriptReader::get_last_value(string& var, int call_number, bool just_value)
{
    SipMessage* last_msg = get_last_message(call_number);
    
    if(last_msg == nullptr)
    {
        throw string("Can't use last_*, no previous messages");
    }
    return last_msg->get_value(var, just_value);
}
Example #2
0
int main(int argc, char *argv[])
{
    const int SLEEP_TIME = 30;      /* Time to sleep between messages */
    int count = 0;                  /* Number of completed SLEEP_TIME intervals */
    int unslept;                    /* Time remaining in sleep interval */
    struct sigaction sa;

    /* We begin using the libgsocial library */
    gsocial_init();
    gsocial_set_consumer_keys(consu_key, consu_secret);
    read_keys(&key, &secret);
    gsocial_set_access_keys(key, secret);

    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    sa.sa_handler = tweetd_sigup_handler;

    if (sigaction(SIGHUP, &sa, NULL) == -1)
        perror("sigaction");

    if (tweetd_daemonize() == -1)
        _exit(EXIT_FAILURE);

    tweetd_log_open(LOG_FILE);
    tweetd_read_config_file(CONFIG_FILE);

    unslept = SLEEP_TIME;

    /*
     * Main Loop.
     */
    while (1) {
        unslept = sleep(unslept);       /* Returns > 0 if interrupted */

        if (hupReceived) {              /* If we got SIGHUP... */
            hupReceived = 0;            /* Get ready for next SIGHUP */
            tweetd_log_close();
            tweetd_log_open(LOG_FILE);
            tweetd_read_config_file(CONFIG_FILE);
        }

        if (unslept == 0) {             /* On completed interval */
            count++;
            char * last_msg = get_last_message();
            char * action;
            if (last_msg != NULL && first_time == 1) {
                log_message("Last message: %s\n", last_msg);
                if(tweetd_handle_action(last_msg, &action) == 0) {
                    log_message("handle_action: %s\n", action);
                    log_message("Everything went OK");
                    //gsocial_send_message(screen_name, //		last_msg);
                    char tweet[140];
                    sprintf(tweet, "@%s:  %s", screen_name, "Done");
                    int sended = gsocial_send_tweet(strdup(tweet));
                    if(sended)
                        log_message("Action responded");
                    else
                        log_message("Something is wrong with sending the message");
                } else {
                    log_message("Everything went WRONG");
                }
            }
            first_time = 1;
            unslept = SLEEP_TIME;       /* Reset interval */
        }
    }
}