void get_slotvar(char *cmd, char *response, size_t chars_left)
{
	int ret;
	struct boot_ctl t_bootctl;
	memset(&t_bootctl, 0, sizeof(t_bootctl));

	ret = read_bootctl(&t_bootctl);
	if (ret) {
		error("get_slotvar, read_bootctl failed\n");
		strcpy(response, "get_slotvar read_bootctl failed");
		return;
	}

	if (!strcmp_l1("has-slot:", cmd)) {
		char *ptnname = NULL;
		ptnname = strchr(cmd, ':') + 1;
		if (!strcmp(ptnname, "system") || !strcmp(ptnname, "boot"))
			strncat(response, "yes", chars_left);
		else
			strncat(response, "no", chars_left);
	} else if (!strcmp_l1("current-slot", cmd)) {
		unsigned int slot = slot_find(&t_bootctl);
		if (slot < SLOT_NUM)
			strncat(response, g_slot_suffix[slot], chars_left);
		else
			strncat(response, "no valid slot", chars_left);
	} else if (!strcmp_l1("slot-suffixes", cmd)) {
		strncat(response, "_a,_b", chars_left);
	} else if (!strcmp_l1("slot-successful:", cmd)) {
		char *suffix = strchr(cmd, ':') + 1;
		unsigned int slot = slotidx_from_suffix(suffix);
		if (slot >= SLOT_NUM) {
			strncat(response, "no such slot", chars_left);
		} else {
			bool suc = t_bootctl.a_slot_meta[slot].bootsuc;
			strncat(response, suc ? "yes" : "no", chars_left);
		}
	} else if (!strcmp_l1("slot-unbootable:", cmd)) {
		char *suffix = strchr(cmd, ':') + 1;
		unsigned int slot = slotidx_from_suffix(suffix);
		if (slot >= SLOT_NUM) {
			strncat(response, "no such slot", chars_left);
		} else {
			unsigned int pri = t_bootctl.a_slot_meta[slot].priority;
			strncat(response, pri ? "no" : "yes", chars_left);
		}
	} else if (!strcmp_l1("slot-retry-count:", cmd)) {
		char *suffix = strchr(cmd, ':') + 1;
		unsigned int slot = slotidx_from_suffix(suffix);
		if (slot >= SLOT_NUM)
			strncat(response, "no such slot", chars_left);
		else
			sprintf(response, "OKAY%d",
				t_bootctl.a_slot_meta[slot].tryremain);
	} else {
		strncat(response, "no such slot command", chars_left);
	}

	return;
}
char *select_slot(void)
{
	int i = 0;
	int ret = 0;
	unsigned int slot;
	struct boot_ctl t_bootctl;
	bool b_need_write = false;

	ret = read_bootctl(&t_bootctl);
	if (ret) {
		printf("read_bootctl failed, ret %d\n", ret);
		return NULL;
	}

	dump_slotmeta(&t_bootctl);

	slot = slot_find(&t_bootctl);
	if (slot >= SLOT_NUM) {
		printf("!!! select_slot, no valid slot\n");
		return NULL;
	}

	/* invalid slot, set priority to 0 */
	for (i	= 0; i < SLOT_NUM; i++) {
		struct slot_meta *pslot_meta = &(t_bootctl.a_slot_meta[i]);
		if ((pslot_meta->bootsuc == 0) &&
			(pslot_meta->tryremain == 0) &&
			(pslot_meta->priority > 0)) {
			pslot_meta->priority = 0;
			b_need_write = true;
		}
	}

	if (t_bootctl.recovery_tryremain != 7) {
		b_need_write = true;
		t_bootctl.recovery_tryremain = 7;
	}

	if ((t_bootctl.a_slot_meta[slot].bootsuc == 0) &&
		(t_bootctl.a_slot_meta[slot].tryremain > 0)) {
		b_need_write = true;
		t_bootctl.a_slot_meta[slot].tryremain--;
	}

	if (b_need_write) {
		ret = write_bootctl(&t_bootctl);
		if (ret)
			printf("!!! write_bootctl failed, ret %d\n", ret);
	}

	g_slot_selected = slot;

	if (slot == 0)
		return FASTBOOT_PARTITION_BOOT_A;
	else
		return FASTBOOT_PARTITION_BOOT_B;
}
Beispiel #3
0
//
// Main
//
int main(int argc, char* argv[]) {
	char *destip;
	u16 destport;
	int start_slot;
	int ret;
	int i=0;
	
	srand( time(NULL) );


	if (argc!=2){
		printf("usage: <skypename>\n");
		exit(1);
	};

	start_slot=slot_find(argv[1]);
	
	printf("Slot: #%d 0x%08X\n",start_slot,start_slot);

	ret=load_snodes_file();
	if (ret==-1){
		printf("file not found\n");
		return -1;
	};

	for(i=0;i<snodes_file_len;i++){

		destip=snodes_file[i].ip;
		destport=atoi(snodes_file[i].port);

		printf("Target node: %s\n",destip);

		ret=snode_tcp_test(destip,destport,start_slot);
		status_tcp_print(ret);

		if(ret==1){
			return 0;
		};

	};
	


	return 0;
	
}
Beispiel #4
0
//
// Main
//
int main(int argc, char* argv[]) {
	char *destip;
	u16 destport;
	char *skypeuser;
	char our_public_ip[128];
	u32 userslot;
	int ret;
	u32 i;
	FILE *fp;
	char line[8192];
	int file_ret;
	char *MY_ADDR;
	

	srand( time(NULL) );



	/*
	if (argc!=3){
		printf("usage: <skypename> <you public ip>\n");
		exit(1);
	};
	skypeuser=strdup(argv[1]);
	MY_ADDR=strdup(argv[2]);
	*/

	if (argc!=2){
		printf("usage: <you public ip>\n");
		exit(1);
	};
	MY_ADDR=strdup(argv[1]);

  
	

	strcpy(our_public_ip,MY_ADDR);

	ret=load_slots_file();
	if (ret==-1){
		printf("load nodes error\n");
		return -1;
	};


	fp=fopen("./_names.txt","r");
	if (fp==NULL){
		printf("file with names not found\n");
		return -1;
	};


	do {
		
		line[0]=0;
		file_ret=fscanf(fp,"%s\n",&line);
		if (strlen(line)==0){
			continue;
		};
		skypeuser=line;

		userslot=slot_find(skypeuser);

		printf("SkypeUser: %s\n",skypeuser);
		printf("User Slot: #%d (0x%08X)\n",userslot,userslot);
		printf("Nodes in slot: %d\n",slots[userslot].snodes_len);

		for (i=0;i<slots[userslot].snodes_len;i++){

			destip=slots[userslot].snodes[i].ip;
			destport=atoi(slots[userslot].snodes[i].port);

			printf("Search request to target node ip: %s\n",destip);

			ret=snode_udp_reqsearch(destip,destport,our_public_ip,skypeuser);
			if (ret==1){
				//exit(1);
			};
		};

	}while(file_ret!=EOF);


	fclose(fp);

			


	return 0;
	
}
STSourceEditor::STSourceEditor(QWidget *parent) : QWidget(parent) {
	ui.setupUi(this);
	CppHighlighter *m_highlighter_header=new CppHighlighter;
	CppHighlighter *m_highlighter_source=new CppHighlighter;
	m_highlighter_header->setDocument(ui.header->editor()->document());
	m_highlighter_source->setDocument(ui.source->editor()->document());
	
	QMap<QString,QTextCharFormat> formats;
	QTextCharFormat format;
	
	format.setForeground(QBrush(Qt::darkGreen));
	formats["comment"]=format;
	
	format.setForeground(QBrush(Qt::darkBlue));
	formats["cpp_keyword"]=format;
	
	format.setForeground(QBrush(Qt::darkMagenta));
	formats["qt_keyword"]=format;
	
	format.setForeground(QBrush(Qt::darkGray));
	formats["operator"]=format;
	
	format.setForeground(QBrush(Qt::darkGray));
	formats["number"]=format;
	
	format.setForeground(QBrush(Qt::red));
	formats["escape_char"]=format;
	
	format.setForeground(QBrush(Qt::darkBlue));
	formats["macro"]=format;
	
	format.setForeground(QBrush(Qt::darkRed));
	formats["string"]=format;
	
	format.setForeground(QBrush(Qt::black));
	formats["function_name"]=format;

	m_highlighter_header->set_text_formats(formats);
	m_highlighter_source->set_text_formats(formats);
	
	QStringList source_keywords; 
	source_keywords << "ST_CLASS" << "ST_PARAMETER" << "ST_CHILD" << "ST_ALIGN" << "ST_DEFAULT";
	foreach (QString source_keyword,source_keywords)
		m_highlighter_source->addUserKeyword(source_keyword);
	
	m_C=0;
	
	QAction *action_save_changes=new QAction("Save changes to code (Ctrl+U)",this);
	action_save_changes->setShortcut(tr("Ctrl+U"));
	ui.save_changes_button->setDefaultAction(action_save_changes);
	addAction(action_save_changes);
	
	QAction *action_find=new QAction(this);
	action_find->setShortcut(tr("Ctrl+F"));
	addAction(action_find);
	connect(action_find,SIGNAL(triggered()),this,SLOT(slot_find()));
	
	connect(ui.header->editor()->document(),SIGNAL(modificationChanged(bool)),this,SLOT(slot_modification_changed()));
	connect(ui.source->editor()->document(),SIGNAL(modificationChanged(bool)),this,SLOT(slot_modification_changed()));		
	connect(ui.save_changes_button,SIGNAL(clicked()),this,SLOT(slotSaveChanges()));
	connect(ui.reload_button,SIGNAL(clicked()),this,SLOT(slot_reload()));
	connect(action_save_changes,SIGNAL(triggered()),this,SLOT(slotSaveChanges()));
	//connect(ui.actionCompile,SIGNAL(triggered()),this,SIGNAL(signalCompile()));
	
	connect(ui.class_box,SIGNAL(currentIndexChanged(QString)),this,SLOT(slot_class_box_changed(QString)));
	
	
	//ui.actionSaveChanges->setShortcut(tr("Ctrl+S"));
	//ui.actionCompile->setShortcut(tr("F9"));
	
}