Ejemplo n.º 1
0
static 
int sys_main(int *argcp, char **argvp, int (*mainp)(int argc, char **argv))
{
  data_t thread_safe_var = "<<default>>";
  thread_safe_globalp = &thread_safe_var;
  return mainp(*argcp, *argvp);
}
Ejemplo n.º 2
0
int main()
{
    int ch,e;
    while(1)
    {
        system("cls");
        printf("\n\n\t\tASSEMBLER");
        printf("\n\t\t1.Get Object Program Of a Program File");
        printf("\n\t\t2.Text Files");
        printf("\n\t\t3.Exit");
        fflush(stdin);
        printf("\n\t\tEnter Your Choice [1..3]:");
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:e=mainp();
                   if(e==1)
                   {
                       printf("\n Additional files can have Wrong data");
                   }
                   else
                       printf("\nObject Program is stored in Oprogram.txt");
                   getch();
                   break;
            case 2:readmain();
                   break;
            case 3:exit(1);

            default:printf("\n Invalid Input!!");

        }
    }
    return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	_gc = new GlobalConfig;

#ifdef WIN32
	_verbase = false;
	if (argc == 2 && strcmp(argv[1], "/install") == 0) {
		return install_service(argv[0]);
	}
	if (argc == 2 && strcmp(argv[1], "/uninstall") == 0) {
		return uninstall_service(argv[0]);
	}
	if (argc == 2 && strcmp(argv[1], "/debug") == 0) {
		_verbase = true;
	}

//	if (argc == 1)
//		_verbase = true;

#if LICENSE
	int lcs_chk = el_init("zonekey_mcu.lcs");
	if (lcs_chk == -1) {
		fprintf(stderr, "ERR: license check error\n");
		return -1;
	}
	else if (lcs_chk == -2) {
		fprintf(stderr, "ERR: license timeout\n");
		return -2;
	}

	const char *feathers = el_getfeatures();
	KVS fs = parse_feathers(feathers);

	// TODO: 检查是否限制同时启动的数目 ...
	KVS::const_iterator itf = fs.find("cap_max");
	if (itf != fs.end()) {
		_gc->cap_max = atoi(itf->second.c_str());
		if (_gc->cap_max == 0)
			_gc->cap_max = 1;
	}

#endif // 

	HANDLE env = OpenEvent(EVENT_MODIFY_STATE, 0, GLOBAL_NAME);
	if (env) {
		fprintf(stderr, "zonekey_mcu: only one instance running\n");
		CloseHandle(env);
		return -1;
	}
	else {
		env = CreateEvent(0, 0, 0, GLOBAL_NAME);
		_global_obj = env;

		if (!_verbase) {
			SERVICE_TABLE_ENTRY ServiceTable[] = {
				{ SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION)mainp },
				{ 0, 0 },
			};

			// 启动服务的控制分派机线程,这个将直到服务结束后,返回
			StartServiceCtrlDispatcher(ServiceTable);
			return 0;
		}
		else {
			mainp(argc, argv);
			return 0;
		}
	}
#else // 
	// linux
	mainp(argc, argv);
	return 0;
#endif // 
}
Ejemplo n.º 4
0
int main(int args, char* arg[]){
	ILink link; mainp(args, arg, link);

	print(PROJECTNAME, " v.", PROJECTVER[0].ver," (", PROJECTVER[0].date, ").\r\n");

	// Create sertificate: to cert/ folder
	// openssl req -x509 -newkey rsa:2048 -new -days 10000 -keyout cert_key.pem -out cert_cert.pem -nodes -subj "/C=RU/L=Moscow/O=Telegram Bot/OU=Telegram Bot/CN=95.143.221.149"
	// replace ip address to your
	// And run this programs!

	// Test bot token
	GetHttp gp, gp2;
	XDataCont ct;
	XDataPEl el;

	// http request
	gp.Request(HLString() + "https://api.telegram.org/bot" + bot_token + "/getMe");
	// Parse json
	ct.Read(gp.GetData());
	el = ct;

	if(el["ok"] != "true"){
		print("Token error: ", el["description"], "\r\n");
		return -1;
	}

	//{"ok":true,"result":{"id":163124850,"first_name":"LivestreamTestBot","username":"******"}}
	el = el("result");
	print("Token info: id: ", el["id"], ", first_name: ", el["first_name"], ", username: "******"username"], "\r\n");


	// Send my server ip and public key to telegram.
	// http request
	MString cert_key = LoadFile("cert/cert_cert.pem");

	HLString ls;
	TString bnid = md5h(cert_key);
	bnid.Add("--------", bnid);
	gp.AddBoundary(ls, bnid, "url", bot_url);
	gp.AddBoundaryFile(ls, bnid, "certificate", "cert.pem", cert_key);
	gp.AddBoundaryEnd(ls, bnid);
	gp.SetBoundary(bnid, ls.String());

	//gp2.SetBoundary("cert.key", cert_key);
	gp.Request(HLString() + "https://api.telegram.org/bot" + bot_token + "/setWebhook?url=" + bot_url
	+ "&certificate=cert.key");

	// Parse json
	ct.Read(gp.GetData());
	el = ct;

	if(el["ok"] != "true"){
		print("Token error: ", el["description"], "\r\n");
		return -1;
	}

	// Load random text
	TgBotLoadRandomText();

	// Run server
	print("Run server.\r\n");
	LightServerHttp http;
	http.SetPort("88");
	http.Listen();

	return 0;
}