Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- interviewer an/abmelden, pausieren/fortfahren
- evtl. funktion um zu letzt angemeldeten abzumelden
- evtl. funktion um alle an/abzumelden
- -> woher session_ids und agent_log_ids?
- - gespeichert in globalen variablen: session, agent_log_id
- - oder via parameter übergeben an die entsprechende Funktion
- Anmerkung: in misc.cpp Funktionen zum allozieren und freigeben von Speicher
- jetzt curl_easy_init()/curl_easy_cleanup(curl) nur 1x in main(),
- vorher bei jeder funktion 1x am anfang + 1x am ende
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* for regex */
- #include "misc.h"
- /* for debugging */
- #include <assert.h>
- #include <signal.h>
- /* compile error, if included */
- #include "memwatch.h"
- /* cURL includes */
- #include <curl/curl.h>
- #include <curl/types.h>
- #include <curl/easy.h>
- struct MemoryStruct {
- char *memory;
- size_t size;
- };
- CURL *curl;
- CURLcode res;
- struct MemoryStruct chunk;
- struct curl_httppost *formpost = NULL;
- struct curl_httppost *lastptr = NULL;
- int i,n,m = 0;
- int choice = 0;
- char *data = NULL;
- char *session = NULL ;
- char *agent_log_id = NULL;
- char *user = NULL;
- char *pass = NULL;
- char *phone = NULL;
- char *phone_pass = NULL;
- char *campaign = NULL;
- char *temp = NULL;
- char *temp2 = NULL;
- char *conf_exten = NULL;
- char *zap_extension = NULL;
- static const char buf[] = "Expect:";
- static void *myrealloc(void *ptr, size_t size);
- static void *myrealloc(void *ptr, size_t size) {
- /* There might be a realloc() out there that doesn't like reallocing
- NULL pointers, so we take care of it here */
- if(ptr)
- return realloc(ptr, size);
- else
- return malloc(size);
- }
- /* WriteMemory for retrieving the HTTP response */
- static size_t
- WriteMemory(void *ptr, size_t size, size_t nmemb, void *data) {
- size_t realsize = size * nmemb;
- struct MemoryStruct *mem = (struct MemoryStruct *)data;
- mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
- if (mem->memory) {
- memcpy(&(mem->memory[mem->size]), ptr, realsize);
- mem->size += realsize;
- mem->memory[mem->size] = 0;
- }
- return realsize;
- }
- /*
- WICHTIG: phone_pass und pass werden x-fach hintereinander gehangen,
- somit mehrere anmeldungen noch unmöglich
- -> z.b. phone_pass = 400140014001
- */
- void login() {
- /* 1 Mal je Transfer, mit dazugehörigem curl_easy_cleanup(curl); */
- curl = curl_easy_init();
- if(curl) {
- printf("Welchen Interviewer moechten Sie anmelden? ");
- scanf("%4s", user);
- printf("\n user = ");
- printf(user);
- printf ("\nAn welchem Telefon moechten Sie den Interviewer anmelden? ");
- scanf("%5s", phone);
- strcat(data, "DB=&phone_login=");
- strcat(data, phone);
- strcat(data, "&phone_pass=");
- /* auto get phone_pass with the help of phone (phone == phone_pass) */
- /* einfach phone_pass = &phone!!! */
- if (strlen(phone_pass) < 4) {
- phone_pass = phone;
- printf("PHONEPASS = ");
- printf(phone_pass);
- /*
- for (i=4001; i<=4003; i++) {
- n = sprintf(temp,"%d",i);
- if (strcmp(temp,phone) == 0) {
- printf("\n");
- strcat(phone_pass,temp);
- printf("PHONEPASS = ");
- printf(phone_pass);
- printf("\n");
- }
- }
- */
- }
- strcat(data, phone_pass);
- strcat(data, "&VD_login=");
- strcat(data, user);
- strcat(data, "&VD_pass=");
- /* auto get pass with the help of user (user == pass) */
- /* einfach pass = &user!!! */
- if (strlen(pass) < 3) {
- pass = user;
- printf("PASS = ");
- printf(pass);
- printf("\n");
- /*
- for (i=101; i<=103; i++) {
- n = sprintf(temp,"%d",i);
- if (strcmp(temp,user) == 0) {
- printf("\n");
- strcat(pass,temp);
- printf("PASS = ");
- printf(pass);
- printf("\n");
- }
- }
- */
- }
- strcat(data, pass);
- strcat(data, "&VD_campaign=111&SUBMIT=SUBMIT");
- printf("\nDATA = ");
- printf(data);
- printf("\n");
- /* what URL receives this POST */
- curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.101.10/agc/vicidial.php");
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemory);
- /* we pass our 'chunk' struct to the callback function */
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
- /* post away! */
- res = curl_easy_perform(curl);
- if(res != CURLE_OK) {
- curl_easy_cleanup(curl);
- printf("Error: ");
- printf(curl_easy_strerror(res));
- printf("\n");
- }
- if (chunk.memory) {
- printf("\n\nETWAS IN CHUNK.MEMORY!!!!\n\n");
- //printf(chunk.memory);
- }
- else {
- printf("\n\nNICHTS IN CHUNK.MEMORY!!!!\n\n");
- printf("\n\nEVTL. KEINE LEADS IN CAMPAIGN!!!!\n\n");
- }
- }
- /* get session from chunk.memory via regex */
- session = pcre_extract(chunk.memory, "var session_name = '([0-9_]+)'" );
- printf("\n\nSESSION = ");
- printf(session);
- printf("\n");
- /* GET agent_log_id from chunk.memory */
- agent_log_id = pcre_extract(chunk.memory, "var agent_log_id = '([0-9]+)'" );
- printf("\n\nAGENT LOG ID = ");
- printf(agent_log_id);
- printf("\n");
- /* var extension = '1'; */
- /* GET zap_extension from chunk.memory */
- zap_extension = pcre_extract(chunk.memory, "var extension = '([0-9])'" );
- printf("\n\nZAP_EXTENSION = ");
- printf(zap_extension);
- printf("\n");
- /* var session_id = '8600051'; */
- /* get conf_exten(sion) from session_id */
- conf_exten = pcre_extract(chunk.memory, "var session_id = '([0-9]+)'" );
- printf("\n\nCONF_EXTENSION = ");
- printf(conf_exten);
- printf("\n");
- printf("curl_easy_cleanup(curl);");
- curl_easy_cleanup(curl);
- printf("\n");
- /* free memory */
- /*
- if(chunk.memory) free(chunk.memory);
- if(data) free(data);
- if (temp) free(temp);
- */
- }
- /* aktiviert den zuletzt angemeldeten Interviewer */
- /* resume und pause via JavaScript, rufen vdc_db_query.php mit entsprechenden Daten auf */
- void resume () {
- curl = curl_easy_init();
- if(curl) {
- strcat(data, "server_ip=192.168.101.10&session_name=");
- if (session && agent_log_id) {
- printf("SESSION = ");
- printf(session);
- printf("\nagent_log_id = ");
- printf(agent_log_id);
- printf("\n");
- strcat(data, session);
- strcat(data, "&ACTION=VDADready&user=");
- strcat(data, user);
- strcat(data, "&pass=");
- strcat(data, pass);
- strcat(data, "&stage=READY&agent_log_id=");
- strcat(data, agent_log_id);
- strcat(data, "&agent_log=undefined&wrapup=undefined&campaign=111");
- printf("TEST12\n");
- /* what URL receives this POST */
- curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.101.10/agc/vdc_db_query.php");
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
- //curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, temp2);
- printf("TEST13\n");
- printf("TEST14\n");
- //curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemory);
- printf("TEST15\n");
- /* we pass our 'chunk' struct to the callback function */
- //curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
- printf("TEST16\n");
- // SEGMENTATION FAULT!!!!!!!!!!!!!11
- /* post away! */
- res = curl_easy_perform(curl);
- if(res != CURLE_OK) {
- //curl_easy_cleanup(curl);
- printf("Error: ");
- printf(curl_easy_strerror(res));
- printf("\n");
- }
- //printf("CURLOPT_ERRORBUFFER - temp2 = ");
- //printf(temp2);
- printf("\nTEST17\n");
- }
- /* session, id etc. aus vars/params oder kommandozeile holen */
- else {
- }
- // 1x weiter als TEST16
- // Interviewer resume OK, aber double free or corruption (out): 0x0805d7c8
- // curl_easy_cleanup+0x21
- printf("\nTEST18\n");
- printf("\n");
- printf("curl_easy_cleanup(curl);");
- curl_easy_cleanup(curl);
- printf("\nTEST19 - nach easy cleanup in resume()\n");
- printf("\n");
- }
- }
- /* aktiviert/deaktiviert interviewer mit übergebener session, user, pass, ...
- int resume_pause (char *session, char *user, char *pass, char *agent_log_id, char *campaign, char *action) { }
- */
- /* deaktiviert den zuletzt angemeldeten Interviewer
- wie resume nur mit ACTION=VDADpause und stage=PAUSED
- */
- void pause () {
- curl = curl_easy_init();
- if(curl) {
- strcat(data, "server_ip=192.168.101.10&session_name=");
- if (session && agent_log_id) {
- printf("SESSION = ");
- printf(session);
- printf("\nagent_log_id = ");
- printf(agent_log_id);
- printf("\n");
- strcat(data, session);
- strcat(data, "&ACTION=VDADpause&user=");
- strcat(data, user);
- strcat(data, "&pass=");
- strcat(data, pass);
- strcat(data, "&stage=PAUSED&agent_log_id=");
- strcat(data, agent_log_id);
- strcat(data, "&agent_log=undefined&wrapup=undefined&campaign=111");
- printf("TEST12\n");
- /* what URL receives this POST */
- curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.101.10/agc/vdc_db_query.php");
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
- //curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, temp2);
- printf("TEST13\n");
- printf("TEST14\n");
- //curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemory);
- printf("TEST15\n");
- /* we pass our 'chunk' struct to the callback function */
- //curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
- printf("TEST16\n");
- /* post away! */
- curl_easy_perform(curl);
- res = curl_easy_perform(curl);
- if(res != CURLE_OK) {
- curl_easy_cleanup(curl);
- printf("Error: ");
- printf(curl_easy_strerror(res));
- printf("\n");
- }
- //printf("CURLOPT_ERRORBUFFER - temp2 = ");
- //printf(temp2);
- printf("\nTEST17\n");
- }
- /* session, id etc. aus vars/params oder von kommandozeile holen */
- else {
- }
- printf("\nTEST18\n");
- printf("\n");
- printf("curl_easy_cleanup(curl);");
- curl_easy_cleanup(curl);
- printf("\nTEST19 - nach easy cleanup in pause()\n");
- printf("\n");
- }
- }
- /* meldet den zuletzt angemeldeten Interviewer ab */
- void logout () {
- curl = curl_easy_init();
- if(curl) {
- strcat(data, "ACTION=userLOGout&LogouTKicKAlL=1&agent_log_id=");
- if (session && agent_log_id) {
- printf("\nagent_log_id = ");
- printf(agent_log_id);
- printf("\n");
- strcat(data, agent_log_id);
- strcat(data, "&campaign=");
- strcat(data, campaign);
- strcat(data, "&conf_exten=");
- // how to get conf_exten???
- strcat(data, conf_exten);
- strcat(data, "&enable_sipsak_messages=0&ext_context=default&extension=");
- // how to get zap extension???
- strcat(data, zap_extension);
- strcat(data, "&format=text&no_delete_sessions=0&pass=");
- strcat(data, pass);
- strcat(data, "&phone_ip=&protocol=zap&server_ip=192.168.101.10&session_name=");
- printf("SESSION = ");
- printf(session);
- strcat(data, session);
- strcat(data, "&user=");
- strcat(data, user);
- printf("TEST12\n");
- /* what URL receives this POST */
- curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.101.10/agc/vicidial.php");
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
- //curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, temp2);
- printf("TEST13\n");
- printf("TEST14\n");
- //curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemory);
- printf("TEST15\n");
- /* we pass our 'chunk' struct to the callback function */
- //curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
- printf("TEST16\n");
- /* post away! */
- res = curl_easy_perform(curl);
- if(res != CURLE_OK) {
- curl_easy_cleanup(curl);
- printf("Error: ");
- printf(curl_easy_strerror(res));
- printf("\n");
- }
- printf("\nTEST17\n");
- }
- /* session, id etc. aus vars/params oder von kommandozeile holen */
- else {
- }
- printf("\nTEST18\n");
- printf("\n");
- printf("curl_easy_cleanup(curl);");
- curl_easy_cleanup(curl);
- printf("\nTEST19 - nach easy cleanup in logout()\n");
- printf("\n");
- }
- }
- /*int main(int argc, char *argv[])*/
- int main() {
- agent_log_id = (char*)calloc(4, sizeof(char));
- user = (char*)calloc(4, sizeof(char));
- pass = (char*)calloc(4, sizeof(char));
- phone = (char*)calloc(5, sizeof(char));
- phone_pass = (char*)calloc(5, sizeof(char));
- conf_exten = (char*)calloc(8, sizeof(char));
- zap_extension = (char*)calloc(4, sizeof(char));
- /* ein Mal je Programm mit dazugehörigem curl_global_cleanup(); */
- curl_global_init(CURL_GLOBAL_ALL);
- // 1 mal je transfer, somit mehrfach, z.b. 1x je funktion
- //curl = curl_easy_init();
- chunk.memory = NULL; /* we expect realloc(NULL, size) to work */
- chunk.size = 0; /* no data at this point */
- while (choice != 5) {
- /*chunk.memory = NULL; we expect realloc(NULL, size) to work */
- /*chunk.size = 0; no data at this point */
- /* somit sind folgende variablen vor jedem funktionsaufruf leer */
- data = (char*)calloc(100, sizeof(char));
- temp = (char*)calloc(5, sizeof(char));
- temp2 = (char*)calloc(500, sizeof(char));
- printf ("\n\n");
- printf ("----------------------");
- printf ("Interviewer-Verwaltung");
- printf ("----------------------\n\n");
- printf ("1 - Einen Interviewer anmelden \n");
- printf ("2 - Den aktuellen Interviewer als bereit melden \n");
- printf ("3 - Den aktuellen Interviewer als nicht bereit melden \n");
- printf ("4 - Den aktuellen Interviewer vom System abmelden \n");
- printf ("----------------------\n");
- printf ("5 - Programm beenden\n\n");
- scanf("%d", &choice);
- switch (choice) {
- case 1:
- printf ("1 - Login Interviewer - gewaehlt\n");
- login();
- break;
- case 2:
- printf ("2 - Resume Interviewer - gewaehlt\n");
- resume();
- break;
- case 3:
- printf ("3 - Pause Interviewer - gewaehlt\n");
- pause();
- break;
- case 4:
- printf ("4 - Logout Interviewer - gewaehlt\n");
- logout();
- break;
- case 5:
- printf ("5 - Programm beenden - gewaehlt\n");
- break;
- default:
- printf ("Keine gueltige Eingabe! \n");
- printf ("ABBRUCH! \n");
- choice = 5;
- }
- }
- /* we're done with libcurl, so clean it up */
- printf("VOR!!!!!! CURL GLOBAL CLEAN UP!\n");
- if (curl) {
- printf("CURL GLOBAL CLEAN UP!\n");
- curl_global_cleanup();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment