inline int web_client_api_old_graph_request(RRDHOST *host, struct web_client *w, char *url) { // get the name of the data to show char *tok = mystrsep(&url, "/?&"); if(tok && *tok) { debug(D_WEB_CLIENT, "%llu: Searching for RRD data with name '%s'.", w->id, tok); // do we have such a data set? RRDSET *st = rrdset_find_byname(host, tok); if(!st) st = rrdset_find(host, tok); if(!st) { // we don't have it // try to send a file with that name buffer_flush(w->response.data); return mysendfile(w, tok); } st->last_accessed_time = now_realtime_sec(); debug(D_WEB_CLIENT_ACCESS, "%llu: Sending %s.json of RRD_STATS...", w->id, st->name); w->response.data->contenttype = CT_APPLICATION_JSON; buffer_flush(w->response.data); rrd_graph2json_api_old(st, url, w->response.data); return 200; } buffer_flush(w->response.data); buffer_strcat(w->response.data, "Graph name?\r\n"); return 400; }
inline int web_client_api_request_single_chart(RRDHOST *host, struct web_client *w, char *url, void callback(RRDSET *st, BUFFER *buf)) { int ret = 400; char *chart = NULL; buffer_flush(w->response.data); while(url) { char *value = mystrsep(&url, "?&"); if(!value || !*value) continue; char *name = mystrsep(&value, "="); if(!name || !*name) continue; if(!value || !*value) continue; // name and value are now the parameters // they are not null and not empty if(!strcmp(name, "chart")) chart = value; //else { /// buffer_sprintf(w->response.data, "Unknown parameter '%s' in request.", name); // goto cleanup; //} } if(!chart || !*chart) { buffer_sprintf(w->response.data, "No chart id is given at the request."); goto cleanup; } RRDSET *st = rrdset_find(host, chart); if(!st) st = rrdset_find_byname(host, chart); if(!st) { buffer_strcat(w->response.data, "Chart is not found: "); buffer_strcat_htmlescape(w->response.data, chart); ret = 404; goto cleanup; } w->response.data->contenttype = CT_APPLICATION_JSON; st->last_accessed_time = now_realtime_sec(); callback(st, w->response.data); return 200; cleanup: return ret; }
inline int web_client_api_request_v1_alarm_log(RRDHOST *host, struct web_client *w, char *url) { uint32_t after = 0; while(url) { char *value = mystrsep(&url, "?&"); if (!value || !*value) continue; char *name = mystrsep(&value, "="); if(!name || !*name) continue; if(!value || !*value) continue; if(!strcmp(name, "after")) after = (uint32_t)strtoul(value, NULL, 0); } buffer_flush(w->response.data); w->response.data->contenttype = CT_APPLICATION_JSON; health_alarm_log2json(host, w->response.data, after); return 200; }
inline int web_client_api_request_v1_alarms(RRDHOST *host, struct web_client *w, char *url) { int all = 0; while(url) { char *value = mystrsep(&url, "?&"); if (!value || !*value) continue; if(!strcmp(value, "all")) all = 1; else if(!strcmp(value, "active")) all = 0; } buffer_flush(w->response.data); w->response.data->contenttype = CT_APPLICATION_JSON; health_alarms2json(host, w->response.data, all); return 200; }
inline uint32_t web_client_api_request_v1_data_options(char *o) { uint32_t ret = 0x00000000; char *tok; while(o && *o && (tok = mystrsep(&o, ", |"))) { if(!*tok) continue; uint32_t hash = simple_hash(tok); int i; for(i = 0; api_v1_data_options[i].name ; i++) { if (unlikely(hash == api_v1_data_options[i].hash && !strcmp(tok, api_v1_data_options[i].name))) { ret |= api_v1_data_options[i].value; break; } } } return ret; }
inline int web_client_api_request_v1(RRDHOST *host, struct web_client *w, char *url) { static int initialized = 0; int i; if(unlikely(initialized == 0)) { initialized = 1; for(i = 0; api_commands[i].command ; i++) api_commands[i].hash = simple_hash(api_commands[i].command); } // get the command char *tok = mystrsep(&url, "/?&"); if(tok && *tok) { debug(D_WEB_CLIENT, "%llu: Searching for API v1 command '%s'.", w->id, tok); uint32_t hash = simple_hash(tok); for(i = 0; api_commands[i].command ;i++) { if(unlikely(hash == api_commands[i].hash && !strcmp(tok, api_commands[i].command))) { if(unlikely(api_commands[i].acl != WEB_CLIENT_ACL_NOCHECK) && !(w->acl & api_commands[i].acl)) return web_client_permission_denied(w); return api_commands[i].callback(host, w, url); } } buffer_flush(w->response.data); buffer_strcat(w->response.data, "Unsupported v1 API command: "); buffer_strcat_htmlescape(w->response.data, tok); return 404; } else { buffer_flush(w->response.data); buffer_sprintf(w->response.data, "Which API v1 command?"); return 400; } }
int main( int argc, char* argv[] ) { char* test[] = { strdup( "" ), strdup( "hello" ), strdup( "hello world" ), strdup( "hello world" ), strdup( "hello world\tthree" ), }; const int len = sizeof( test ) / sizeof( char* ); char* mytest[len], **ptr = NULL, **myptr = NULL; char* res = NULL, *myres = NULL, *sep = " "; int i; for ( i = 0; i < len; i++ ) { mytest[i] = strdup( test[i] ); } for ( i = 0; i < len; i++ ) { if ( i == 2 ) { sep = "\t "; } ptr = &test[i]; do { printf( "strsep( ptr = &\"%s\", \"%s\" )", *ptr, sep ); res = strsep( ptr, sep ); printf( " = \"%s\", ptr = \"%s\"\n", res, *ptr ); printf( "-------------\n" ); } while ( *ptr ); myptr = &mytest[i]; do { printf( "mystrsep( myptr = &\"%s\", \"%s\" )", *myptr, sep ); myres = mystrsep( myptr, sep ); printf( " = \"%s\", myptr = \"%s\"\n", myres, *myptr ); printf( "-------------\n" ); } while ( *myptr ); printf( "--------------------------\n" ); } }
inline int web_client_api_request_v1_registry(RRDHOST *host, struct web_client *w, char *url) { static uint32_t hash_action = 0, hash_access = 0, hash_hello = 0, hash_delete = 0, hash_search = 0, hash_switch = 0, hash_machine = 0, hash_url = 0, hash_name = 0, hash_delete_url = 0, hash_for = 0, hash_to = 0 /*, hash_redirects = 0 */; if(unlikely(!hash_action)) { hash_action = simple_hash("action"); hash_access = simple_hash("access"); hash_hello = simple_hash("hello"); hash_delete = simple_hash("delete"); hash_search = simple_hash("search"); hash_switch = simple_hash("switch"); hash_machine = simple_hash("machine"); hash_url = simple_hash("url"); hash_name = simple_hash("name"); hash_delete_url = simple_hash("delete_url"); hash_for = simple_hash("for"); hash_to = simple_hash("to"); /* hash_redirects = simple_hash("redirects"); */ } char person_guid[GUID_LEN + 1] = ""; debug(D_WEB_CLIENT, "%llu: API v1 registry with URL '%s'", w->id, url); // TODO // The browser may send multiple cookies with our id char *cookie = strstr(w->response.data->buffer, NETDATA_REGISTRY_COOKIE_NAME "="); if(cookie) strncpyz(person_guid, &cookie[sizeof(NETDATA_REGISTRY_COOKIE_NAME)], 36); char action = '\0'; char *machine_guid = NULL, *machine_url = NULL, *url_name = NULL, *search_machine_guid = NULL, *delete_url = NULL, *to_person_guid = NULL; /* int redirects = 0; */ while(url) { char *value = mystrsep(&url, "?&"); if (!value || !*value) continue; char *name = mystrsep(&value, "="); if (!name || !*name) continue; if (!value || !*value) continue; debug(D_WEB_CLIENT, "%llu: API v1 registry query param '%s' with value '%s'", w->id, name, value); uint32_t hash = simple_hash(name); if(hash == hash_action && !strcmp(name, "action")) { uint32_t vhash = simple_hash(value); if(vhash == hash_access && !strcmp(value, "access")) action = 'A'; else if(vhash == hash_hello && !strcmp(value, "hello")) action = 'H'; else if(vhash == hash_delete && !strcmp(value, "delete")) action = 'D'; else if(vhash == hash_search && !strcmp(value, "search")) action = 'S'; else if(vhash == hash_switch && !strcmp(value, "switch")) action = 'W'; #ifdef NETDATA_INTERNAL_CHECKS else error("unknown registry action '%s'", value); #endif /* NETDATA_INTERNAL_CHECKS */ } /* else if(hash == hash_redirects && !strcmp(name, "redirects")) redirects = atoi(value); */ else if(hash == hash_machine && !strcmp(name, "machine")) machine_guid = value; else if(hash == hash_url && !strcmp(name, "url")) machine_url = value; else if(action == 'A') { if(hash == hash_name && !strcmp(name, "name")) url_name = value; } else if(action == 'D') { if(hash == hash_delete_url && !strcmp(name, "delete_url")) delete_url = value; } else if(action == 'S') { if(hash == hash_for && !strcmp(name, "for")) search_machine_guid = value; } else if(action == 'W') { if(hash == hash_to && !strcmp(name, "to")) to_person_guid = value; } #ifdef NETDATA_INTERNAL_CHECKS else error("unused registry URL parameter '%s' with value '%s'", name, value); #endif /* NETDATA_INTERNAL_CHECKS */ } if(unlikely(respect_web_browser_do_not_track_policy && web_client_has_donottrack(w))) { buffer_flush(w->response.data); buffer_sprintf(w->response.data, "Your web browser is sending 'DNT: 1' (Do Not Track). The registry requires persistent cookies on your browser to work."); return 400; } if(unlikely(action == 'H')) { // HELLO request, dashboard ACL if(unlikely(!web_client_can_access_dashboard(w))) return web_client_permission_denied(w); } else { // everything else, registry ACL if(unlikely(!web_client_can_access_registry(w))) return web_client_permission_denied(w); } switch(action) { case 'A': if(unlikely(!machine_guid || !machine_url || !url_name)) { error("Invalid registry request - access requires these parameters: machine ('%s'), url ('%s'), name ('%s')", machine_guid ? machine_guid : "UNSET", machine_url ? machine_url : "UNSET", url_name ? url_name : "UNSET"); buffer_flush(w->response.data); buffer_strcat(w->response.data, "Invalid registry Access request."); return 400; } web_client_enable_tracking_required(w); return registry_request_access_json(host, w, person_guid, machine_guid, machine_url, url_name, now_realtime_sec()); case 'D': if(unlikely(!machine_guid || !machine_url || !delete_url)) { error("Invalid registry request - delete requires these parameters: machine ('%s'), url ('%s'), delete_url ('%s')", machine_guid?machine_guid:"UNSET", machine_url?machine_url:"UNSET", delete_url?delete_url:"UNSET"); buffer_flush(w->response.data); buffer_strcat(w->response.data, "Invalid registry Delete request."); return 400; } web_client_enable_tracking_required(w); return registry_request_delete_json(host, w, person_guid, machine_guid, machine_url, delete_url, now_realtime_sec()); case 'S': if(unlikely(!machine_guid || !machine_url || !search_machine_guid)) { error("Invalid registry request - search requires these parameters: machine ('%s'), url ('%s'), for ('%s')", machine_guid?machine_guid:"UNSET", machine_url?machine_url:"UNSET", search_machine_guid?search_machine_guid:"UNSET"); buffer_flush(w->response.data); buffer_strcat(w->response.data, "Invalid registry Search request."); return 400; } web_client_enable_tracking_required(w); return registry_request_search_json(host, w, person_guid, machine_guid, machine_url, search_machine_guid, now_realtime_sec()); case 'W': if(unlikely(!machine_guid || !machine_url || !to_person_guid)) { error("Invalid registry request - switching identity requires these parameters: machine ('%s'), url ('%s'), to ('%s')", machine_guid?machine_guid:"UNSET", machine_url?machine_url:"UNSET", to_person_guid?to_person_guid:"UNSET"); buffer_flush(w->response.data); buffer_strcat(w->response.data, "Invalid registry Switch request."); return 400; } web_client_enable_tracking_required(w); return registry_request_switch_json(host, w, person_guid, machine_guid, machine_url, to_person_guid, now_realtime_sec()); case 'H': return registry_request_hello_json(host, w); default: buffer_flush(w->response.data); buffer_strcat(w->response.data, "Invalid registry request - you need to set an action: hello, access, delete, search"); return 400; } }
// returns the HTTP code inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, char *url) { debug(D_WEB_CLIENT, "%llu: API v1 data with URL '%s'", w->id, url); int ret = 400; BUFFER *dimensions = NULL; buffer_flush(w->response.data); char *google_version = "0.6", *google_reqId = "0", *google_sig = "0", *google_out = "json", *responseHandler = NULL, *outFileName = NULL; time_t last_timestamp_in_data = 0, google_timestamp = 0; char *chart = NULL , *before_str = NULL , *after_str = NULL , *group_time_str = NULL , *points_str = NULL; int group = RRDR_GROUPING_AVERAGE; uint32_t format = DATASOURCE_JSON; uint32_t options = 0x00000000; while(url) { char *value = mystrsep(&url, "?&"); if(!value || !*value) continue; char *name = mystrsep(&value, "="); if(!name || !*name) continue; if(!value || !*value) continue; debug(D_WEB_CLIENT, "%llu: API v1 data query param '%s' with value '%s'", w->id, name, value); // name and value are now the parameters // they are not null and not empty if(!strcmp(name, "chart")) chart = value; else if(!strcmp(name, "dimension") || !strcmp(name, "dim") || !strcmp(name, "dimensions") || !strcmp(name, "dims")) { if(!dimensions) dimensions = buffer_create(100); buffer_strcat(dimensions, "|"); buffer_strcat(dimensions, value); } else if(!strcmp(name, "after")) after_str = value; else if(!strcmp(name, "before")) before_str = value; else if(!strcmp(name, "points")) points_str = value; else if(!strcmp(name, "gtime")) group_time_str = value; else if(!strcmp(name, "group")) { group = web_client_api_request_v1_data_group(value, RRDR_GROUPING_AVERAGE); } else if(!strcmp(name, "format")) { format = web_client_api_request_v1_data_format(value); } else if(!strcmp(name, "options")) { options |= web_client_api_request_v1_data_options(value); } else if(!strcmp(name, "callback")) { responseHandler = value; } else if(!strcmp(name, "filename")) { outFileName = value; } else if(!strcmp(name, "tqx")) { // parse Google Visualization API options // https://developers.google.com/chart/interactive/docs/dev/implementing_data_source char *tqx_name, *tqx_value; while(value) { tqx_value = mystrsep(&value, ";"); if(!tqx_value || !*tqx_value) continue; tqx_name = mystrsep(&tqx_value, ":"); if(!tqx_name || !*tqx_name) continue; if(!tqx_value || !*tqx_value) continue; if(!strcmp(tqx_name, "version")) google_version = tqx_value; else if(!strcmp(tqx_name, "reqId")) google_reqId = tqx_value; else if(!strcmp(tqx_name, "sig")) { google_sig = tqx_value; google_timestamp = strtoul(google_sig, NULL, 0); } else if(!strcmp(tqx_name, "out")) { google_out = tqx_value; format = web_client_api_request_v1_data_google_format(google_out); } else if(!strcmp(tqx_name, "responseHandler")) responseHandler = tqx_value; else if(!strcmp(tqx_name, "outFileName")) outFileName = tqx_value; } } } if(!chart || !*chart) { buffer_sprintf(w->response.data, "No chart id is given at the request."); goto cleanup; } RRDSET *st = rrdset_find(host, chart); if(!st) st = rrdset_find_byname(host, chart); if(!st) { buffer_strcat(w->response.data, "Chart is not found: "); buffer_strcat_htmlescape(w->response.data, chart); ret = 404; goto cleanup; } st->last_accessed_time = now_realtime_sec(); long long before = (before_str && *before_str)?str2l(before_str):0; long long after = (after_str && *after_str) ?str2l(after_str):0; int points = (points_str && *points_str)?str2i(points_str):0; long group_time = (group_time_str && *group_time_str)?str2l(group_time_str):0; debug(D_WEB_CLIENT, "%llu: API command 'data' for chart '%s', dimensions '%s', after '%lld', before '%lld', points '%d', group '%d', format '%u', options '0x%08x'" , w->id , chart , (dimensions)?buffer_tostring(dimensions):"" , after , before , points , group , format , options ); if(outFileName && *outFileName) { buffer_sprintf(w->response.header, "Content-Disposition: attachment; filename=\"%s\"\r\n", outFileName); debug(D_WEB_CLIENT, "%llu: generating outfilename header: '%s'", w->id, outFileName); } if(format == DATASOURCE_DATATABLE_JSONP) { if(responseHandler == NULL) responseHandler = "google.visualization.Query.setResponse"; debug(D_WEB_CLIENT_ACCESS, "%llu: GOOGLE JSON/JSONP: version = '%s', reqId = '%s', sig = '%s', out = '%s', responseHandler = '%s', outFileName = '%s'", w->id, google_version, google_reqId, google_sig, google_out, responseHandler, outFileName ); buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'ok',sig:'%ld',table:", responseHandler, google_version, google_reqId, st->last_updated.tv_sec); } else if(format == DATASOURCE_JSONP) { if(responseHandler == NULL) responseHandler = "callback"; buffer_strcat(w->response.data, responseHandler); buffer_strcat(w->response.data, "("); } ret = rrdset2anything_api_v1(st, w->response.data, dimensions, format, points, after, before, group, group_time , options, &last_timestamp_in_data); if(format == DATASOURCE_DATATABLE_JSONP) { if(google_timestamp < last_timestamp_in_data) buffer_strcat(w->response.data, "});"); else { // the client already has the latest data buffer_flush(w->response.data); buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'error',errors:[{reason:'not_modified',message:'Data not modified'}]});", responseHandler, google_version, google_reqId); } } else if(format == DATASOURCE_JSONP) buffer_strcat(w->response.data, ");"); cleanup: buffer_free(dimensions); return ret; }
// set data values in the radio message buffer es_Status es_tcl_track_radio_set(char* subcmd, char* arg, void (*appendResult)(char*, es_ClientData), es_ClientData data) { CompressedRadioMessage_TM *rm = &es_tcl_track_radio_buf; // header if( subcmd != NULL && !strcmp("header",subcmd) ) { if(arg==NULL) { snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid sub command 'set header': missing argument"); return ES_TCL_ERROR; } char *varname, *next; arg = strdup(arg); next = arg; appendResult(es_msg_buf,data); while((varname = mystrsep(&next," ")) != NULL) { char *v = mystrsep(&next," "); if( v == NULL ) { snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"missing value for variable %s",varname); return ES_TCL_ERROR; } int value = atoi(v); if( !strcmp("nid_message",varname) ) { rm->Header.nid_message = value; } else if( !strcmp("d_emergencystop",varname) ) { rm->Header.d_emergencystop = value; } else if( !strcmp("d_ref",varname) ) { rm->Header.d_ref = value; } else if( !strcmp("d_sr",varname) ) { rm->Header.d_sr = value; } else if( !strcmp("m_ack",varname) ) { rm->Header.m_ack = value; } else if( !strcmp("m_version",varname) ) { rm->Header.m_version = value; } else if( !strcmp("nid_em",varname) ) { rm->Header.nid_em = value; } else if( !strcmp("nid_lrbg",varname) ) { rm->Header.nid_lrbg = value; } else if( !strcmp("q_dir",varname) ) { rm->Header.q_dir = value; } else if( !strcmp("q_scale",varname) ) { rm->Header.q_scale = value; } else if( !strcmp("radioDevice",varname) ) { rm->Header.radioDevice = value; } else if( !strcmp("receivedSystemTime",varname) ) { rm->Header.receivedSystemTime = value; } else if( !strcmp("t_sh_rqst",varname) ) { rm->Header.t_sh_rqst = value; } else if( !strcmp("t_train",varname) ) { rm->Header.t_train = value; } else if( !strcmp("t_train_reference",varname) ) { rm->Header.t_train_reference = value; } else { snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid radio header variable: %s",varname); free(arg); return ES_TCL_ERROR; } } free(arg); return ES_OK; } snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid sub command '%s': expected 'header'",subcmd); return ES_TCL_ERROR; }
int parse_aff_file(FILE * afflst) { int i, j; int numents=0; char achar='\0'; short ff=0; char ft; struct affent * ptr= NULL; struct affent * nptr= NULL; char * line = malloc(MAX_LN_LEN); while (fgets(line,MAX_LN_LEN,afflst)) { mychomp(line); ft = ' '; fprintf(stderr,"parsing line: %s\n",line); if (strncmp(line,"FULLSTRIP",9) == 0) fullstrip = 1; if (strncmp(line,"PFX",3) == 0) ft = 'P'; if (strncmp(line,"SFX",3) == 0) ft = 'S'; if (ft != ' ') { char * tp = line; char * piece; ff = 0; i = 0; while ((piece=mystrsep(&tp,' '))) { if (*piece != '\0') { switch(i) { case 0: break; case 1: { achar = *piece; break; } case 2: { if (*piece == 'Y') ff = XPRODUCT; break; } case 3: { numents = atoi(piece); if ((numents < 0) || ((SIZE_MAX/sizeof(struct affent)) < numents)) { fprintf(stderr, "Error: too many entries: %d\n", numents); numents = 0; } else { ptr = malloc(numents * sizeof(struct affent)); ptr->achar = achar; ptr->xpflg = ff; fprintf(stderr,"parsing %c entries %d\n", achar,numents); } break; } default: break; } i++; } free(piece); } /* now parse all of the sub entries*/ nptr = ptr; for (j=0; j < numents; j++) { if (!fgets(line,MAX_LN_LEN,afflst)) return 1; mychomp(line); tp = line; i = 0; while ((piece=mystrsep(&tp,' '))) { if (*piece != '\0') { switch(i) { case 0: { if (nptr != ptr) { nptr->achar = ptr->achar; nptr->xpflg = ptr->xpflg; } break; } case 1: break; case 2: { nptr->strip = mystrdup(piece); nptr->stripl = strlen(nptr->strip); if (strcmp(nptr->strip,"0") == 0) { free(nptr->strip); nptr->strip=mystrdup(""); nptr->stripl = 0; } break; } case 3: { nptr->appnd = mystrdup(piece); nptr->appndl = strlen(nptr->appnd); if (strcmp(nptr->appnd,"0") == 0) { free(nptr->appnd); nptr->appnd=mystrdup(""); nptr->appndl = 0; } if (strchr(nptr->appnd, '/')) { char * addseparator = (char *) realloc(nptr->appnd, nptr->appndl + 2); if (addseparator) { nptr->appndl++; addseparator[nptr->appndl-1] = '|'; addseparator[nptr->appndl] = '\0'; nptr->appnd = addseparator; } } break; } case 4: { encodeit(nptr,piece);} fprintf(stderr, " affix: %s %d, strip: %s %d\n",nptr->appnd, nptr->appndl,nptr->strip,nptr->stripl); default: break; } i++; } free(piece); } nptr++; } if (ptr) { if (ft == 'P') { ptable[numpfx].aep = ptr; ptable[numpfx].num = numents; fprintf(stderr,"ptable %d num is %d flag %c\n",numpfx,ptable[numpfx].num,ptr->achar); numpfx++; } else if (ft == 'S') { stable[numsfx].aep = ptr; stable[numsfx].num = numents; fprintf(stderr,"stable %d num is %d flag %c\n",numsfx,stable[numsfx].num,ptr->achar); numsfx++; } ptr = NULL; } nptr = NULL; numents = 0; achar='\0'; } } free(line); return 0; }
int web_client_api_old_data_request(RRDHOST *host, struct web_client *w, char *url, int datasource_type) { if(!url || !*url) { buffer_flush(w->response.data); buffer_sprintf(w->response.data, "Incomplete request."); return 400; } RRDSET *st = NULL; char *args = strchr(url, '?'); if(args) { *args='\0'; args = &args[1]; } // get the name of the data to show char *tok = mystrsep(&url, "/"); if(!tok) tok = ""; // do we have such a data set? if(*tok) { debug(D_WEB_CLIENT, "%llu: Searching for RRD data with name '%s'.", w->id, tok); st = rrdset_find_byname(host, tok); if(!st) st = rrdset_find(host, tok); } if(!st) { // we don't have it // try to send a file with that name buffer_flush(w->response.data); return(mysendfile(w, tok)); } // we have it debug(D_WEB_CLIENT, "%llu: Found RRD data with name '%s'.", w->id, tok); // how many entries does the client want? int lines = (int)st->entries; int group_count = 1; time_t after = 0, before = 0; int group_method = GROUP_AVERAGE; int nonzero = 0; if(url) { // parse the lines required tok = mystrsep(&url, "/"); if(tok) lines = str2i(tok); if(lines < 1) lines = 1; } if(url) { // parse the group count required tok = mystrsep(&url, "/"); if(tok && *tok) group_count = str2i(tok); if(group_count < 1) group_count = 1; //if(group_count > save_history / 20) group_count = save_history / 20; } if(url) { // parse the grouping method required tok = mystrsep(&url, "/"); if(tok && *tok) { if(strcmp(tok, "max") == 0) group_method = GROUP_MAX; else if(strcmp(tok, "average") == 0) group_method = GROUP_AVERAGE; else if(strcmp(tok, "sum") == 0) group_method = GROUP_SUM; else debug(D_WEB_CLIENT, "%llu: Unknown group method '%s'", w->id, tok); } } if(url) { // parse after time tok = mystrsep(&url, "/"); if(tok && *tok) after = str2ul(tok); if(after < 0) after = 0; } if(url) { // parse before time tok = mystrsep(&url, "/"); if(tok && *tok) before = str2ul(tok); if(before < 0) before = 0; } if(url) { // parse nonzero tok = mystrsep(&url, "/"); if(tok && *tok && strcmp(tok, "nonzero") == 0) nonzero = 1; } w->response.data->contenttype = CT_APPLICATION_JSON; buffer_flush(w->response.data); char *google_version = "0.6"; char *google_reqId = "0"; char *google_sig = "0"; char *google_out = "json"; char *google_responseHandler = "google.visualization.Query.setResponse"; char *google_outFileName = NULL; time_t last_timestamp_in_data = 0; if(datasource_type == DATASOURCE_DATATABLE_JSON || datasource_type == DATASOURCE_DATATABLE_JSONP) { w->response.data->contenttype = CT_APPLICATION_X_JAVASCRIPT; while(args) { tok = mystrsep(&args, "&"); if(tok && *tok) { char *name = mystrsep(&tok, "="); if(name && *name && strcmp(name, "tqx") == 0) { char *key = mystrsep(&tok, ":"); char *value = mystrsep(&tok, ";"); if(key && value && *key && *value) { if(strcmp(key, "version") == 0) google_version = value; else if(strcmp(key, "reqId") == 0) google_reqId = value; else if(strcmp(key, "sig") == 0) google_sig = value; else if(strcmp(key, "out") == 0) google_out = value; else if(strcmp(key, "responseHandler") == 0) google_responseHandler = value; else if(strcmp(key, "outFileName") == 0) google_outFileName = value; } } } } debug(D_WEB_CLIENT_ACCESS, "%llu: GOOGLE JSONP: version = '%s', reqId = '%s', sig = '%s', out = '%s', responseHandler = '%s', outFileName = '%s'", w->id, google_version, google_reqId, google_sig, google_out, google_responseHandler, google_outFileName ); if(datasource_type == DATASOURCE_DATATABLE_JSONP) { last_timestamp_in_data = strtoul(google_sig, NULL, 0); // check the client wants json if(strcmp(google_out, "json") != 0) { buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'error',errors:[{reason:'invalid_query',message:'output format is not supported',detailed_message:'the format %s requested is not supported by netdata.'}]});", google_responseHandler, google_version, google_reqId, google_out); return 200; } } } if(datasource_type == DATASOURCE_DATATABLE_JSONP) { buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'ok',sig:'%ld',table:", google_responseHandler, google_version, google_reqId, st->last_updated.tv_sec); } debug(D_WEB_CLIENT_ACCESS, "%llu: Sending RRD data '%s' (id %s, %d lines, %d group, %d group_method, %ld after, %ld before).", w->id, st->name, st->id, lines, group_count, group_method, after, before); time_t timestamp_in_data = rrdset2json_api_old(datasource_type, st, w->response.data, lines, group_count , group_method, (unsigned long) after, (unsigned long) before , nonzero); if(datasource_type == DATASOURCE_DATATABLE_JSONP) { if(timestamp_in_data > last_timestamp_in_data) buffer_strcat(w->response.data, "});"); else { // the client already has the latest data buffer_flush(w->response.data); buffer_sprintf(w->response.data, "%s({version:'%s',reqId:'%s',status:'error',errors:[{reason:'not_modified',message:'Data not modified'}]});", google_responseHandler, google_version, google_reqId); } } return 200; }
void parse_aff_file(FILE * afflst) { int i, j; int numents = 0; char achar = '\0'; short ff=0; char ft; struct affent * ptr= NULL; struct affent * nptr= NULL; char * line = malloc(MAX_LN_LEN); while (fgets(line,MAX_LN_LEN,afflst)) { mychomp(line); ft = ' '; fprintf(stderr,"parsing line: %s\n",line); if (strncmp(line,"PFX",3) == 0) ft = 'P'; if (strncmp(line,"SFX",3) == 0) ft = 'S'; if (ft != ' ') { char * tp = line; char * piece; i = 0; ff = 0; while ((piece=mystrsep(&tp,' '))) { if (*piece != '\0') { switch(i) { case 0: break; case 1: { achar = *piece; break; } case 2: { if (*piece == 'Y') ff = XPRODUCT; break; } case 3: { numents = atoi(piece); ptr = malloc(numents * sizeof(struct affent)); ptr->achar = achar; ptr->xpflg = ff; fprintf(stderr,"parsing %c entries %d\n",achar,numents); break; } default: break; } i++; } free(piece); } /* now parse all of the sub entries*/ nptr = ptr; for (j=0; j < numents; j++) { fgets(line,MAX_LN_LEN,afflst); mychomp(line); tp = line; i = 0; while ((piece=mystrsep(&tp,' '))) { if (*piece != '\0') { switch(i) { case 0: { if (nptr != ptr) { nptr->achar = ptr->achar; nptr->xpflg = ptr->xpflg; } break; } case 1: break; case 2: { nptr->strip = mystrdup(piece); nptr->stripl = strlen(nptr->strip); if (strcmp(nptr->strip,"0") == 0) { free(nptr->strip); nptr->strip=mystrdup(""); nptr->stripl = 0; } break; } case 3: { nptr->appnd = mystrdup(piece); nptr->appndl = strlen(nptr->appnd); if (strcmp(nptr->appnd,"0") == 0) { free(nptr->appnd); nptr->appnd=mystrdup(""); nptr->appndl = 0; } break; } case 4: { encodeit(nptr,piece);} fprintf(stderr, " affix: %s %d, strip: %s %d\n",nptr->appnd, nptr->appndl,nptr->strip,nptr->stripl); default: break; } i++; } free(piece); } nptr++; } if (ft == 'P') { ptable[numpfx].aep = ptr; ptable[numpfx].num = numents; fprintf(stderr,"ptable %d num is %d\n",numpfx,ptable[numpfx].num); numpfx++; } else { stable[numsfx].aep = ptr; stable[numsfx].num = numents; fprintf(stderr,"stable %d num is %d\n",numsfx,stable[numsfx].num); numsfx++; } ptr = NULL; nptr = NULL; numents = 0; achar='\0'; } } free(line); }
int web_client_api_request_v1_badge(RRDHOST *host, struct web_client *w, char *url) { int ret = 400; buffer_flush(w->response.data); BUFFER *dimensions = NULL; const char *chart = NULL , *before_str = NULL , *after_str = NULL , *points_str = NULL , *multiply_str = NULL , *divide_str = NULL , *label = NULL , *units = NULL , *label_color = NULL , *value_color = NULL , *refresh_str = NULL , *precision_str = NULL , *scale_str = NULL , *alarm = NULL; int group = GROUP_AVERAGE; uint32_t options = 0x00000000; while(url) { char *value = mystrsep(&url, "/?&"); if(!value || !*value) continue; char *name = mystrsep(&value, "="); if(!name || !*name) continue; if(!value || !*value) continue; debug(D_WEB_CLIENT, "%llu: API v1 badge.svg query param '%s' with value '%s'", w->id, name, value); // name and value are now the parameters // they are not null and not empty if(!strcmp(name, "chart")) chart = value; else if(!strcmp(name, "dimension") || !strcmp(name, "dim") || !strcmp(name, "dimensions") || !strcmp(name, "dims")) { if(!dimensions) dimensions = buffer_create(100); buffer_strcat(dimensions, "|"); buffer_strcat(dimensions, value); } else if(!strcmp(name, "after")) after_str = value; else if(!strcmp(name, "before")) before_str = value; else if(!strcmp(name, "points")) points_str = value; else if(!strcmp(name, "group")) { group = web_client_api_request_v1_data_group(value, GROUP_AVERAGE); } else if(!strcmp(name, "options")) { options |= web_client_api_request_v1_data_options(value); } else if(!strcmp(name, "label")) label = value; else if(!strcmp(name, "units")) units = value; else if(!strcmp(name, "label_color")) label_color = value; else if(!strcmp(name, "value_color")) value_color = value; else if(!strcmp(name, "multiply")) multiply_str = value; else if(!strcmp(name, "divide")) divide_str = value; else if(!strcmp(name, "refresh")) refresh_str = value; else if(!strcmp(name, "precision")) precision_str = value; else if(!strcmp(name, "scale")) scale_str = value; else if(!strcmp(name, "alarm")) alarm = value; } if(!chart || !*chart) { buffer_no_cacheable(w->response.data); buffer_sprintf(w->response.data, "No chart id is given at the request."); goto cleanup; } int scale = (scale_str && *scale_str)?str2i(scale_str):100; RRDSET *st = rrdset_find(host, chart); if(!st) st = rrdset_find_byname(host, chart); if(!st) { buffer_no_cacheable(w->response.data); buffer_svg(w->response.data, "chart not found", NAN, "", NULL, NULL, -1, scale, 0); ret = 200; goto cleanup; } st->last_accessed_time = now_realtime_sec(); RRDCALC *rc = NULL; if(alarm) { rc = rrdcalc_find(st, alarm); if (!rc) { buffer_no_cacheable(w->response.data); buffer_svg(w->response.data, "alarm not found", NAN, "", NULL, NULL, -1, scale, 0); ret = 200; goto cleanup; } } long long multiply = (multiply_str && *multiply_str )?str2l(multiply_str):1; long long divide = (divide_str && *divide_str )?str2l(divide_str):1; long long before = (before_str && *before_str )?str2l(before_str):0; long long after = (after_str && *after_str )?str2l(after_str):-st->update_every; int points = (points_str && *points_str )?str2i(points_str):1; int precision = (precision_str && *precision_str)?str2i(precision_str):-1; if(!multiply) multiply = 1; if(!divide) divide = 1; int refresh = 0; if(refresh_str && *refresh_str) { if(!strcmp(refresh_str, "auto")) { if(rc) refresh = rc->update_every; else if(options & RRDR_OPTION_NOT_ALIGNED) refresh = st->update_every; else { refresh = (int)(before - after); if(refresh < 0) refresh = -refresh; } } else { refresh = str2i(refresh_str); if(refresh < 0) refresh = -refresh; } } if(!label) { if(alarm) { char *s = (char *)alarm; while(*s) { if(*s == '_') *s = ' '; s++; } label = alarm; } else if(dimensions) { const char *dim = buffer_tostring(dimensions); if(*dim == '|') dim++; label = dim; } else label = st->name; } if(!units) { if(alarm) { if(rc->units) units = rc->units; else units = ""; } else if(options & RRDR_OPTION_PERCENTAGE) units = "%"; else units = st->units; } debug(D_WEB_CLIENT, "%llu: API command 'badge.svg' for chart '%s', alarm '%s', dimensions '%s', after '%lld', before '%lld', points '%d', group '%d', options '0x%08x'" , w->id , chart , alarm?alarm:"" , (dimensions)?buffer_tostring(dimensions):"" , after , before , points , group , options ); if(rc) { if (refresh > 0) { buffer_sprintf(w->response.header, "Refresh: %d\r\n", refresh); w->response.data->expires = now_realtime_sec() + refresh; } else buffer_no_cacheable(w->response.data); if(!value_color) { switch(rc->status) { case RRDCALC_STATUS_CRITICAL: value_color = "red"; break; case RRDCALC_STATUS_WARNING: value_color = "orange"; break; case RRDCALC_STATUS_CLEAR: value_color = "brightgreen"; break; case RRDCALC_STATUS_UNDEFINED: value_color = "lightgrey"; break; case RRDCALC_STATUS_UNINITIALIZED: value_color = "#000"; break; default: value_color = "grey"; break; } } buffer_svg(w->response.data, label, (isnan(rc->value)||isinf(rc->value)) ? rc->value : rc->value * multiply / divide, units, label_color, value_color, precision, scale, options ); ret = 200; } else { time_t latest_timestamp = 0; int value_is_null = 1; calculated_number n = NAN; ret = 500; // if the collected value is too old, don't calculate its value if (rrdset_last_entry_t(st) >= (now_realtime_sec() - (st->update_every * st->gap_when_lost_iterations_above))) ret = rrdset2value_api_v1(st, w->response.data, &n, (dimensions) ? buffer_tostring(dimensions) : NULL , points, after, before, group, 0, options, NULL, &latest_timestamp, &value_is_null); // if the value cannot be calculated, show empty badge if (ret != 200) { buffer_no_cacheable(w->response.data); value_is_null = 1; n = 0; ret = 200; } else if (refresh > 0) { buffer_sprintf(w->response.header, "Refresh: %d\r\n", refresh); w->response.data->expires = now_realtime_sec() + refresh; } else buffer_no_cacheable(w->response.data); // render the badge buffer_svg(w->response.data, label, (value_is_null)?NAN:(n * multiply / divide), units, label_color, value_color, precision, scale, options ); } cleanup: buffer_free(dimensions); return ret; }
inline int web_client_api_request_v1_allmetrics(RRDHOST *host, struct web_client *w, char *url) { int format = ALLMETRICS_SHELL; int help = 0, types = 0, timestamps = 1, names = backend_send_names; // prometheus options const char *prometheus_server = w->client_ip; uint32_t prometheus_options = backend_options; const char *prometheus_prefix = backend_prefix; while(url) { char *value = mystrsep(&url, "?&"); if (!value || !*value) continue; char *name = mystrsep(&value, "="); if(!name || !*name) continue; if(!value || !*value) continue; if(!strcmp(name, "format")) { if(!strcmp(value, ALLMETRICS_FORMAT_SHELL)) format = ALLMETRICS_SHELL; else if(!strcmp(value, ALLMETRICS_FORMAT_PROMETHEUS)) format = ALLMETRICS_PROMETHEUS; else if(!strcmp(value, ALLMETRICS_FORMAT_PROMETHEUS_ALL_HOSTS)) format = ALLMETRICS_PROMETHEUS_ALL_HOSTS; else if(!strcmp(value, ALLMETRICS_FORMAT_JSON)) format = ALLMETRICS_JSON; else format = 0; } else if(!strcmp(name, "help")) { if(!strcmp(value, "yes")) help = 1; else help = 0; } else if(!strcmp(name, "types")) { if(!strcmp(value, "yes")) types = 1; else types = 0; } else if(!strcmp(name, "names")) { if(!strcmp(value, "yes")) names = 1; else names = 0; } else if(!strcmp(name, "timestamps")) { if(!strcmp(value, "yes")) timestamps = 1; else timestamps = 0; } else if(!strcmp(name, "server")) { prometheus_server = value; } else if(!strcmp(name, "prefix")) { prometheus_prefix = value; } else if(!strcmp(name, "data") || !strcmp(name, "source") || !strcmp(name, "data source") || !strcmp(name, "data-source") || !strcmp(name, "data_source") || !strcmp(name, "datasource")) { prometheus_options = backend_parse_data_source(value, prometheus_options); } } buffer_flush(w->response.data); buffer_no_cacheable(w->response.data); switch(format) { case ALLMETRICS_JSON: w->response.data->contenttype = CT_APPLICATION_JSON; rrd_stats_api_v1_charts_allmetrics_json(host, w->response.data); return 200; case ALLMETRICS_SHELL: w->response.data->contenttype = CT_TEXT_PLAIN; rrd_stats_api_v1_charts_allmetrics_shell(host, w->response.data); return 200; case ALLMETRICS_PROMETHEUS: w->response.data->contenttype = CT_PROMETHEUS; rrd_stats_api_v1_charts_allmetrics_prometheus_single_host(host, w->response.data, prometheus_server, prometheus_prefix, prometheus_options, help, types, names, timestamps); return 200; case ALLMETRICS_PROMETHEUS_ALL_HOSTS: w->response.data->contenttype = CT_PROMETHEUS; rrd_stats_api_v1_charts_allmetrics_prometheus_all_hosts(host, w->response.data, prometheus_server, prometheus_prefix, prometheus_options, help, types, names, timestamps); return 200; default: w->response.data->contenttype = CT_TEXT_PLAIN; buffer_strcat(w->response.data, "Which format? '" ALLMETRICS_FORMAT_SHELL "', '" ALLMETRICS_FORMAT_PROMETHEUS "', '" ALLMETRICS_FORMAT_PROMETHEUS_ALL_HOSTS "' and '" ALLMETRICS_FORMAT_JSON "' are currently supported."); return 400; } }
void LogInfo::parse(QString s) { errorfield = 0; char *c = (char *)malloc(s.length() + 1), *csep; strcpy(c, s.data()); // init data _from = _until = 0; _conname = ""; _currency = ""; _bytes_in = _bytes_out = -1; _session_cost = _total_cost = -1; // start of connection time csep = c; char *p = mystrsep(&csep, ":"); int i = 0; while(i < 8 && p != 0) { QString token = p; switch(i) { case 0: _from = token.toULong(); break; case 1: _conname = token.copy(); break; case 2: _currency = token.copy(); break; case 3: _until = token.toULong(); break; case 4: _session_cost = token.toFloat(); break; case 5: _total_cost = token.toFloat(); break; case 6: _bytes_in = token.toLong(); break; case 7: _bytes_out = token.toLong(); break; } i++; p = mystrsep(&csep, ":"); } free(c); if(i == 8) errorfield = 0; else errorfield = i+1; }
// uninstalls our conduit int UninstallConduit() { int dwReturnCode; BOOL bHotSyncRunning = FALSE; // Get the Palm Desktop Installation directory TCHAR szPalmDesktopDir[_MAX_PATH]; unsigned long desktopSize=_MAX_PATH; // Load the Conduit Manager DLL. HINSTANCE hConduitManagerDLL; if( (dwReturnCode=GetPalmDesktopInstallDirectory(szPalmDesktopDir, &desktopSize)) == 0 ) { if( (dwReturnCode = LoadConduitManagerDll(&hConduitManagerDLL, szPalmDesktopDir)) != 0 ) return(dwReturnCode); } // if registery key not load it from local dir if present by any chance else return(dwReturnCode); // need to switch current working directory to directory with palm dlls // because of a bug in Palm Desktop 6.01 GetCurrentDirectory(sizeof(gSavedCwd), gSavedCwd); SetCurrentDirectory(szPalmDesktopDir); // Prepare to uninstall the conduit using Conduit Manager functions CmRemoveConduitByCreatorIDPtr lpfnCmRemoveConduitByCreatorID; lpfnCmRemoveConduitByCreatorID = (CmRemoveConduitByCreatorIDPtr) GetProcAddress(hConduitManagerDLL, "CmRemoveConduitByCreatorID"); if( (lpfnCmRemoveConduitByCreatorID == NULL) ) return(IDS_ERR_LOADING_CONDMGR); CmSetCorePathPtr lpfnCmSetCorePath = (CmSetCorePathPtr) GetProcAddress(hConduitManagerDLL, "CmSetCorePath"); CmSetHotSyncExePathPtr lpfnCmSetHotSyncExePath = (CmSetHotSyncExePathPtr) GetProcAddress(hConduitManagerDLL, "CmSetHotSyncExecPath"); CmRestoreHotSyncSettingsPtr lpfnCmRestoreHotSyncSettings; lpfnCmRestoreHotSyncSettings = (CmRestoreHotSyncSettingsPtr) GetProcAddress(hConduitManagerDLL, "CmRestoreHotSyncSettings"); CmGetCreatorValueStringPtr lpfnCmGetCreatorValueString = (CmGetCreatorValueStringPtr) GetProcAddress(hConduitManagerDLL, "CmGetCreatorValueString"); CmInstallCreatorPtr lpfnCmInstallCreator; lpfnCmInstallCreator = (CmInstallCreatorPtr) GetProcAddress(hConduitManagerDLL, "CmInstallCreator"); CmSetCreatorRemotePtr lpfnCmSetCreatorRemote; lpfnCmSetCreatorRemote = (CmSetCreatorRemotePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorRemote"); CmSetCreatorNamePtr lpfnCmSetCreatorName; lpfnCmSetCreatorName = (CmSetCreatorNamePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorName"); CmSetCreatorTitlePtr lpfnCmSetCreatorTitle; lpfnCmSetCreatorTitle = (CmSetCreatorTitlePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorTitle"); CmSetCreatorPriorityPtr lpfnCmSetCreatorPriority; lpfnCmSetCreatorPriority = (CmSetCreatorPriorityPtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorPriority"); CmSetCreatorIntegratePtr lpfnCmSetCreatorIntegrate; lpfnCmSetCreatorIntegrate = (CmSetCreatorIntegratePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorIntegrate"); CmSetCreatorFilePtr lpfnCmSetCreatorFile = (CmSetCreatorFilePtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorFile"); CmSetCreatorDirectoryPtr lpfnCmSetCreatorDirectory = (CmSetCreatorDirectoryPtr) GetProcAddress(hConduitManagerDLL, "CmSetCreatorDirectory"); if( (lpfnCmRestoreHotSyncSettings == NULL) ) return(IDS_ERR_LOADING_CONDMGR); // Load the HSAPI DLL. HINSTANCE hHsapiDLL; if( (dwReturnCode = LoadHsapiDll(&hHsapiDLL, szPalmDesktopDir)) != 0 ) return(dwReturnCode); // Shutdown the HotSync Process if it is running if( (bHotSyncRunning=IsHotSyncRunning(hHsapiDLL)) ) { // Check for any synchronizations in progress if( IsHotSyncInProgress(hHsapiDLL) ) return IDS_ERR_HOTSYNC_IN_PROGRESS; ShutdownHotSync(hHsapiDLL); } TCHAR oldConduitSettings[500]; int strSize = sizeof(oldConduitSettings); dwReturnCode = (*lpfnCmGetCreatorValueString)(CREATOR, "oldConduitSettings", oldConduitSettings, &strSize, ""); // Actually uninstall the conduit dwReturnCode = (*lpfnCmRemoveConduitByCreatorID)(CREATOR); if(dwReturnCode >= 0) { // uninstall Mozilla Palm Sync Support Proxy Dll dwReturnCode = UnregisterMozPalmSyncDll(); // dwReturnCode = (*lpfnCmRestoreHotSyncSettings)(TRUE); } if (dwReturnCode >= 0) { char * szOldCreatorName; char *szOldRemote; char *szOldCreatorTitle; char *szOldCreatorFile; char *szOldCreatorDirectory; char *oldIntStr; DWORD oldPriority; DWORD oldIntegrate; int oldType; char *strPtr = oldConduitSettings; szOldRemote = mystrsep(&strPtr, ','); szOldCreatorName = mystrsep(&strPtr, ','); szOldCreatorTitle = mystrsep(&strPtr, ','); szOldCreatorFile = mystrsep(&strPtr, ','); szOldCreatorDirectory = mystrsep(&strPtr, ','); oldIntStr = mystrsep(&strPtr, ','); oldType = (oldIntStr) ? atoi(oldIntStr) : 0; oldIntStr = mystrsep(&strPtr, ','); oldPriority = (oldIntStr) ? atoi(oldIntStr) : 0; oldIntStr = mystrsep(&strPtr, ','); oldIntegrate = (oldIntStr) ? atoi(oldIntStr) : 0; dwReturnCode = (*lpfnCmInstallCreator)(CREATOR, oldType); if( dwReturnCode == 0 ) { dwReturnCode = (*lpfnCmSetCreatorName)(CREATOR, szOldCreatorName); if( dwReturnCode != 0 ) return dwReturnCode; // Construct conduit title (the one displayed in HotSync Mgr's Custom...list).. dwReturnCode = (*lpfnCmSetCreatorTitle)(CREATOR, szOldCreatorTitle); if( dwReturnCode != 0 ) return dwReturnCode; dwReturnCode = (*lpfnCmSetCreatorRemote)(CREATOR, szOldRemote); if( dwReturnCode != 0 ) return dwReturnCode; dwReturnCode = (*lpfnCmSetCreatorFile)(CREATOR, szOldCreatorFile); if( dwReturnCode != 0 ) return dwReturnCode; dwReturnCode = (*lpfnCmSetCreatorDirectory)(CREATOR, szOldCreatorDirectory); if( dwReturnCode != 0 ) return dwReturnCode; dwReturnCode = (*lpfnCmSetCreatorPriority)(CREATOR, oldPriority); if( dwReturnCode != 0 ) return dwReturnCode; // Applications should always set Integrate to 0 dwReturnCode = (*lpfnCmSetCreatorIntegrate)(CREATOR, oldIntegrate); } } // if (lpfnCmSetCorePath) // (*lpfnCmSetCorePath)(szPalmDesktopDir); // if (lpfnCmSetHotSyncExePath) // (*lpfnCmSetHotSyncExePath)(szPalmHotSyncInstallDir); // this registry key is set by the RestoreHotSyncSettings to point incorrectly to Mozilla dir // this should point to the Palm directory to enable sync with Palm Desktop. #if 0 HKEY key; LONG rc = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\U.S. Robotics\\Pilot Desktop\\Core", 0, KEY_ALL_ACCESS, &key); if(rc == ERROR_SUCCESS) ::RegSetValueEx(key, "Path", 0, REG_SZ, (const BYTE *) szPalmDesktopDir, desktopSize); if(rc == ERROR_SUCCESS) ::RegSetValueEx(key, "HotSyncPath", 0, REG_SZ, (const BYTE *) szPalmHotSyncInstallDir, installSize); #endif // Re-start HotSync if it was running before if( bHotSyncRunning ) StartHotSync(hHsapiDLL); // restore cwd, if we changed it. if (gSavedCwd[0]) SetCurrentDirectory(gSavedCwd); if( dwReturnCode < 0 ) return dwReturnCode; else return(0); }
// set data values in the balise message buffer es_Status es_tcl_track_balise_set(char* subcmd, char* arg, void (*appendResult)(char*, es_ClientData), es_ClientData data) { CompressedBaliseMessage_TM *bm = &es_tcl_track_balise_buf; // header if( subcmd != NULL && !strcmp("header",subcmd) ) { if (arg == NULL) { snprintf(es_msg_buf, ES_MSG_BUF_SIZE, "invalid sub command 'set header': missing argument"); return ES_TCL_ERROR; } char *varname, *next; arg = strdup(arg); next = arg; appendResult(es_msg_buf, data); while ((varname = mystrsep(&next, " ")) != NULL) { char *v = mystrsep(&next, " "); if (v == NULL) { snprintf(es_msg_buf, ES_MSG_BUF_SIZE, "missing value for variable %s", varname); return ES_TCL_ERROR; } int value = atoi(v); if (!strcmp("nid_bg", varname)) { bm->Header.nid_bg = value; } else if (!strcmp("n_pig", varname)) { bm->Header.n_pig = value; } else if (!strcmp("n_total", varname)) { bm->Header.n_total = value; } else if (!strcmp("m_dup", varname)) { bm->Header.m_dup = value; } else if (!strcmp("m_mcount", varname)) { bm->Header.m_mcount = value; } else if (!strcmp("m_version", varname)) { bm->Header.m_version = value; } else if (!strcmp("nid_c", varname)) { bm->Header.nid_c = value; } else if (!strcmp("q_link", varname)) { bm->Header.q_link = value; } else if (!strcmp("q_media", varname)) { bm->Header.q_media = value; } else if (!strcmp("q_updown", varname)) { bm->Header.q_updown = value; } else { snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid balise header variable: %s",varname); free(arg); return ES_TCL_ERROR; } } free(arg); return ES_OK; } snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid sub command '%s': expected 'header'",subcmd); return ES_TCL_ERROR; }