Exemplo n.º 1
0
// checks if a positions is on the same street as a segment
static int check_same_street(const PluginLine *line, const RoadMapPosition *point_position) {

    const char *street_name;
    const char *city_name;
    char			current_street_name[512];
    char			current_city_name[512];
    int point_res;
    int square_current = roadmap_square_active ();

    get_street_from_line (line->square, line->line_id, &street_name, &city_name);
    strncpy_safe (current_street_name, street_name, sizeof (current_street_name));
    strncpy_safe (current_city_name, city_name, sizeof (current_city_name));

    point_res = get_street(point_position, &street_name, &city_name);

    roadmap_square_set_current (square_current);

    if (point_res == -1)
        return FALSE;

    if (strcmp (current_street_name, street_name) == 0 &&
            strcmp (current_city_name, city_name) == 0)
        return TRUE;
    else
        return FALSE;

}
Exemplo n.º 2
0
const char *roadmap_db_map_path (void) {

   const char *map_path;
   static char map_path_static[512];
   static int map_path_initialized = 0;
   
   if (!map_path_initialized) { 
   
	#ifdef J2ME
      map_path = roadmap_path_preferred("maps");;
      strncpy_safe (map_path_static, map_path, sizeof (map_path_static));
	#elif defined (WIN32)
		map_path = roadmap_path_join (roadmap_path_user(), "maps");
		strncpy_safe (map_path_static, map_path, sizeof (map_path_static));
		roadmap_path_free (map_path);
	#elif IPHONE
	   map_path = roadmap_path_join (roadmap_main_bundle_path(), "maps");
	   strncpy_safe (map_path_static, map_path, sizeof (map_path_static));
	   roadmap_path_free (map_path);
	#else
	   map_path = roadmap_path_first ("maps");
	   while (map_path && !roadmap_file_exists (map_path,"")) {
	   	map_path = roadmap_path_next ("maps", map_path);
	   }
	   if (map_path) {
			strncpy_safe (map_path_static, map_path, sizeof (map_path_static));
	   } else {
	   	map_path_static[0] = '\0';
	   }
	#endif
		map_path_initialized = 1;
   }
   	
   return map_path_static;
}
Exemplo n.º 3
0
int msg_reg_get_msg_format(char *msg_fmt, int len, int msg_sn)
{
	struct mr_message *pmsg		= NULL;
	int index					= 0;
	va_list args;
	int ret;

	if (!g_mr)
		return RF_NOT_INIT;

	pmsg = g_mr->msg_header;
	while (pmsg) {
		if (msg_sn == pmsg->msg_sn) {
			strncpy_safe(msg_fmt, pmsg->msg, len, len - 1);
			break;
		}
		pmsg = pmsg->pnext;
	}
	if (!pmsg)
		return RF_NOT_FOUND;

	for (index = 0; index < 2; index++)
		str_replace(msg_fmt, len, rf_evt_params_convet_map[index].src, rf_evt_params_convet_map[index].rep);

	return RF_SUCCESS;
}
Exemplo n.º 4
0
void tts_db_generate_path( const char* voice_id, TtsPath* db_path )
{
   static char s_voice_id[TTS_VOICE_MAXLEN] = {0};
   static unsigned long counter = 0;
   char path_suffix[TTS_PATH_MAXLEN];
   const EpochTimeMicroSec* time_now = roadmap_time_get_epoch_us( NULL );


   if ( !db_path )
      return;

   // File name
   snprintf( path_suffix, sizeof( path_suffix ), "%s//%s//%lu-%lu-%lu.%s", TTS_DB_FILES_ROOT_DIR, voice_id,
         time_now->epoch_sec, time_now->usec, counter++, TTS_RESULT_FILE_NAME_EXT );
   // Full path
   roadmap_path_format( db_path->path, TTS_PATH_MAXLEN, roadmap_path_tts(), path_suffix );

   if ( strcmp( s_voice_id, voice_id ) ) // Save io time
   {
      char* parent = roadmap_path_parent( db_path->path, NULL );
      strncpy_safe( s_voice_id, voice_id, TTS_VOICE_MAXLEN );
      // Create path if not exists
      roadmap_path_create( parent );
      free( parent );
   }
}
Exemplo n.º 5
0
static int roadmap_nmea_rmc (int argc, char *argv[]) {

   if (argc <= 9) return 0;

   RoadMapNmeaReceived.rmc.status = *(argv[2]);


   RoadMapNmeaReceived.rmc.fixtime =
      roadmap_nmea_decode_time (argv[1], argv[9]);

   strncpy_safe (RoadMapNmeaDate, argv[9], sizeof(RoadMapNmeaDate));

   if (RoadMapNmeaReceived.rmc.fixtime < 0) return 0;


   RoadMapNmeaReceived.rmc.latitude =
      roadmap_nmea_decode_coordinate  (argv[3], argv[4], 'N', 'S');

   if (RoadMapNmeaReceived.rmc.latitude == 0) return 0;

   RoadMapNmeaReceived.rmc.longitude =
      roadmap_nmea_decode_coordinate (argv[5], argv[6], 'E', 'W');

   if (RoadMapNmeaReceived.rmc.longitude == 0) return 0;


   RoadMapNmeaReceived.rmc.speed =
      roadmap_nmea_decode_numeric (argv[7], 1);

   RoadMapNmeaReceived.rmc.steering =
      roadmap_nmea_decode_numeric (argv[8], 1);

   return 1;
}
Exemplo n.º 6
0
/*
 Get the message args format from message types(Int array)
 For example: [1,2,1] => ("%d,%s,%d")
*/
int msg_reg_get_args_format(char *msg_args_fmt, int max_len, int msg_sn)
{
	struct mr_message *pmsg		= NULL;
	int		index				= 0;
	va_list args;
	int		ret;
	char	tmp[256]			= {0};

	if (!g_mr)
			return RF_NOT_INIT;

	pmsg = g_mr->msg_header;
	while (pmsg) {
		/*Search all all msg, find msg idx is equal.*/
		if (msg_sn == pmsg->msg_sn) {
			for (index = 0; index < pmsg->num_of_args; index++) {
				if (index != 0)
					strncat(tmp, ",", 1);

				if (pmsg->types[index] == TYPE_STR_ID)
					strncat(tmp, "%s", 2);
				else if (pmsg->types[index] == TYPE_INT_ID)
					strncat(tmp, "%d", 2);
				else
					printf("error message type: %d\n", pmsg->types[index]);
			}

			strncpy_safe(msg_args_fmt, tmp, max_len, max_len - 1);
			return RF_SUCCESS;
		}
		pmsg = pmsg->pnext;
	}

	return RF_NOT_FOUND;
}
Exemplo n.º 7
0
static void draw_browser_rect(SsdWidget widget, RoadMapGuiRect *rect, int flags){
   RTBonus *pbonus = (RTBonus *)widget->context;
   RMBrowserContext context;
   int width, height;
   if ((flags & SSD_GET_SIZE)){
      return;
   }

   if (pbonus == NULL)
      return;

   if ( (old_rect.minx != rect->minx) || (old_rect.maxx != rect->maxx) || (old_rect.miny != rect->miny) || (old_rect.maxy != rect->maxy)){
      if ( (old_rect.minx != -1) && (old_rect.maxx != -1) && (old_rect.miny != -1) && (old_rect.maxy != -1))
         roadmap_browser_close_embedded();
      old_rect = *rect;
      context.flags = BROWSER_FLAG_WINDOW_TYPE_TRANSPARENT|BROWSER_FLAG_WINDOW_TYPE_NO_SCROLL;
      context.rect = *rect;
      height = rect->maxy - rect->miny +1;
      width = rect->maxx - rect->minx +1;
      strncpy_safe( context.url, build_url( pbonus, height, width ), WEB_VIEW_URL_MAXSIZE );
      context.attrs.on_close_cb = NULL;
      context.attrs.title_attrs.title = NULL;
      context.attrs.on_load_cb = NULL;
      roadmap_browser_show_embedded(&context);
   }

}
static void roadmap_address_street_result (const char *result, void *data) {

   RoadMapAddressDialog *context = (RoadMapAddressDialog *)data;
   char name[255];
   char *tmp;

   if ((result == NULL) || !strlen (result)) return;

   strncpy_safe (name, result, sizeof(name));

   tmp = strrchr (name, ',');
   if (tmp) {
      *tmp = 0;
      tmp += 2;

      if (*tmp && !*context->city_name) {
         free (context->city_name);
         context->city_name = strdup (tmp);
      }
   }

   if (context->street_name) free(context->street_name);
   context->street_name = strdup(name);


   ssd_show_keyboard_dialog(  roadmap_lang_get ("House number"),
                              NULL,
                              house_keyboard_callback,
                              context);
}
void get_evt_links(rf_link_t *links, int32 type, int32 reg, const int8 *fmt, ...)
{
	va_list args;
	int32 port;
	int8 ip_addr[WRAP_DB_MAX_VALUE_LEN] = {0};
	memdb_integer nid = 0;
	int32 mask, zone_reg = 0;
	int8 fmt_hdr[256] = {0};
	int8 format[2048] = {0};
	int8 prefix[MAX_URL] = {0};

	rmm_cfg_get_rest_prefix(prefix, MAX_URL);

	if (libutils_get_ip((int8 *)ip_addr) < 0) {
		memset(ip_addr, 0, WRAP_DB_MAX_VALUE_LEN);
		strncpy_safe(ip_addr, "x", sizeof(ip_addr), 1);
	}

	port = rmm_cfg_get_port(RESTD_PORT);
	if (port == 0) {
		HTTPD_ERR("Failed to call rmm_cfg_get_restd_port\n");
		exit(-1);
	}

	snprintf(fmt_hdr, sizeof(fmt_hdr), RF_EVENT_URL_FMT_HDR, ip_addr, port);
	snprintf(format, sizeof(format), "%s%s%s", fmt_hdr, fmt, prefix);

	va_start(args, fmt);
	vsprintf(links->self, format, args);
	va_end(args);

	nid = libwrap_get_uniq_node_by_type(type);

	libwrap_get_listener_links(reg, nid, links);
}
Exemplo n.º 10
0
/*
 ******************************************************************************
 * Queue one TTS request.
 * Auxiliary
 */
static const char* _parse_text( const char* text )
{
   static char parsed_text[TTS_TEXT_MAX_LENGTH];
   char* pCh = parsed_text;

   strncpy_safe( parsed_text, text, TTS_TEXT_MAX_LENGTH );

   for( ; *pCh; pCh++ )
   {
      if ( *pCh == '|' )
      {
         *pCh = ' ';
      }

//      if ( *pCh == ',' || *pCh == '.' )
//         continue;
//      if ( *pCh >= '0' && *pCh <= '9' )
//         continue;
//      if ( *pCh >= 'A' && *pCh <= 'Z' )
//         continue;
//      if ( *pCh >= 'a' && *pCh <= 'z' )
//         continue;
//
//      // Otherwise replace by space
//      *pCh = ' ';
   }
   return parsed_text;
}
Exemplo n.º 11
0
/**
 * Generate an Alert from TrafficInfo
  * @param pTrafficInfo - pointer to the TrafficInfo
 * @return TRUE operation was successful
 */
static BOOL RTTrafficInfo_GenerateAlert(RTTrafficInfo *pTrafficInfo, int iNodeNumber)
{
	RTAlert alert;
	int speed;

	RTAlerts_Alert_Init(&alert);

	alert.iID = pTrafficInfo->iID +  ALERT_ID_OFFSET;

	alert.iType = RT_ALERT_TYPE_TRAFFIC_INFO;
	alert.iSubType = pTrafficInfo->iType;
	alert.iSpeed = (int)(roadmap_math_meters_p_second_to_speed_unit( (float)pTrafficInfo->fSpeed)+0.5F);

	strncpy_safe(alert.sLocationStr, pTrafficInfo->sDescription,RT_ALERT_LOCATION_MAX_SIZE);

	speed = (int)(roadmap_math_meters_p_second_to_speed_unit((float)pTrafficInfo->fSpeed));
	sprintf(alert.sDescription, roadmap_lang_get("Average speed %d %s"), speed,  roadmap_lang_get(roadmap_math_speed_unit()) );
	alert.iDirection = RT_ALERT_MY_DIRECTION;
	alert.i64ReportTime = time(NULL);

	alert.bAlertByMe = FALSE;
	alert.iLatitude = pTrafficInfo->sNodes[iNodeNumber].Position.latitude;
	alert.iLongitude = pTrafficInfo->sNodes[iNodeNumber].Position.longitude;

	return RTAlerts_Add(&alert);

}
Exemplo n.º 12
0
static int get_log_modules(json_t *obj, struct rmm_log_module *modules, int *count)
{
	json_pair_t *pair;
	int index = 0;
	int max_lines;
	int level;
	int handler;

	json_t *rmm_logd = json_object_get(obj, PROC_RMM_LOGD);

	if (rmm_logd == NULL) {
		printf("Can't find the %s attribute.\n", PROC_RMM_LOGD);
		return -1;
	}

	json_t *log_modules = json_object_get(rmm_logd, ATTR_LOG_MODULES);

	if (log_modules == NULL)
		return -1;

	json_object_t *jobj_log_modules = json_to_object(log_modules);

	if (jobj_log_modules == NULL)
		return -1;

	for (pair = jobj_log_modules->next; pair != NULL; pair = pair->next) {
		strncpy_safe(modules[index].name, pair->name, RMM_LOG_MODULE_NAME_LEN, RMM_LOG_MODULE_NAME_LEN - 1);
		modules[index].max_lines = get_json_int_value(pair->value,  ATTR_MAX_LINES);
		modules[index].level = get_json_int_value(pair->value, ATTR_LOG_LEVEL);
		index++;
	}
	*count = index;
	return 0;
}
Exemplo n.º 13
0
int rmm_cfg_get_vm_root_password(char *password, int max_len, int vm_idx)
{
	json_t *jvm;
	char attr[16] = {0};
	snprintf(attr, sizeof(attr),"%s%d", ATTR_VM_HEADER, vm_idx);

	json_t *conf = load_rmm_cfg();
	if (conf == 0) {
		printf("Load rmm config file fail...\n");
		return -1;
	}

	jvm = get_json_attr(conf, PROC_AUTO_TEST, attr);
	if (jvm == NULL)
		return -1;

	json_t *jpw = json_object_get(jvm, ATTR_VM_ROOT_PASSWORD);
	if (jpw == NULL) {
		printf("Can't find the %s attribute.\n", ATTR_VM_ROOT_PASSWORD);
		return -1;
	}
	char *data = json_string_value(jpw);
	strncpy_safe(password, data, max_len, max_len - 1);
	json_free(conf);
	return 0;
}
Exemplo n.º 14
0
static int get_tty_infos(json_t *obj, char *infos, int *count)
{
	int index = 0;
	char *data;

	json_t *rmm_logd = json_object_get(obj, PROC_ASSETD);
	if (rmm_logd == NULL) {
		printf("Can't find the %s attribute.\n", PROC_ASSETD);
		return -1;
	}

	json_t *tty_infos = json_object_get(rmm_logd, ATTR_TTY_INFOS);
	if (tty_infos == NULL) {
		printf("Can't find the %s attribute.\n", ATTR_TTY_INFOS);
		return -1;
	}

	int array_size = json_array_size(tty_infos);
	for (index = 0; index < array_size; index++) {
		data = json_string_value(json_array_get(tty_infos, index));
		if(data)
			strncpy_safe(infos + RMM_TTY_INFO_LEN * index, data, RMM_TTY_INFO_LEN, RMM_TTY_INFO_LEN - 1);
	}

	*count = index;
	return 0;
}
SETTINGS_READER_RESULT Settings_parseDataChannelSetting(char const * const setting, int lineNo)
{
    char * pSettingString;
    char * pValueString;
    char * pChannelString;
    char * pChannelSettingString;

    uint8_t length = strlen(setting);

    char lowercaseCopy[MAX_LINE_LENGTH];

    strncpy_safe(lowercaseCopy, setting, length+1);
    toLowerStr(lowercaseCopy);

    bool success = true;

    if (*setting == '#') { return noError(); } // Line is a comment
    
    // If line is blank, fail early
    if (stringIsWhitespace(setting)) { return noError(); }

    // Split the string by '=' to get setting and name
    success &= splitAndStripWhiteSpace(lowercaseCopy, '=', &pSettingString, NULL, &pValueString, NULL);
    if (!success) { return noEqualsError(lineNo); }

    // Split the setting to get channel and setting name
    success &= splitAndStripWhiteSpace(pSettingString, '.', &pChannelString, NULL, &pChannelSettingString, NULL);
    if (!success) { return noSettingError(lineNo); }

    int8_t ch = Settings_getChannelFromSetting(pChannelString);
    if (ch == -1) { return noChannelError(lineNo); }

    if (0 == strncmp(pChannelSettingString, "type", 4))
    {
        // Try to interpret setting as a channel type
        s_fieldTypes[ch] = Setting_parseSettingAsType(pValueString);
        if (s_fieldTypes[ch] == INVALID_TYPE) { return unknownTypeError(lineNo, pValueString); }

        setupChannel(ch, s_fieldTypes[ch]);
        return noError();
    }

    /* If processing got this far, the setting needs to be interpreted based on the channel datatype */
    switch (s_fieldTypes[ch])
    {
    case VOLTAGE:
        return tryParseAsVoltageSetting(ch, pChannelSettingString, pValueString, lineNo);
    case CURRENT:
        return tryParseAsCurrentSetting(ch, pChannelSettingString, pValueString, lineNo);
    case TEMPERATURE_C:
    case TEMPERATURE_F:
    case TEMPERATURE_K:
        return tryParseAsThermistorSetting(ch, pChannelSettingString, pValueString, lineNo);

    case INVALID_TYPE:
    default:
        // If the channel type is not set prior to any other settings, this is an error.
        return channelNotSetError(lineNo, ch);
    }
}
Exemplo n.º 16
0
static void roadmap_option_set_geometry2 (const char *value) {

    char *p;
    char *geometry;
    char buffer[256];
    RoadMapConfigDescriptor descriptor;

    strncpy_safe (buffer, value, sizeof(buffer));

    geometry = strchr (buffer, '=');
    if (geometry == NULL) {
        roadmap_log (ROADMAP_FATAL,
                     "%s: invalid geometry option syntax", value);
    }
    *(geometry++) = 0;

    for (p = strchr(buffer, '-'); p != NULL; p =strchr(p, '-')) {
        *p = ' ';
    }

    descriptor.category = "Geometry";
    descriptor.name = strdup(buffer);
    descriptor.reference = NULL;
    roadmap_config_declare ("preferences", &descriptor, "300x200", NULL);
    roadmap_config_set (&descriptor, geometry);
}
Exemplo n.º 17
0
int roadmap_sound_list_add_buf (RoadMapSoundList list, void* buf, size_t size )
{
   char path[512];
   int file_num = list->count;
   RoadMapFile file;

   if (list->count == MAX_SOUND_LIST) return SND_LIST_ERR_LIST_FULL;

   list->buf_list[list->count] = buf;
   list->buf_list_sizes[list->count] = size;


   /*
    * Temporary solution - write the buffer to the file for further playing
    * AGA
    */
   sprintf( path, "%s/tmp/%d", roadmap_path_tts(), file_num );
   if ( file_num == 0 )
   {
      roadmap_path_create( roadmap_path_parent( path, NULL ) );
   }

   file = roadmap_file_open( path, "w" );
   roadmap_file_write( file, buf, size );
   roadmap_file_close( file );

   strncpy_safe( list->list[list->count], path, 512 );


   list->count++;

   return list->count - 1;
}
Exemplo n.º 18
0
long log_init(const char *module_name)
{
	struct loginfo* phandler = (struct loginfo*)malloc(sizeof(struct loginfo));
	set_path_by_module_name(phandler, module_name);
	strncpy_safe(phandler->module, module_name, MAX_PATH_SIZE, MAX_PATH_SIZE - 1);
	log_init_handler(phandler);
	return (long)phandler;
}
Exemplo n.º 19
0
static void load_json_str_value(char *dest, int max_len, json_t *jobj, char *name)
{
	char *data = get_json_str(jobj, name);

	if (data == NULL)
		return;
	strncpy_safe(dest, data, max_len, max_len - 1);
}
Exemplo n.º 20
0
static int roadmap_nmea_pgrmm (int argc, char *argv[]) {

    if (argc <= 1) return 0;

    strncpy_safe (RoadMapNmeaReceived.pgrmm.datum,
             		argv[1], sizeof(RoadMapNmeaReceived.pgrmm.datum));

    return 1;
}
Exemplo n.º 21
0
const char *xml_get_string_value(xmlDoc *doc, char *format, ...)
{
  va_list ap;
  char str[4096];

  va_start(ap, format);
  vsnprintf(str, 4095, format, ap);
  va_end(ap);

  int i,n;
  char **arr;
  int found = TRUE;

  split_into_array(str, '.', &n, &arr);

  xmlNode *cur = xmlDocGetRootElement(doc);

  // first item much match the name of the root
  if (strcmp(arr[0], (char*)cur->name)!=0) {
    // root node doesn't match -- return empty string
    strcpy(buf, "");
  }
  else {
    // subsequent items specify the search path through the xml tree
    for (i=1; i<n; ++i) {
      char *elem;
      int k;
      extract_array_specifier(arr[i], &elem, &k);

      xmlNode *next = findNode(doc, cur, elem, k);
      if (!next) {
        // not found -- return NULL
        found = FALSE;
        strcpy(buf, "");
        FREE(elem);
        break;
      }
      
      FREE(elem);
      cur = next;
    }
  }

  if (found) {
    assert(cur != NULL);
    xmlChar *ret = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
    strncpy_safe(buf, (char*)ret, MAX_LEN-1);
    xmlFree(ret);
  }
  else {
    strcpy(buf, MAGIC_UNSET_STRING);
  }

  free_char_array(&arr, n);

  return buf;
}
void get_event_type_by_nodeid(int32 nodeid, int8 *data, int32 data_len)
{
	int32 i  = 0;

	for (i = 0; i < sizeof(nodeid_keys) / sizeof(id_evt_type_t); i++) {
		if (nodeid_keys[i].node_id == nodeid) {
			strncpy_safe(data, nodeid_keys[i].type_name, data_len, data_len - 1);
			return;
		}
	}
	HTTPD_ERR("nodeid input error: %d\n", nodeid);
}
Exemplo n.º 23
0
void set_title(int band_specified, const char *band_in)
{
    // acquisition planning -- leave the title as it is.
    if (planner_is_active()) return;

    char title[256];
    char band[128];

    if (band_in)
        strncpy_safe(band, band_in, sizeof(band));
    else
        strcpy(band, "");

    meta_parameters *meta = curr->meta;
    char *basename = get_basename(curr->data_name);
    snprintf(title, 239, "asf_view ver %s: %s", VERSION, basename);

    if (band_specified) {
        sprintf(&title[strlen(title)], " (%s)", band);
    } else if (meta && meta->general && meta->general->band_count > 1) {
        if (strlen(meta->general->bands) > 0) {
            strncpy_safe(band, meta->general->bands, sizeof(band));
            char *p = strchr(band, ',');
            if (p) *p = '\0';
        } else if (strncmp_case(basename, "IMG-", 4) == 0) {
            strncpy_safe(band, basename+4, sizeof(band));
            char *p = strchr(band, '-');
            if (p) *p = '\0';
        } else {
            strcpy(band, "");
        }
        if (strlen(band) > 0 && strcmp(band, MAGIC_UNSET_STRING) != 0)
            sprintf(&title[strlen(title)], " (%s)", band);
    }
    free(basename);

    GtkWidget *widget = get_widget_checked("ssv_main_window");
    gtk_window_set_title(GTK_WINDOW(widget), title);
}
Exemplo n.º 24
0
void test_strncpy(){
	int8_t tx[5];
	int8_t rx[32];
	int len;
	printf("-----test strncpy-----\n");
	snprintf_safe(tx, 5, "%s", "binh");
	snprintf_safe(rx, 32, "%s", "ngo sdffsdfsdf");
	len = strlen_safe(tx);
	printf("tx='%s' len=%d\n", tx, len);
	strncpy_safe((char*)tx, (char*)rx, 5);
	len = strlen_safe(tx);
	printf("tx='%s' len=%d %s\n", tx, len, (len == 4) ? "DONE" : "FAILED");
}
Exemplo n.º 25
0
void editor_marker_voice_file(int marker, char *file, int size) {
    char *path = roadmap_path_join (roadmap_path_user (), "markers");
    char file_name[100];
    char *full_name;

    roadmap_path_create (path);
    snprintf (file_name, sizeof(file_name), "voice_%d.wav", marker);

    full_name = roadmap_path_join (path, file_name);
    strncpy_safe (file, full_name, size);

    roadmap_path_free (full_name);
    roadmap_path_free (path);
}
Exemplo n.º 26
0
// Main program body.
int
main (int argc, char *argv[])
{
  int currArg = 1;
  int NUM_ARGS = 4;

  handle_license_and_version_args(argc, argv, ASF_NAME_STRING);
  asfSplashScreen(argc, argv);

  if (argc >= 2 && strmatches(argv[1],"-help","--help",NULL))
    print_help();
  if (argc<3)
    rtc_usage(ASF_NAME_STRING);

  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key,"-help","--help",NULL)) {
        print_help(); // doesn't return
    }
    else if (strmatches(key,"-log","--log",NULL)) {
      CHECK_ARG(1);
      strncpy_safe(logFile,GET_ARG(1),256);
      fLog = FOPEN(logFile, "a");
      logflag = TRUE;
    }
    else if (strmatches(key,"-quiet","--quiet","-q",NULL)) {
      quietflag = TRUE;
    }
    else {
      --currArg;
      break;
    }
  }

  if ((argc-currArg) < NUM_ARGS) {
    printf("Insufficient arguments.  Expected %d, got %d.\n",
           NUM_ARGS, argc-currArg);
    rtc_usage(argv[0]);
  } else if ((argc-currArg) > NUM_ARGS) {
    printf("Unknown argument: %s\n", argv[currArg]);
    rtc_usage(argv[0]);
  }

  int fail = uavsar_rtc(argv[currArg], argv[currArg+1], argv[currArg+2],
                        argv[currArg+3]);

  asfPrintStatus(fail ? "Failed.\n" : "Done.\n");
  return fail ? EXIT_FAILURE : EXIT_SUCCESS;
}
Exemplo n.º 27
0
int rmm_cfg_get_rmcp_password(char *password, int max_len)
{
	int rc = 0;
	char ciphertxt[CIPHER_LENGTH_MAX] = {};
	char plaintxt[PLAIN_LENGTH_MAX] = {};

	rc = get_str_attr(PROC_IPMI_MODULE, ATTR_RMCP_PASSWORD, ciphertxt, CIPHER_LENGTH_MAX);
	if (rc == 0) {
		rc = rmm_decrypt(ciphertxt, RMM_DECRYPT_KEYFILE, plaintxt);
		if (rc == 0) {
			strncpy_safe(password, plaintxt, max_len, max_len - 1);
		}
	}
	return rc;
}
Exemplo n.º 28
0
int rmm_cfg_get_rmcp_username(char *username, int max_len)
{
	int rc = 0;
	char ciphertxt[CIPHER_LENGTH_MAX] = {};
	char plaintxt[PLAIN_LENGTH_MAX] = {};

	rc = get_str_attr(PROC_IPMI_MODULE, ATTR_RMCP_USERNAME, ciphertxt, CIPHER_LENGTH_MAX);
	if (rc == 0) {
		rc = rmm_decrypt(ciphertxt, RMM_DECRYPT_KEYFILE, plaintxt);
		if (rc == 0) {
			strncpy_safe(username, plaintxt, max_len, max_len - 1);
		}
	}
	return rc;
}
Exemplo n.º 29
0
static void str_replace(char *target, int max_len, char *old, char *str_new)
{
	char *buffer = (char *)malloc(max_len);
	char *beg_of_substr = NULL;

	if (buffer == NULL)
		return;

	beg_of_substr = strstr(target, old);
	if (beg_of_substr == NULL) {
		free(buffer);
		return;
	}

	strncpy_safe(buffer, target, max_len, beg_of_substr - target);
	buffer[beg_of_substr-target] = '\0';

	snprintf(buffer + (beg_of_substr - target), max_len - (beg_of_substr - target), "%s%s", str_new, beg_of_substr + strlen(old));
	target[0] = '\0';
	strncpy_safe(target, buffer, max_len, max_len - 1);
	free(buffer);

	return str_replace(target, max_len, old, str_new);
}
Exemplo n.º 30
0
static int get_seqid(const char *data, int max_len)
{
	int ret = 0;
	char ch_id[256] = {0};
	int len = (max_len < 256 ? max_len : 256 - 1);
	strncpy_safe(ch_id, data, sizeof(ch_id), len);
	char* temp = strtok(ch_id, " ");

	if (temp)
		ret = (int)strtol(temp, NULL, 10);
	else 
		ret = 0;

	return ret;
}