static obj_t string_ci_ge_fn(obj_t args, Reporter rep) { obj_t s1, s2; int rv; if (!args_match(rep, args, 2, is_string, is_string)) return unspecific; s1 = list_ref(args, 0); s2 = list_ref(args, 1); rv = string_ci_cmp(fetch_string(s1), fetch_string(s2)); return make_bool(rv >= 0); }
static int dump_pidl(void) { const lnk_string *pidl; int i, n = 0, sz = 0; pidl = fetch_string(FALSE); if (!pidl) return -1; printf("PIDL\n"); printf("----\n\n"); while(sz<pidl->size) { const lnk_string *segment = (const lnk_string*) &pidl->str.a[sz]; if(!segment->size) break; sz+=segment->size; if(sz>pidl->size) { printf("bad pidl\n"); break; } n++; printf("segment %d (%2d bytes) : ",n,segment->size); for(i=0; i<segment->size; i++) printf("%02x ",segment->str.a[i]); printf("\n"); } printf("\n"); return 0; }
static obj_t string_length_fn(obj_t args, Reporter rep) { obj_t obj; if (!args_match(rep, args, 1, is_string)) return unspecific; obj = list_ref(args, 0); return make_num(fetch_string(obj)->len); }
static obj_t string2list_fn(obj_t args, Reporter rep) { obj_t string, list = null_obj; char *cs; size_t n, i; if (!args_match(rep, args, 1, is_string)) return unspecific; string = list_ref(args, 0); cs = fetch_string(string)->data; n = fetch_string(string)->len; for (i = 0; i < n; i++) list = cons(make_char(cs[n-i-1]), list); return list; }
static obj_t string_copy_fn(obj_t args, Reporter rep) { string str; if (!args_match(rep, args, 1, is_string)) return unspecific; str = fetch_string(list_ref(args, 0)); return make_string(string_clone(str)); }
static obj_t string_ref_fn(obj_t args, Reporter rep) { obj_t obj, idx; long k; if (!args_match(rep, args, 2, is_string, is_num)) return unspecific; obj = list_ref(args, 0); idx = list_ref(args, 1); k = fetch_num(idx); if (k < 0 || (size_t)k >= fetch_string(obj)->len) { reportf(rep, "string-ref: index %ld is out of range", k); return unspecific; } return make_char(fetch_string(obj)->data[k]); }
static obj_t string_set_fn(obj_t args, Reporter rep) { obj_t obj, idx, chr; long k; if (!args_match(rep, args, 3, is_string, is_num, is_char)) return unspecific; obj = list_ref(args, 0); idx = list_ref(args, 1); chr = list_ref(args, 2); k = fetch_num(idx); if (k < 0 || (size_t)k >= fetch_string(obj)->len) { reportf(rep, "string-set!: index %ld is out of range", k); return unspecific; } fetch_string(obj)->data[k] = fetch_char(chr); return unspecific; }
static obj_t string_fill_fn(obj_t args, Reporter rep) { string str; char ch; if (!args_match(rep, args, 2, is_string, is_char)) return unspecific; str = fetch_string(list_ref(args, 0)); ch = fetch_char(list_ref(args, 1)); memset(str->data, ch, str->len); return unspecific; }
static obj_t string_append_fn(obj_t args, Reporter rep) { size_t len = 0, i = 0; obj_t arg; string result; if (!args_plus_match(rep, args, 0, is_string)) return unspecific; for (arg = args; ! is_null(arg); arg = cdr(arg)) len += fetch_string(car(arg))->len; result = string_alloc(len); for (arg = args; ! is_null(arg); arg = cdr(arg)) { string str = fetch_string(car(arg)); memcpy(result->data + i, str->data, str->len); i += str->len; } return make_string(result); }
static obj_t substring_fn(obj_t args, Reporter rep) { string str; long start, end; if (!args_match(rep, args, 3, is_string, is_num, is_num)) return unspecific; str = fetch_string(list_ref(args, 0)); start = fetch_num(list_ref(args, 1)); end = fetch_num(list_ref(args, 2)); if (!(0 <= start && start <= end && end <= (long)str->len)) { reportf(rep, "substring: invalid range [%d, %d)", start, end); return unspecific; } return make_string(string_from(str->data + start, end - start)); }
static int dump_string(const char *what, int unicode) { const lnk_string *data; unsigned sz; data = fetch_string(unicode); if (!data) return -1; printf("%s : ", what); sz = data->size; if (unicode) while (sz) printf("%c", data->str.w[data->size - sz--]); else while (sz) printf("%c", data->str.a[data->size - sz--]); printf("\n"); return 0; }
int instClTimeHandler(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests){ DEBUGMSGTL(("gpDroneMIB", "Got request, mode is %d:\n", reqinfo->mode)); switch(reqinfo->mode){ case MODE_GET: DEBUGMSGTL(("gpDroneMIB", "Old val is: %s\n", instClTime)); fetch_string("instClTime",instClTime); DEBUGMSGTL(("gpDroneMIB", "New val is: %s\n", instClTime)); snmp_set_var_typed_value(requests->requestvb,ASN_OCTET_STR,instClTime,strlen(instClTime)); break; default: printf("ERROR - Something wrong happened!"); } }
static void print_atom(FILE *out, obj_t obj) { if (eq(obj, unspecific)) { fputs("#<unspecified>", out); } else if (is_null(obj)) { fputs("()", out); } else if (is_bool(obj)) { if (fetch_bool(obj)) fputs("#t", out); else fputs("#f", out); } else if (is_symbol(obj)) { print_string(out, fetch_symbol(obj)); } else if (is_num(obj)) { fprintf(out, "%ld", (long)fetch_num(obj)); } else if (is_char(obj)) { char ch = fetch_char(obj); switch (ch) { case ' ': fputs("#\\space", out); break; case '\n': fputs("#\\newline", out); break; default: fprintf(out, "#\\%c", ch); break; } } else if (is_string(obj)) { putc('"', out); print_string(out, fetch_string(obj)); putc('"', out); } else if (is_pair(obj)) { if (!print_quotation(out, obj)) print_list(out, obj); } else { fputs("#<unknown>", out); /* TODO: function, lambda */ } }
static int fetch(const opal_identifier_t *uid, const char *key, void **data, opal_data_type_t type) { opal_byte_object_t *boptr; uint16_t ui16; uint32_t ui32; int ival; unsigned int uival; char *pmikey; char tmp_val[1024]; size_t sval; opal_identifier_t proc; /* to protect alignment, copy the data across */ memcpy(&proc, uid, sizeof(opal_identifier_t)); OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output, "db:pmi:fetch: searching for key %s[%s] on proc %" PRIu64 "", (NULL == key) ? "NULL" : key, opal_dss.lookup_data_type(type), proc)); /* if the key is NULL, that is an error */ if (NULL == key) { OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM); return OPAL_ERR_BAD_PARAM; } /* setup the key */ if (NULL == (pmikey = setup_key(proc, key))) { OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM); return OPAL_ERR_BAD_PARAM; } /* check to see if they are looking for a string */ if (OPAL_STRING == type) { /* might have been passed in multiple sections */ *data = fetch_string(pmikey); free(pmikey); return OPAL_SUCCESS; } /* otherwise, retrieve the pmi keyval */ if (NULL == (pmikey = setup_key(proc, key))) { OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM); return OPAL_ERR_BAD_PARAM; } if (PMI_SUCCESS != kvs_get(pmikey, tmp_val, pmi_vallen_max)) { OPAL_ERROR_LOG(OPAL_ERR_NOT_FOUND); free(pmikey); return OPAL_ERR_NOT_FOUND; } free(pmikey); /* return the value according to the provided type */ switch (type) { case OPAL_UINT32: ui32 = (uint32_t)strtoul(tmp_val, NULL, 10); memcpy(*data, &ui32, sizeof(uint32_t)); break; case OPAL_UINT16: ui16 = (uint16_t)strtoul(tmp_val, NULL, 10); memcpy(*data, &ui16, sizeof(uint16_t)); break; case OPAL_INT: ival = (int)strtol(tmp_val, NULL, 10); memcpy(*data, &ival, sizeof(int)); break; case OPAL_UINT: uival = (unsigned int)strtoul(tmp_val, NULL, 10); memcpy(*data, &uival, sizeof(unsigned int)); break; case OPAL_BYTE_OBJECT: sval = 0; boptr = (opal_byte_object_t*)malloc(sizeof(opal_byte_object_t)); boptr->bytes = (uint8_t*)pmi_decode(tmp_val, &sval); boptr->size = sval; *data = boptr; break; default: OPAL_ERROR_LOG(OPAL_ERR_NOT_SUPPORTED); return OPAL_ERR_NOT_SUPPORTED; } return OPAL_SUCCESS; }
static BOOL fetch_module( DWORD process, DWORD flags, LDR_MODULE** ldr_mod, ULONG* num ) { HANDLE hProcess; PROCESS_BASIC_INFORMATION pbi; PPEB_LDR_DATA pLdrData; NTSTATUS status; PLIST_ENTRY head, curr; BOOL ret = FALSE; *num = 0; if (!(flags & TH32CS_SNAPMODULE)) return TRUE; if (process) { hProcess = OpenProcess( PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, process ); if (!hProcess) return FALSE; } else hProcess = GetCurrentProcess(); status = NtQueryInformationProcess( hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), NULL ); if (!status) { if (ReadProcessMemory( hProcess, &pbi.PebBaseAddress->LdrData, &pLdrData, sizeof(pLdrData), NULL ) && ReadProcessMemory( hProcess, &pLdrData->InLoadOrderModuleList.Flink, &curr, sizeof(curr), NULL )) { head = &pLdrData->InLoadOrderModuleList; while (curr != head) { if (!*num) *ldr_mod = HeapAlloc( GetProcessHeap(), 0, sizeof(LDR_MODULE) ); else *ldr_mod = HeapReAlloc( GetProcessHeap(), 0, *ldr_mod, (*num + 1) * sizeof(LDR_MODULE) ); if (!*ldr_mod) break; if (!ReadProcessMemory( hProcess, CONTAINING_RECORD(curr, LDR_MODULE, InLoadOrderModuleList), &(*ldr_mod)[*num], sizeof(LDR_MODULE), NULL)) break; curr = (*ldr_mod)[*num].InLoadOrderModuleList.Flink; /* if we cannot fetch the strings, then just ignore this LDR_MODULE * and continue loading the other ones in the list */ if (!fetch_string( hProcess, &(*ldr_mod)[*num].BaseDllName )) continue; if (fetch_string( hProcess, &(*ldr_mod)[*num].FullDllName )) (*num)++; else HeapFree( GetProcessHeap(), 0, (*ldr_mod)[*num].BaseDllName.Buffer ); } ret = TRUE; } } else SetLastError( RtlNtStatusToDosError( status ) ); if (process) CloseHandle( hProcess ); return ret; }
int format_first(ErlNifEnv* env, ErlNifBinary* result, char** fmt_start_ptr, ERL_NIF_TERM* items) { char* fmt_start = *fmt_start_ptr; char* fmt_iter = fmt_start; int consumed = 0; int fmt_long = 0; int arg_type = ARG_NONE; // started at the end of line if (*fmt_iter == 0) return 0; // find first covnertion spec character or string end while (*fmt_iter != 0) { if (*fmt_iter == '%') { // Ignore "%%" as it does not take any arguments if (*(fmt_iter+1) == '%') fmt_iter += 2; else { arg_type = -1; break; }; } else fmt_iter += 1; } // find convertion specifier while (*fmt_iter != 0){ if (index("dic", *fmt_iter) != NULL) { arg_type = fmt_long?ARG_LONG:ARG_INT; consumed++; fmt_iter++; break; }; if (index("ouxX", *fmt_iter) != NULL) { arg_type = fmt_long?ARG_ULONG:ARG_UINT; consumed++; fmt_iter++; break; }; if (index("eEfFgGaA", *fmt_iter) != NULL) { arg_type = ARG_DOUBLE; consumed++; fmt_iter++; break; }; if (*fmt_iter == 's') { arg_type = ARG_STRING; consumed++; fmt_iter++; break; }; // Extra argument is consumed from input if (*fmt_iter == '*') consumed++; // We don't support references to argument positions -> return error if (*fmt_iter == '$') return -1; // Support long if (*fmt_iter == 'l') fmt_long = 1; // At last, go to next character fmt_iter++; }; // convertion spec opened but not closed if (arg_type < 0) return -1; // Too much stars in spec if (consumed > 3) return -1; // To not copy part of format, just set zero where scan has ended, then return original value back char kept_fmt_byte = *fmt_iter; *fmt_iter = 0; // We don't really know how much memory will be used, so we call asprintf to let it allocate as much as it needs // Do not forget to call free() in the end! char* formatted = NULL; char* stringbuf; int e1, e2; switch (arg_type) { case ARG_NONE: asprintf(&formatted, fmt_start); break; // Numeric types: see macros above case ARG_INT: fetch_asprintf(fetch_int); case ARG_LONG: fetch_asprintf(fetch_long); case ARG_UINT: fetch_asprintf(fetch_uint); case ARG_ULONG: fetch_asprintf(fetch_ulong); case ARG_DOUBLE: fetch_asprintf(fetch_double); case ARG_STRING: // This cannot be handled by that simple macros because of allocation inside fetch_string switch (consumed) { case 1: asprintf(&formatted, fmt_start, stringbuf = fetch_string(env, items)); free(stringbuf); break; case 2: e1 = fetch_int(env, items); asprintf(&formatted, fmt_start, e1, stringbuf = fetch_string(env, items)); free(stringbuf); break; case 3: e1 = fetch_int(env, items); e2 = fetch_int(env, items); asprintf(&formatted, fmt_start, e1, e2, stringbuf = fetch_string(env, items)); free(stringbuf); break; }; break; }; // Put back saved byte and move format pointer *fmt_iter = kept_fmt_byte; *fmt_start_ptr = fmt_iter; // asprintf did not run or returned error if (formatted == NULL || formatted < 0) return -2; // remember where we start copying formatted part int oldsize = result->size; // Here we are sure formatted contains zero-terminated string, so strlen is safe int part_length = strlen(formatted); enif_realloc_binary(result, oldsize + part_length); // Do copy from formatted to result buffer char* copy_dest = (char*)result->data + oldsize; memcpy(copy_dest, formatted, part_length); // free memory allocated by asprintf free(formatted); // Return number of elements read from items return consumed; };
/* * Our initialization routine, called automatically by the agent * (Note that the function name must match init_FILENAME()) */ void init_gpDroneMIB(void) { netsnmp_handler_registration *reg; //Series of OIDs and variable watchers. Not all of them are fully implemented thought :( const oid sysAircraftID_oid[] = {1,3,6,1,4,1,12620,1,1 }; static netsnmp_watcher_info sysAircraftID_winfo; const oid sysAircraftType_oid[] = {1,3,6,1,4,1,12620,1,2 }; static netsnmp_watcher_info sysAircraftType_winfo; const oid sysTimeUp_oid[] = { 1,3,6,1,4,1,12620,1,4 }; static netsnmp_watcher_info sysTimeUp_winfo; //static netsnmp_watcher_info instPosMagneticCompass_winfo; const oid instPosGpsLatitude_oid[] = { 1,3,6,1,4,1,12620,2,1,5 }; static netsnmp_watcher_info instPosGpsLatitude_winfo; const oid instPosGpsLongitude_oid[] = { 1,3,6,1,4,1,12620,2,1,6 }; static netsnmp_watcher_info instPosGpsLongitude_winfo; const oid instPosAltitude_oid[] = { 1,3,6,1,4,1,12620,2,1,7 }; static netsnmp_watcher_info instPosAltitude_winfo; const oid instClTime_oid[] = { 1,3,6,1,4,1,12620,2,2,1 }; static netsnmp_watcher_info instClTime_winfo; const oid instSpeedGround_oid[] = { 1,3,6,1,4,1,12620,2,3,3 }; static netsnmp_watcher_info instSpeedGround_winfo; const oid instSpeedVertical_oid[] = { 1,3,6,1,4,1,12620,2,3,4 }; static netsnmp_watcher_info instSpeedVertical_winfo; const oid lgSetPosition_oid[] = { 1,3,6,1,4,1,12620,7,3 }; static netsnmp_watcher_info lgSetPosition_winfo; const oid lightNum_oid[] = { 1,3,6,1,4,1,12620,5,1 }; static netsnmp_watcher_info lightNum_winfo; //New variable (not in the original MIB definition)... const oid instTotalFuel_oid[] = { 1,3,6,1,4,1,12620,2,5 }; static netsnmp_watcher_info instTotalFuel_winfo; DEBUGMSGTL(("gpDroneMIB", "Initializing the gpDroneMIB module\n")); /* Now we register the variables of the MIB... */ /*sysAircraftID*/ DEBUGMSGTL(("gpDroneMIB", "Initializing sysAircraftID scalar octet string. Default value = %s\n", sysAircraftID)); reg = netsnmp_create_handler_registration( "sysAircraftID", NULL, sysAircraftID_oid, OID_LENGTH(sysAircraftID_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&sysAircraftID_winfo, sysAircraftID, strlen(sysAircraftID), ASN_OCTET_STR, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &sysAircraftID_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched sysAircraftID" ); } /*end sysAircraftID*/ fetch_string("sysAircraftType",sysAircraftType); /*sysAircraftType*/ DEBUGMSGTL(("gpDroneMIB", "Initializing sysAircraftType scalar octet string. Default value = %s\n", sysAircraftType)); reg = netsnmp_create_handler_registration( "sysAircraftType", NULL, sysAircraftType_oid, OID_LENGTH(sysAircraftType_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&sysAircraftType_winfo, sysAircraftType, strlen(sysAircraftType), ASN_OCTET_STR, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &sysAircraftType_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched sysAircraftID" ); } /*end sysAircraftType*/ DEBUGMSGTL(("gpDroneMIB", "Initializing sysTimeUp scalar integer. Default value = %d\n", sysTimeUp)); reg = netsnmp_create_handler_registration( "sysTimeUp", sysTimeUpHandler, sysTimeUp_oid, OID_LENGTH(sysTimeUp_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&sysTimeUp_winfo, &sysTimeUp, sizeof(u_long), ASN_TIMETICKS, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &sysTimeUp_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched sysTimeUp" ); } /*instPosGpsLatitude*/ DEBUGMSGTL(("gpDroneMIB", "Initializing instPosGpsLatitude scalar octet string. Default value = %s\n", instPosGpsLatitude)); reg = netsnmp_create_handler_registration( "instPosGpsLatitude", instPosGpsLatitudeHandler, instPosGpsLatitude_oid, OID_LENGTH(instPosGpsLatitude_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&instPosGpsLatitude_winfo, instPosGpsLatitude, strlen(instPosGpsLatitude), ASN_OCTET_STR, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &instPosGpsLatitude_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched instPosGpsLatitude" ); } /*end instPosGpsLatitude*/ /*instPosGpsLongitude*/ DEBUGMSGTL(("gpDroneMIB", "Initializing instPosGpsLongitude scalar octet string. Default value = %s\n", instPosGpsLongitude)); reg = netsnmp_create_handler_registration( "instPosGpsLongitude", instPosGpsLongitudeHandler, instPosGpsLongitude_oid, OID_LENGTH(instPosGpsLongitude_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&instPosGpsLongitude_winfo, instPosGpsLongitude, strlen(instPosGpsLongitude), ASN_OCTET_STR, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &instPosGpsLongitude_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" ); } /*end instPosGpsLongitude*/ /*instPosAltitude*/ DEBUGMSGTL(("gpDroneMIB", "Initializing instPosAltitude scalar octet string. Default value = %s\n", instPosAltitude)); reg = netsnmp_create_handler_registration( "instPosAltitude", instPosAltitudeHandler, instPosAltitude_oid, OID_LENGTH(instPosAltitude_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&instPosAltitude_winfo, instPosAltitude, strlen(instPosAltitude), ASN_OCTET_STR, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &instPosAltitude_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" ); } /*end instPosAltitude*/ /*instSpeedGround*/ DEBUGMSGTL(("gpDroneMIB", "Initializing instSpeedGround scalar octet string. Default value = %s\n", instSpeedGround)); reg = netsnmp_create_handler_registration( "instSpeedGround", instSpeedGroundHandler, instSpeedGround_oid, OID_LENGTH(instSpeedGround_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&instSpeedGround_winfo, instSpeedGround, strlen(instSpeedGround), ASN_OCTET_STR, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &instSpeedGround_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" ); } /*end instSpeedGround*/ /*instSpeedVertical*/ DEBUGMSGTL(("gpDroneMIB", "Initializing instSpeedVertical scalar octet string. Default value = %s\n", instSpeedVertical)); reg = netsnmp_create_handler_registration( "instSpeedVertical", instSpeedVerticalHandler, instSpeedVertical_oid, OID_LENGTH(instSpeedVertical_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&instSpeedVertical_winfo, instSpeedVertical, strlen(instSpeedVertical), ASN_OCTET_STR, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &instSpeedVertical_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" ); } /*end instSpeedVertical*/ /*instClTime*/ DEBUGMSGTL(("gpDroneMIB", "Initializing instClTime scalar octet string. Default value = %s\n", instClTime)); reg = netsnmp_create_handler_registration( "instClTime", instClTimeHandler, instClTime_oid, OID_LENGTH(instClTime_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&instClTime_winfo, instClTime, strlen(instClTime), ASN_OCTET_STR, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &instClTime_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" ); } /*end instClTime*/ DEBUGMSGTL(("gpDroneMIB", "Initializing lightNum scalar integer. Default value = %d\n", lightNum)); reg = netsnmp_create_handler_registration( "lightNum", NULL, lightNum_oid, OID_LENGTH(lightNum_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&lightNum_winfo, &lightNum, sizeof(long), ASN_INTEGER, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &lightNum_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched lightNum" ); } DEBUGMSGTL(("gpDroneMIB", "Initializing lgSetPosition scalar integer. Default value = %d\n", lgSetPosition)); reg = netsnmp_create_handler_registration( "lgSetPosition", lgSetPositionHandler, lgSetPosition_oid, OID_LENGTH(lgSetPosition_oid), HANDLER_CAN_RWRITE); netsnmp_init_watcher_info(&lgSetPosition_winfo, &lgSetPosition, sizeof(long), ASN_INTEGER, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &lgSetPosition_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched lgSetPosition" ); } //New fuel variable... DEBUGMSGTL(("gpDroneMIB", "Initializing instTotalFuel scalar octet string. Default value = %s\n", instTotalFuel)); reg = netsnmp_create_handler_registration( "instTotalFuel", instTotalFuelHandler, instTotalFuel_oid, OID_LENGTH(instTotalFuel_oid), HANDLER_CAN_RONLY); netsnmp_init_watcher_info(&instTotalFuel_winfo, instTotalFuel, strlen(instTotalFuel), ASN_OCTET_STR, WATCHER_FIXED_SIZE); if (netsnmp_register_watched_scalar( reg, &instTotalFuel_winfo ) < 0 ) { snmp_log( LOG_ERR, "Failed to register watched instPosGpsLongitude" ); } /* here we initialize all the tables we're planning on supporting */ initialize_table_lightingTable(); DEBUGMSGTL(("gpDroneMIB", "Done initalizing gpDroneMIB module\n")); }
static GHashTable * parse_settings (unsigned char *data, size_t len) { XSettingsBuffer buffer; GHashTable *settings = NULL; CARD32 serial; CARD32 n_entries; CARD32 i; GValue *value = NULL; char *x_name = NULL; const char *gdk_name; buffer.pos = buffer.data = data; buffer.len = len; if (!fetch_card8 (&buffer, (unsigned char *)&buffer.byte_order)) goto out; if (buffer.byte_order != MSBFirst && buffer.byte_order != LSBFirst) { g_warning ("Invalid XSETTINGS property (unknown byte order %u)", buffer.byte_order); goto out; } buffer.pos += 3; if (!fetch_card32 (&buffer, &serial) || !fetch_card32 (&buffer, &n_entries)) goto out; GDK_NOTE(SETTINGS, g_print("reading %u settings (serial %u byte order %u)\n", n_entries, serial, buffer.byte_order)); for (i = 0; i < n_entries; i++) { CARD8 type; CARD16 name_len; CARD32 v_int; if (!fetch_card8 (&buffer, &type)) goto out; buffer.pos += 1; if (!fetch_card16 (&buffer, &name_len)) goto out; if (!fetch_string (&buffer, name_len, &x_name) || /* last change serial (we ignore it) */ !fetch_card32 (&buffer, &v_int)) goto out; switch (type) { case XSETTINGS_TYPE_INT: if (!fetch_card32 (&buffer, &v_int)) goto out; value = g_new0 (GValue, 1); g_value_init (value, G_TYPE_INT); g_value_set_int (value, (gint32) v_int); GDK_NOTE(SETTINGS, g_print(" %s = %d\n", x_name, (gint32) v_int)); break; case XSETTINGS_TYPE_STRING: { char *s; if (!fetch_card32 (&buffer, &v_int) || !fetch_string (&buffer, v_int, &s)) goto out; value = g_new0 (GValue, 1); g_value_init (value, G_TYPE_STRING); g_value_take_string (value, s); GDK_NOTE(SETTINGS, g_print(" %s = \"%s\"\n", x_name, s)); } break; case XSETTINGS_TYPE_COLOR: { unsigned short red, green, blue, alpha; GdkRGBA rgba; if (!fetch_ushort (&buffer, &red) || !fetch_ushort (&buffer, &green) || !fetch_ushort (&buffer, &blue) || !fetch_ushort (&buffer, &alpha)) goto out; rgba.red = red / 65535.0; rgba.green = green / 65535.0; rgba.blue = blue / 65535.0; rgba.alpha = alpha / 65535.0; value = g_new0 (GValue, 1); g_value_init (value, G_TYPE_STRING); g_value_set_boxed (value, &rgba); GDK_NOTE(SETTINGS, g_print(" %s = #%02X%02X%02X%02X\n", x_name, alpha,red, green, blue)); } break; default: /* Quietly ignore unknown types */ GDK_NOTE(SETTINGS, g_print(" %s = ignored (unknown type %u)\n", x_name, type)); break; } gdk_name = gdk_from_xsettings_name (x_name); g_free (x_name); x_name = NULL; if (gdk_name == NULL) { GDK_NOTE(SETTINGS, g_print(" ==> unknown to GTK\n")); free_value (value); } else { GDK_NOTE(SETTINGS, g_print(" ==> storing as '%s'\n", gdk_name)); if (settings == NULL) settings = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, free_value); if (g_hash_table_lookup (settings, gdk_name) != NULL) { g_warning ("Invalid XSETTINGS property (Duplicate entry for '%s')", gdk_name); goto out; } g_hash_table_insert (settings, (gpointer) gdk_name, value); } value = NULL; } return settings; out: if (value) free_value (value); if (settings) g_hash_table_unref (settings); g_free (x_name); return NULL; }