예제 #1
0
파일: main.c 프로젝트: analani/tg
void parse_config_val (config_t *conf, char **s, char *param_name, const char *default_name, const char *path) {
  static char buf[1000]; 
  int l = 0;
  if (prefix) {
    l = strlen (prefix);
    memcpy (buf, prefix, l);
    buf[l ++] = '.';
  }
  *s = 0;
  const char *r = 0;
  strcpy (buf + l, param_name);
  config_lookup_string (conf, buf, &r);
  if (r) {
    if (path && *r != '/') {
      tasprintf (s, "%s/%s", path, r);
    } else {
      *s = tstrdup (r);
    }
  } else {
    if (path && default_name) {
      tasprintf (s, "%s/%s", path, default_name);
    } else {
      *s  = default_name ? tstrdup (default_name) : 0;
    }
  }
}
예제 #2
0
파일: main.c 프로젝트: Telegram-FFOS/tg
void args_parse (int argc, char **argv) {
  int opt = 0;
  while ((opt = getopt (argc, argv, "u:hk:vn:Nc:p:l:RfBL:Es:")) != -1) {
    switch (opt) {
    case 'u':
      set_default_username (optarg);
      break;
    case 'k':
      rsa_public_key_name = tstrdup (optarg);
      break;
    case 'v':
      verbosity ++;
      break;
    case 'N':
      msg_num_mode ++;
      break;
    case 'c':
      config_filename = tstrdup (optarg);
      break;
    case 'p':
      prefix = tstrdup (optarg);
      assert (strlen (prefix) <= 100);
      break;
    case 'l':
      log_level = atoi (optarg);
      break;
    case 'R':
      register_mode = 1;
      break;
    case 'f':
      sync_from_start = 1;
      break;
    case 'B':
      binlog_enabled = 1;
      break;
    case 'L':
      if (log_net_file) { 
        usage ();
      }
      log_net_file = tstrdup (optarg);
      log_net_f = fopen (log_net_file, "a");
      assert (log_net_f);
      break;
    case 'E':
      disable_auto_accept = 1;
      break;
    case 'w':
      allow_weak_random = 1;
      break;
    case 's':
      lua_file = tstrdup (optarg);
      break;
    case 'h':
    default:
      usage ();
      break;
    }
  }
}
예제 #3
0
static int
dotdoozer_parse(job_t *j, htsmsg_t *target)
{
  SHA_CTX ctx;
  uint8_t digest[20];

  const char *buildenv = htsmsg_get_str(target, "buildenv");
  if(buildenv == NULL)
    return 0;

  cfg_root(root);
  const char *source = cfg_get_str(root, CFG("buildenvs", buildenv, "source"),
                                   NULL);
  if(source == NULL) {
    snprintf(j->errmsg, sizeof(j->errmsg), "Don't know about buildenv: %s",
             buildenv);
    return DOOZER_PERMANENT_FAIL;
  }

  // We are going to build in a chroot
  j->projectdir_internal = "/project";

  j->buildenv_source = tstrdup(source);

  // Compute SHA1 of source URL, this is the source ID

  SHA1((void *)source, strlen(source), digest);
  bin2hex(j->buildenv_source_id, sizeof(j->buildenv_source_id),
          digest, sizeof(digest));

  // Compute SHA1 of source URL + all build deps, this is the modified ID

  SHA1_Init(&ctx);
  SHA1_Update(&ctx, source, strlen(source));
  htsmsg_t *builddeps = htsmsg_get_list(target, "builddeps");
  if(builddeps != NULL) {

    htsmsg_field_t *f;

    int count = 0;
    HTSMSG_FOREACH(f, builddeps) {
      if(f->hmf_type != HMF_STR) {
        snprintf(j->errmsg, sizeof(j->errmsg),
                 "Not all builddeps are strings");
        return DOOZER_PERMANENT_FAIL;
      }
      count++;
    }

    j->num_builddeps = count;

    const char **bds = talloc_zalloc(count * sizeof(char *));
    count = 0;
    HTSMSG_FOREACH(f, builddeps) {
      bds[count++] = tstrdup(f->hmf_str);
      SHA1_Update(&ctx, f->hmf_str, strlen(f->hmf_str));
    }
예제 #4
0
void empty_auth_file (void) {
//  alloc_dc (1, tstrdup (test_dc ? TG_SERVER_TEST : TG_SERVER), 443); 
  /* alloc_dc (1, tstrdup (test_dc ? TG_SERVER_TEST : TG_SERVER), 65521); */
  alloc_dc (1, tstrdup (test_dc ? TG_SERVER_TEST : TG_SERVER), 65521);
  dc_working_num = 1;
  auth_state = 0;
  write_auth_file ();
}
예제 #5
0
void SetMenuName (HMENU menu, UINT pos, BOOL bypos, LPCTSTR name) {
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_DATA;
if (!GetMenuItemInfo(menu, pos, bypos, &mii)) return;
if (mii.dwItemData) free((void*)(mii.dwItemData));
mii.dwItemData = name? (ULONG_PTR)tstrdup(name) :NULL;
SetMenuItemInfo(menu, pos, bypos, &mii);
}
예제 #6
0
파일: tmodule.c 프로젝트: Estella/trollbot
/* This function will parse a tconfig "module" block, and attempt
 * to load the module
 */
struct tmodule *tmodule_from_tconfig(struct tconfig_block *tcfg, struct tconfig_block *global_cfg)
{
	lt_dlhandle ltmodule   = NULL;
	struct tmodule *module = NULL;
	int (*tmodule_load)(struct tconfig_block *, struct tconfig_block *);

	if (strcmp(tcfg->key, "module"))
		return NULL;

	/* Search modules directory */
	lt_dlsetsearchpath("modules");

	ltmodule = lt_dlopenext(tcfg->value);

	if (ltmodule == NULL)
	{
		troll_debug(LOG_WARN, "Could not open module \"%s\" (Reason: %s)", tcfg->value, lt_dlerror());
		return NULL;
	}

	troll_debug(LOG_DEBUG, "Loaded module \"%s\"", tcfg->value);

	if ((tmodule_load = lt_dlsym(ltmodule, "tmodule_load")) == NULL)
	{
		troll_debug(LOG_WARN, "Could not find symbol tmodule_load in  module \"%s\"", tcfg->value);
		lt_dlclose(ltmodule);
	} 
	else
	{
		/* We praise our magnificient overlords */
		if (!(*tmodule_load)(tcfg->child, global_cfg))
		{
			troll_debug(LOG_WARN, "Init function for module \"%s\" failed", tcfg->value);
			lt_dlclose(ltmodule);
			return NULL;
		}
	}

	module = tmalloc(sizeof(struct tmodule));

	module->name                    = tstrdup(tcfg->value);
	module->handle                  = ltmodule;

	/* Loading mechanism */
	module->tmodule_load            = lt_dlsym(ltmodule, "tmodule_load"); 
	module->tmodule_unload          = lt_dlsym(ltmodule, "tmodule_unload");

	/* Socket system */
	module->tmodule_get_tsockets    = lt_dlsym(ltmodule, "tmodule_get_tsockets");

	/* Messaging system */
	module->tmodule_get_messages    = lt_dlsym(ltmodule, "tmodule_get_messages");
	module->tmodule_handle_messages = lt_dlsym(ltmodule, "tmodule_handle_messages");

	return module;
}
예제 #7
0
int Notebook::openPage(NotebookPage *np,bool sel) {
	np->tab.index = pages.size();
	pages << np;
	np->page->parent = this;
debug_output("Notebook::openPage(page->create(%s))\n",np->page->getInstance().getName());
	np->page->create(window,0);
	np->page->createAll(0,false);
#ifdef USE_GTK
	GtkWidget *t;
	if((style&NOTEBOOK_CLOSE_BUTTON)) {
		GValue val = { 0 };
		int w,h;
		GtkWidget *bt,*im,*l;

		t = gtk_hbox_new(FALSE,3);
		l = gtk_label_new(np->tab.name);

		bt = gtk_button_new();
		gtk_widget_set_name(bt,"tab-close-button");
		g_value_init(&val,G_TYPE_INT);
		g_value_set_int(&val,GTK_RELIEF_NONE); 
		g_object_set_property(G_OBJECT(bt),"relief",&val);
		g_value_unset(&val);
		im = gtk_image_new_from_stock(GTK_STOCK_CLOSE,GTK_ICON_SIZE_MENU);
		gtk_icon_size_lookup(GTK_ICON_SIZE_MENU,&w,&h);
		gtk_widget_set_size_request(bt,w+2,h+2);
		gtk_container_add(GTK_CONTAINER(bt),im);
		g_signal_connect(G_OBJECT(bt),"clicked",G_CALLBACK(close_tab_callback),(gpointer)&np->tab);
		gtk_box_pack_start(GTK_BOX(t),l,TRUE,TRUE,0);
		gtk_box_pack_start(GTK_BOX(t),bt,FALSE,FALSE,0);

		np->tab.button = bt;
		np->tab.label = l;

		gtk_widget_show_all(t);
	} else {
		t = gtk_label_new(np->tab.name);
	}
	gtk_widget_show_all(t);
	np->page->show();
	gtk_notebook_append_page(GTK_NOTEBOOK(component),(GtkWidget *)np->page->getComponent(),t);
#endif
#ifdef USE_WIN32
	np->status = 1;
//	SetParent((HWND)page->getComponent(),(HWND)parent->getComponent());
debug_output("Notebook::openPage(%s)\n",np->tab.name);
	if(type==WIDGET_NOTEBOOK) {
		TCITEM ti = {TCIF_TEXT};
		ti.pszText = tstrdup(np->tab.name);
		TabCtrl_InsertItem((HWND)component,np->tab.index,&ti);
		tfree(ti.pszText);
	}
#endif
	if(sel) selectPage(np->tab.index);
	return selected;
}
예제 #8
0
파일: main.c 프로젝트: pwrtelegram/tg
char *get_home_directory (void) {
  if (home_directory) { return home_directory; }
  home_directory = getenv("TELEGRAM_HOME");
  if (!str_empty (home_directory)) { return home_directory = tstrdup (home_directory); }
  home_directory = getenv("HOME");
  if (!str_empty (home_directory)) { return home_directory = tstrdup (home_directory); }
  struct passwd *current_passwd;
  uid_t user_id;
  setpwent ();
  user_id = getuid ();
  while ((current_passwd = getpwent ())) {
    if (current_passwd->pw_uid == user_id) {
      home_directory = tstrdup (current_passwd->pw_dir);
      break;
    }
  }
  endpwent ();
  if (str_empty (home_directory)) { home_directory = tstrdup ("."); }
  return home_directory;
}
예제 #9
0
파일: main.c 프로젝트: analani/tg
char *get_home_directory (void) {
  static char *home_directory = NULL;
  if (home_directory != NULL) {
    return home_directory;
  }
  struct passwd *current_passwd;
  uid_t user_id;
  setpwent ();
  user_id = getuid ();
  while ((current_passwd = getpwent ())) {
    if (current_passwd->pw_uid == user_id) {
      home_directory = tstrdup (current_passwd->pw_dir);
      break;
    }
  }
  endpwent ();
  if (home_directory == NULL) {
    home_directory = tstrdup (".");
  }
  return home_directory;
}
예제 #10
0
void NotebookPage::setTabLabel(const char *str) {
	if(tab.name) free(tab.name);
	tab.name = strdup(str);
#ifdef USE_GTK
	gtk_label_set_text(GTK_LABEL(tab.label),str);
#endif
#ifdef USE_WIN32
	TCITEM ti = {TCIF_TEXT};
	ti.pszText = (tchar_t *)tstrdup(str);
	TabCtrl_SetItem((HWND)tab.notebook->getComponent(),tab.index,&ti);
	tfree(ti.pszText);
#endif
}
예제 #11
0
/* This function gets an unparsed line from ICS, and makes it into the http_data struct */
void parse_http_line(struct http_server *http, char *buffer)
{
	struct http_data *data    = NULL;

	data = http_data_new();

	data->txt_packet = tstrdup(buffer);
	data->tokens     = tssv_split(buffer);

	troll_debug(LOG_DEBUG, "%s\n",data->txt_packet);

	http_data_free(data);
}
예제 #12
0
파일: main.c 프로젝트: pwrtelegram/tg
char *get_config_directory (void) {
  char *config_directory;
  config_directory = getenv("TELEGRAM_CONFIG_DIR");
  if (!str_empty (config_directory)) { return tstrdup (config_directory); }
  // XDG: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
  config_directory = getenv("XDG_CONFIG_HOME");
  if (!str_empty (config_directory)) {
    tasprintf (&config_directory, "%s/" PROG_NAME, config_directory);
    // :TODO: someone check whether it could be required to pass tasprintf
    //        a tstrdup()ed config_directory instead; works for me without.
    //        should work b/c this scope's lifespan encompasses tasprintf()
    return config_directory;
  }
  tasprintf (&config_directory, "%s/" CONFIG_DIRECTORY, get_home_directory ());
  return config_directory;
}
예제 #13
0
파일: tgl.c 프로젝트: bbgram/bbgram
void tgl_init (struct tgl_state *TLS) {
  assert (TLS->timer_methods);
  assert (TLS->net_methods);
  if (!TLS->callback.create_print_name) {
    TLS->callback.create_print_name = tgls_default_create_print_name;
  }
  if (!TLS->temp_key_expire_time) {
    TLS->temp_key_expire_time = 100000;
  }

  TLS->message_list.next_use = &TLS->message_list;
  TLS->message_list.prev_use = &TLS->message_list;

  tglmp_on_start (TLS);
  
  if (!TLS->app_id) {
    TLS->app_id = TG_APP_ID;
    TLS->app_hash = tstrdup (TG_APP_HASH);
  }
}
예제 #14
0
파일: loop.c 프로젝트: pwrtelegram/tg
static void one_string_read_end (void) {
  printf ("\n");
  fflush (stdout);

  read_one_string = 0;
  tfree_str (one_string_prompt);
  one_string_prompt = NULL;
  reactivate_readline ();

  one_string_results[one_string_num] = tstrdup (one_string);
  ++one_string_num;

  if (one_string_num < one_string_total_args) {
    do_get_string (TLS);
  } else {
    one_string_cb (TLS, (void *)one_string_results, string_cb_arg);
    int i;
    for (i = 0; i < one_string_total_args; i++) {
      tfree_str (one_string_results[i]);
    }
  }
}
예제 #15
0
파일: tgl.c 프로젝트: bbgram/bbgram
void tgl_set_app_version (struct tgl_state *TLS, const char *app_version) {
  if (TLS->app_version) {
    tfree_str (TLS->app_version);
  }
  TLS->app_version = tstrdup (app_version);
}
예제 #16
0
int http_in(struct http_server *http)
{
	static char         *buffer  = NULL;
	static size_t       size     = BUFFER_SIZE;
	int                 recved   = 0;
	char                *line    = NULL;
	const char          *ptr     = NULL;
	char                *optr    = NULL;
	char                *bufcopy = NULL;


	/* The previous line never existed, or it was completed and
	 * set to NULL upon completion.
	 */
	if (buffer == NULL)
	{
		/* Start with a new zeroed buffer */
		buffer = tmalloc0(BUFFER_SIZE + 1);
		recved = recv(http->sock,buffer,BUFFER_SIZE-1,0);
	} else {
		/* There was a fragment left over, create a larger buffer */
		buffer = tcrealloc0(buffer,
				strlen(buffer) + BUFFER_SIZE + 1,
				&size);

		recved = recv(http->sock,&buffer[strlen(buffer)],BUFFER_SIZE-1,0);

	}

	/* On Errors, or socket close */
	switch (recved)
	{
		case -1:
			free(buffer);
			buffer = NULL;
			return 1;
		case 0:
			http->sock = -1;
			free(buffer);
			buffer = NULL;
			return 0;
	}

	while (strchr(buffer,'\n') != NULL)
	{ /* Complete ICS line */
		line = tmalloc0(strlen(buffer)+1);

		optr = line;

		for(ptr = buffer;*ptr != '\n' && *ptr != '\r';ptr++)
		{
			*optr = *ptr;
			optr++;
		}

		/* This should deal with httpds which output \r only, \r\n, or \n */
		while (*ptr == '\r' || *ptr == '\n')
			ptr++;

		/* Pass the single line for more processing */
		parse_http_line(http,line);

		free(line);
		line = NULL;

		if (strlen(ptr) == 0)
		{
			free(buffer);
			buffer = NULL;
			break;
		}

		bufcopy = tstrdup(ptr);

		free(buffer);

		size   = strlen(bufcopy) + 1;

		buffer = bufcopy;
	}

	return 1;

}
예제 #17
0
/* This is broken
 * Problem: no newlines, or EOL indicator
 * Solutions: Wait until it validates?
 * will work on anything but the beginning and end packet
 * which contain <stream:stream> and </stream:stream>
 * could skip first packet but it won't guarantee that
 * it will get everything in the first packet.
 * different status perhaps.
 */
int xmpp_in(struct xmpp_server *xs)
{

	/* This method is deprecated for XMPP */
	/* Big Ol FIXME */
	return 0;
#ifdef CLOWNS
	static char         *buffer  = NULL;
	static size_t       size     = BUFFER_SIZE;
	int                 recved   = 0;
	char                *line    = NULL;
	const char          *ptr     = NULL;
	char                *optr    = NULL;
	char                *bufcopy = NULL;


	if (buffer == NULL)
	{
		buffer = tmalloc0(BUFFER_SIZE + 1);
		recved = recv(xs->sock,buffer,BUFFER_SIZE-1,0);
	} else {
		/* There was a fragment left over */
		buffer = tcrealloc0(buffer,
				strlen(buffer) + BUFFER_SIZE + 1,
				&size);

		recved = recv(xs->sock,&buffer[strlen(buffer)],BUFFER_SIZE-1,0);

	}


	switch (recved)
	{
		case -1:
			free(buffer);
			buffer = NULL;
			return 1;
		case 0:
			/* Try parsing what's left of the buffer if it has any contents *NON-VALIDATED* */
			if (buffer != NULL)
				parse_xmpp_line(xs,buffer);

			xs->sock = -1;
			free(buffer);
			buffer = NULL;
			return 0;
	}

	/* Check if validates here */
	line = tmalloc0(strlen(buffer)+1);

	optr = line;

	for(ptr = buffer;*ptr != '\0';ptr++)
	{
		*optr = *ptr;
		optr++;
	}

	/* IF VALIDATES */
	if (xs->status == XMPP_CONNECTED)
	{

		parse_xmpp_line(xs,line);
	}

	free(line);
	line = NULL;

	if (strlen(ptr) == 0)
	{
		free(buffer);
		buffer = NULL;
		break;
	}

	bufcopy = tstrdup(ptr);

	free(buffer);

	size   = strlen(bufcopy) + 1;

	buffer = bufcopy;

	return 1;
#endif /* CLOWNS */
}
예제 #18
0
파일: loop.c 프로젝트: pwrtelegram/tg
void generate_prompt (enum tgl_value_type type, int num) {
  switch (type) {
  case tgl_phone_number:
    assert (!num);
    one_string_prompt = tstrdup ("phone number: ");
    one_string_flags = 0;
    return;
  case tgl_code:
    assert (!num);
    one_string_prompt = tstrdup ("code ('CALL' for phone code): ");
    one_string_flags = 0;
    return;
  case tgl_register_info:
    one_string_flags = 0;
    switch (num) {
    case 0:
      one_string_prompt = tstrdup ("register (Y/n): ");
      return;
    case 1:
      one_string_prompt = tstrdup ("first name: ");
      return;
    case 2:
      one_string_prompt = tstrdup ("last name: ");
      return;
    default:
      assert (0);
    }
    return;
  case tgl_new_password:
    one_string_flags = 1;
    switch (num) {
    case 0:
      one_string_prompt = tstrdup ("new password: "******"retype new password: "******"old password: "******"new password: "******"retype new password: "******"password: ");
    return;
  case tgl_bot_hash:
    one_string_flags = 0;
    assert (!num);
    one_string_prompt = bot_hash;
    return;
  default:
    assert (0);
  }
}
예제 #19
0
/* This handles all triggers which have a handler of tcl, or was set that way through
 * a bind in a TCL script. 
 *
 * Rewritten to use the proper way, instead of doing that Tcl_ValEval() garbage.
 */
void tcl_handler(struct network *net, struct trigger *trig, struct irc_data *data, struct dcc_session *dcc, const char *dccbuf)
{
	int ret;
	char *my_arg;
	Tcl_Obj *command;
	Tcl_Obj *nick;
	Tcl_Obj *uhost;
	Tcl_Obj *hand;
	Tcl_Obj *chan;
	Tcl_Obj *arg;
	Tcl_Obj *msg;
	Tcl_Obj *from;
	Tcl_Obj *keyword;
	Tcl_Obj *text;
	Tcl_Obj **objv;

	switch (trig->type)
	{
		case TRIG_PUB: 
			/* The proper way of doing things, according to #tcl on freenode (they'd know) */
			command = Tcl_NewStringObj(trig->command,      strlen(trig->command));
			nick    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			uhost   = Tcl_NewStringObj(data->prefix->host, strlen(data->prefix->host));
			hand    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			chan    = Tcl_NewStringObj(data->c_params[0],  strlen(data->c_params[0]));

			/* We do this because I'm retarded and have no way of figuring out what should happen after the mask */
			my_arg = tstrdup(troll_makearg(data->rest_str,trig->mask));
			arg     = Tcl_NewStringObj(my_arg, strlen(my_arg));

			/* We need to increase the reference count, because if TCL suddenly gets some
			 * time for GC, it will notice a zero reference count
			 */
			Tcl_IncrRefCount(command);
			Tcl_IncrRefCount(nick);
			Tcl_IncrRefCount(uhost);
			Tcl_IncrRefCount(hand);
			Tcl_IncrRefCount(chan);
			Tcl_IncrRefCount(arg);

			/* I don't need a NULL last array element */
			objv = tmalloc(sizeof(Tcl_Obj *) * 6);

			objv[0] = command;
			objv[1] = nick;
			objv[2] = uhost;
			objv[3] = hand;
			objv[4] = chan;
			objv[5] = arg;
	
			/* Call <command> <nick> <uhost> <hand> <chan> <arg> */
			ret = Tcl_EvalObjv(net->tclinterp, 6, objv, TCL_EVAL_GLOBAL);

			/* Decrement the reference count so the GC will catch it */
			Tcl_DecrRefCount(command);
			Tcl_DecrRefCount(nick);
			Tcl_DecrRefCount(uhost);
			Tcl_DecrRefCount(hand);
			Tcl_DecrRefCount(chan);
			Tcl_DecrRefCount(arg);

			/* If we returned an error, send it to trollbot's warning channel */
			if (ret == TCL_ERROR)
			{
				troll_debug(LOG_WARN,"TCL Error: %s\n",Tcl_GetStringResult(net->tclinterp));
			}

			free(my_arg);
			free(objv);

			break;
		case TRIG_PUBM:
			/* The proper way of doing things, according to #tcl on freenode (they'd know) */
			command = Tcl_NewStringObj(trig->command,      strlen(trig->command));
			nick    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			uhost   = Tcl_NewStringObj(data->prefix->host, strlen(data->prefix->host));
			hand    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			chan    = Tcl_NewStringObj(data->c_params[0],  strlen(data->c_params[0]));
			text    = Tcl_NewStringObj(data->rest_str,     strlen(data->rest_str));

			/* We need to increase the reference count, because if TCL suddenly gets some
			 * time for GC, it will notice a zero reference count
			 */
			Tcl_IncrRefCount(command);
			Tcl_IncrRefCount(nick);
			Tcl_IncrRefCount(uhost);
			Tcl_IncrRefCount(hand);
			Tcl_IncrRefCount(chan);
			Tcl_IncrRefCount(text);

			/* I don't need a NULL last array element */
			objv = tmalloc(sizeof(Tcl_Obj *) * 6);

			objv[0] = command;
			objv[1] = nick;
			objv[2] = uhost;
			objv[3] = hand;
			objv[4] = chan;
			objv[5] = text;
	
			/* Call <command> <nick> <uhost> <hand> <chan> <arg> */
			ret = Tcl_EvalObjv(net->tclinterp, 6, objv, TCL_EVAL_GLOBAL);

			/* Decrement the reference count so the GC will catch it */
			Tcl_DecrRefCount(command);
			Tcl_DecrRefCount(nick);
			Tcl_DecrRefCount(uhost);
			Tcl_DecrRefCount(hand);
			Tcl_DecrRefCount(chan);
			Tcl_DecrRefCount(text);

			/* If we returned an error, send it to trollbot's warning channel */
			if (ret == TCL_ERROR)
			{
				troll_debug(LOG_WARN,"TCL Error: %s\n",Tcl_GetStringResult(net->tclinterp));
			}

			free(objv);

			break;
		case TRIG_MSG:
			/* The proper way of doing things, according to #tcl on freenode (they'd know) */
			command = Tcl_NewStringObj(trig->command,      strlen(trig->command));
			nick    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			uhost   = Tcl_NewStringObj(data->prefix->host, strlen(data->prefix->host));
			hand    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));

			/* This is stupid, I don't even remember why the hell I did this */
			my_arg  = ((&data->rest_str[strlen(trig->mask)] == NULL) || &data->rest_str[strlen(trig->mask)+1] == NULL) ? "" : &data->rest_str[strlen(trig->mask)+1];
			text    = Tcl_NewStringObj(my_arg,     strlen(my_arg));

			/* We need to increase the reference count, because if TCL suddenly gets some
			 * time for GC, it will notice a zero reference count
			 */
			Tcl_IncrRefCount(command);
			Tcl_IncrRefCount(nick);
			Tcl_IncrRefCount(uhost);
			Tcl_IncrRefCount(hand);
			Tcl_IncrRefCount(text);

			/* I don't need a NULL last array element */
			objv = tmalloc(sizeof(Tcl_Obj *) * 5);

			objv[0] = command;
			objv[1] = nick;
			objv[2] = uhost;
			objv[3] = hand;
			objv[4] = text;
	
			/* Call <command> <nick> <uhost> <hand> <chan> <arg> */
			ret = Tcl_EvalObjv(net->tclinterp, 5, objv, TCL_EVAL_GLOBAL);

			/* Decrement the reference count so the GC will catch it */
			Tcl_DecrRefCount(command);
			Tcl_DecrRefCount(nick);
			Tcl_DecrRefCount(uhost);
			Tcl_DecrRefCount(hand);
			Tcl_DecrRefCount(text);

			/* If we returned an error, send it to trollbot's warning channel */
			if (ret == TCL_ERROR)
			{
				troll_debug(LOG_WARN,"TCL Error: %s\n",Tcl_GetStringResult(net->tclinterp));
			}

			free(objv);
			break;
		case TRIG_MSGM:
			/* The proper way of doing things, according to #tcl on freenode (they'd know) */
			command = Tcl_NewStringObj(trig->command,      strlen(trig->command));
			nick    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			uhost   = Tcl_NewStringObj(data->prefix->host, strlen(data->prefix->host));
			hand    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));

			/* This is stupid, I don't even remember why the hell I did this */
			text    = Tcl_NewStringObj(data->rest_str,     strlen(data->rest_str));

			/* We need to increase the reference count, because if TCL suddenly gets some
			 * time for GC, it will notice a zero reference count
			 */
			Tcl_IncrRefCount(command);
			Tcl_IncrRefCount(nick);
			Tcl_IncrRefCount(uhost);
			Tcl_IncrRefCount(hand);
			Tcl_IncrRefCount(text);

			/* I don't need a NULL last array element */
			objv = tmalloc(sizeof(Tcl_Obj *) * 5);

			objv[0] = command;
			objv[1] = nick;
			objv[2] = uhost;
			objv[3] = hand;
			objv[4] = text;
	
			/* Call <command> <nick> <uhost> <hand> <chan> <arg> */
			ret = Tcl_EvalObjv(net->tclinterp, 5, objv, TCL_EVAL_GLOBAL);

			/* Decrement the reference count so the GC will catch it */
			Tcl_DecrRefCount(command);
			Tcl_DecrRefCount(nick);
			Tcl_DecrRefCount(uhost);
			Tcl_DecrRefCount(hand);
			Tcl_DecrRefCount(text);

			/* If we returned an error, send it to trollbot's warning channel */
			if (ret == TCL_ERROR)
			{
				troll_debug(LOG_WARN,"TCL Error: %s\n",Tcl_GetStringResult(net->tclinterp));
			}

			free(objv);
			break;
		case TRIG_TOPC:
			/* The proper way of doing things, according to #tcl on freenode (they'd know) */
			command = Tcl_NewStringObj(trig->command,      strlen(trig->command));
			nick    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			uhost   = Tcl_NewStringObj(data->prefix->host, strlen(data->prefix->host));
			hand    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			chan    = Tcl_NewStringObj(data->c_params[0],  strlen(data->c_params[0]));
			text    = Tcl_NewStringObj(data->rest_str,     strlen(data->rest_str));

			/* We need to increase the reference count, because if TCL suddenly gets some
			 * time for GC, it will notice a zero reference count
			 */
			Tcl_IncrRefCount(command);
			Tcl_IncrRefCount(nick);
			Tcl_IncrRefCount(uhost);
			Tcl_IncrRefCount(hand);
			Tcl_IncrRefCount(chan);
			Tcl_IncrRefCount(text);

			/* I don't need a NULL last array element */
			objv = tmalloc(sizeof(Tcl_Obj *) * 6);

			objv[0] = command;
			objv[1] = nick;
			objv[2] = uhost;
			objv[3] = hand;
			objv[4] = chan;
			objv[5] = text;
	
			/* Call <command> <nick> <uhost> <hand> <chan> <arg> */
			ret = Tcl_EvalObjv(net->tclinterp, 6, objv, TCL_EVAL_GLOBAL);

			/* Decrement the reference count so the GC will catch it */
			Tcl_DecrRefCount(command);
			Tcl_DecrRefCount(nick);
			Tcl_DecrRefCount(uhost);
			Tcl_DecrRefCount(hand);
			Tcl_DecrRefCount(chan);
			Tcl_DecrRefCount(text);

			/* If we returned an error, send it to trollbot's warning channel */
			if (ret == TCL_ERROR)
			{
				troll_debug(LOG_WARN,"TCL Error: %s\n",Tcl_GetStringResult(net->tclinterp));
			}

			free(objv);
			break;
		case TRIG_RAW:
			/* The proper way of doing things, according to #tcl on freenode (they'd know) */
			command = Tcl_NewStringObj(trig->command,      strlen(trig->command));
			from    = Tcl_NewStringObj(data->c_params[0],  strlen(data->c_params[0]));
			keyword = Tcl_NewStringObj(trig->command,      strlen(trig->command));
			text    = Tcl_NewStringObj(data->rest_str,     strlen(data->rest_str));

			/* We need to increase the reference count, because if TCL suddenly gets some
			 * time for GC, it will notice a zero reference count
			 */
			Tcl_IncrRefCount(command);
			Tcl_IncrRefCount(from);
			Tcl_IncrRefCount(keyword);
			Tcl_IncrRefCount(text);

			/* I don't need a NULL last array element */
			objv = tmalloc(sizeof(Tcl_Obj *) * 4);

			objv[0] = command;
			objv[1] = from;
			objv[2] = keyword;
			objv[3] = text;
	
			/* Call <command> <nick> <uhost> <hand> <chan> <arg> */
			ret = Tcl_EvalObjv(net->tclinterp, 4, objv, TCL_EVAL_GLOBAL);

			/* Decrement the reference count so the GC will catch it */
			Tcl_DecrRefCount(command);
			Tcl_DecrRefCount(from);
			Tcl_DecrRefCount(keyword);
			Tcl_DecrRefCount(text);

			/* If we returned an error, send it to trollbot's warning channel */
			if (ret == TCL_ERROR)
			{
				troll_debug(LOG_WARN,"TCL Error: %s\n",Tcl_GetStringResult(net->tclinterp));
			}

			free(objv);
			break;
		/* :[email protected] JOIN :#test */
		case TRIG_JOIN:
			/* The proper way of doing things, according to #tcl on freenode (they'd know) */
			command = Tcl_NewStringObj(trig->command,      strlen(trig->command));
			nick    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			uhost   = Tcl_NewStringObj(data->prefix->host, strlen(data->prefix->host));
			hand    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			chan    = Tcl_NewStringObj(data->rest_str,     strlen(data->rest_str));

			/* We need to increase the reference count, because if TCL suddenly gets some
			 * time for GC, it will notice a zero reference count
			 */
			Tcl_IncrRefCount(command);
			Tcl_IncrRefCount(nick);
			Tcl_IncrRefCount(uhost);
			Tcl_IncrRefCount(hand);
			Tcl_IncrRefCount(chan);


			/* I don't need a NULL last array element */
			objv = tmalloc(sizeof(Tcl_Obj *) * 5);

			objv[0] = command;
			objv[1] = nick;
			objv[2] = uhost;
			objv[3] = hand;
			objv[4] = chan;

			/* Call <command> <nick> <uhost> <hand> <chan> <arg> */
			ret = Tcl_EvalObjv(net->tclinterp, 5, objv, TCL_EVAL_GLOBAL);

			/* Decrement the reference count so the GC will catch it */
			Tcl_DecrRefCount(command);
			Tcl_DecrRefCount(nick);
			Tcl_DecrRefCount(uhost);
			Tcl_DecrRefCount(hand);
			Tcl_DecrRefCount(chan);

			/* If we returned an error, send it to trollbot's warning channel */
			if (ret == TCL_ERROR)
			{
				troll_debug(LOG_WARN,"TCL Error: %s\n",Tcl_GetStringResult(net->tclinterp));
			}

			free(objv);
	
			break;
		/* :[email protected] PART #boo :eat my shit */
		case TRIG_PART:
			/* The proper way of doing things, according to #tcl on freenode (they'd know) */
			command = Tcl_NewStringObj(trig->command,      strlen(trig->command));
			nick    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			uhost   = Tcl_NewStringObj(data->prefix->host, strlen(data->prefix->host));
			hand    = Tcl_NewStringObj(data->prefix->nick, strlen(data->prefix->nick));
			chan    = Tcl_NewStringObj(data->c_params[0],  strlen(data->c_params[0]));
			msg     = Tcl_NewStringObj(data->rest_str,     strlen(data->rest_str));


			/* We need to increase the reference count, because if TCL suddenly gets some
			 * time for GC, it will notice a zero reference count
			 */
			Tcl_IncrRefCount(command);
			Tcl_IncrRefCount(nick);
			Tcl_IncrRefCount(uhost);
			Tcl_IncrRefCount(hand);
			Tcl_IncrRefCount(chan);
			Tcl_IncrRefCount(msg);


			/* I don't need a NULL last array element */
			objv = tmalloc(sizeof(Tcl_Obj *) * 6);

			objv[0] = command;
			objv[1] = nick;
			objv[2] = uhost;
			objv[3] = hand;
			objv[4] = chan;
			objv[5] = msg;

			/* Call <command> <nick> <uhost> <hand> <chan> <arg> */
			ret = Tcl_EvalObjv(net->tclinterp, 6, objv, TCL_EVAL_GLOBAL);

			/* Decrement the reference count so the GC will catch it */
			Tcl_DecrRefCount(command);
			Tcl_DecrRefCount(nick);
			Tcl_DecrRefCount(uhost);
			Tcl_DecrRefCount(hand);
			Tcl_DecrRefCount(chan);
			Tcl_DecrRefCount(msg);


			/* If we returned an error, send it to trollbot's warning channel */
			if (ret == TCL_ERROR)
			{
				troll_debug(LOG_WARN,"TCL Error: %s\n",Tcl_GetStringResult(net->tclinterp));
			}

			free(objv);
	
			break;
	}  
}
예제 #20
0
/* This function gets an unparsed line from XMPP, and makes it into the xmpp_data struct */
void parse_xmpp_line(struct xmpp_server *xs, const char *buffer)
{
	struct xmpp_data *data    = NULL;
	struct auth_type *at      = NULL;
	xmlNodePtr        node    = NULL;
	xmlNodePtr        node2   = NULL;
	xmlNodePtr        splnker = NULL;

	data = xmpp_data_new();

	printf("Incoming Packet: %s\n",buffer);
	data->txt_packet = tstrdup(buffer);

	data->xml_packet = xmlReadMemory(buffer, strlen(buffer), "noname.xml", NULL, 0);

	if (data->xml_packet == NULL)
	{
		log_entry_printf(NULL,NULL,"X","Failed to parse XML packet from XMPP");
		return;
	}

	/* Parse out the packet a bit for the one time shit */
	node = xmlDocGetRootElement(data->xml_packet);

	/* Go to the child node pointer */
	if ((node = node->xmlChildrenNode) == NULL)
	{
		log_entry_printf(NULL,NULL,"X","Root element of packet had no children");
		xmpp_data_free(data);
		return;
	}

	/* For all the ugly one time stuff that I'm not going to create a bind type for */
	if (!xmlStrcmp(node->name, (const xmlChar *)"features"))
	{
		/*  features
		 *    starttls/
		 *    mechanisms
		 *      mechanism - DIGEST-MD5
		 *      mechanism - PLAIN
		 *    /mechanisms
		 *  /features
		 */

		if ((node2 = node->xmlChildrenNode) == NULL)
		{
			log_entry_printf(NULL,NULL,"X","features node of XMPP packet had NULL children");
			xmpp_data_free(data);
			return;
		}

		while (node2 != NULL)
		{
			if (!xmlStrcmp(node2->name, (const xmlChar *)"starttls"))
			{
				log_entry_printf(NULL,NULL,"X","Server claims: TLS Supported");
			}
			else if (!xmlStrcmp(node2->name, (const xmlChar *)"register"))
			{
				log_entry_printf(NULL,NULL,"X","Server is requiring us to register");
			}
			else if (!xmlStrcmp(node2->name,(const xmlChar *)"mechanisms"))
			{
				if ((splnker = node2->xmlChildrenNode) == NULL)
				{
					log_entry_printf(NULL,NULL,"X","mechanisms of XMPP packet had NULL children");
					xmpp_data_free(data);
					return;
				}

				while (splnker != NULL)
				{
					if (!xmlStrcmp(splnker->name,(const xmlChar *)"mechanism"))
					{
						at       = new_auth_type();
						at->name = xmlNodeListGetString(data->xml_packet, splnker->xmlChildrenNode, 1);

						log_entry_printf(NULL,NULL,"X","Server accepts algorithm type: %s",at->name);
						/* Add it to the server's list */
						xs->auth_types_remote = auth_type_add(xs->auth_types_remote, at);

						/* Try to get the local algorithm name */
						at->algo_name = auth_type_get_algo_info(at->name);
					}

					splnker = splnker->next;
				}

				log_entry_printf(NULL,NULL,"X","Server Mechanisms complete");
			}

			node2 = node2->next;
		}

		xmpp_printf(xs, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
	}

	xmpp_trigger_match(xs, data);

	xmpp_data_free(data);
}
예제 #21
0
파일: tgl.c 프로젝트: bbgram/bbgram
void tgl_set_download_directory (struct tgl_state *TLS, const char *path) {
  TLS->downloads_directory = tstrdup (path);
}
예제 #22
0
bool cSystemWatcherDrv::HandleEvent(cMessageInfo &msg, cEventInfo &evi)
{
	cEvent event(0, msg.eventHdr->m_ProcessId);
	evi.time = event.GetTime();
	evi.pid = event.m_pid;
	evi.eventType = evtUnknown;
	evi.objectType = objUnknown;
	evi.name = NULL;
	evi.name2 = NULL;
	evi.userId = 0;
	evi.extraData = 0;

	if( msg.eventHdr->m_HookID == FLTTYPE_SYSTEM )
	{
		switch(msg.eventHdr->m_FunctionMj)
		{
		case MJ_CREATE_PROCESS_NOTIFY:
			{
				ULONG Pid = 0;
				PSINGLE_PARAM pParamPid = MKL_GetEventParam(msg.msg, msg.msgSize, _PARAM_OBJECT_SOURCE_ID, FALSE);
				if (pParamPid)
					Pid = *(ULONG*) pParamPid->ParamValue;

				PWCHAR pwchPath = NULL;
				PSINGLE_PARAM pParamUrl = MKL_GetEventParam(msg.msg, msg.msgSize, _PARAM_OBJECT_URL_W, FALSE);
				if (pParamUrl)
					pwchPath = (PWCHAR) pParamUrl->ParamValue;

				PWCHAR pwchFolder = NULL;
				PSINGLE_PARAM pParamFolder = MKL_GetEventParam(msg.msg, msg.msgSize, _PARAM_OBJECT_BASEPATH, FALSE);
				if (pParamFolder)
					pwchFolder = (PWCHAR) pParamFolder->ParamValue;

				PWCHAR pwchCmd = NULL;
				PSINGLE_PARAM pParamCmd = MKL_GetEventParam(msg.msg, msg.msgSize, _PARAM_OBJECT_STARTUP_STR, FALSE);
				if (pParamCmd)
					pwchCmd = (PWCHAR) pParamCmd->ParamValue;

				printf("create process pid %d (parent %d) from '%S'\n", Pid, msg.eventHdr->m_ProcessId, pwchPath);

				if (pwchFolder)
					printf("\tfolder: '%S'\n", pwchFolder);

				if (pwchCmd)
					printf("\tCmdLine: '%S'\n", pwchCmd);

				cFile image_path( &m_envhelper, pwchPath, pwchPath );
				cPath working_folder(&m_envhelper, pwchFolder, pwchFolder);

				evi.eventType = evtProcessStart;
				evi.objectType = objFile;
				evi.extraData = Pid;
				evi.name = tstrdup(image_path.getFull());

				return true;
			}

		case MJ_EXIT_PROCESS:
			{
 				PWCHAR pwchPath = NULL;
 				HRESULT hResult = MKL_GetProcessPath(m_driverContext, msg.msg, &pwchPath);
				
				printf("exit process pid %d, '%S'\n", msg.eventHdr->m_ProcessId, pwchPath);

				cFile image_path(&m_envhelper, pwchPath, pwchPath);

				evi.eventType = evtProcessStop;
				evi.objectType = objFile;
				evi.name = tstrdup(image_path.getFull());

				pfMemFree(NULL, (void**)&pwchPath);
				
				return true;
			}
		}		
	}

	if( msg.eventHdr->m_HookID == FLTTYPE_NFIOR )
	{
		PWCHAR pwchPath = NULL;
		PSINGLE_PARAM pParamUrl = MKL_GetEventParam(msg.msg, msg.msgSize, _PARAM_OBJECT_URL_W, FALSE);
		if (pParamUrl)
			pwchPath = (PWCHAR)pParamUrl->ParamValue;

		if( msg.eventHdr->m_FunctionMj == IRP_MJ_CREATE )
		{
			PSINGLE_PARAM pParamCtx = MKL_GetEventParam(msg.msg, msg.msgSize, _PARAM_OBJECT_CONTEXT_FLAGS, FALSE);
			bool fileCreated = pParamCtx && (*(ULONG *)pParamCtx->ParamValue & _CONTEXT_OBJECT_FLAG_CREATENEWOBJECT);
			if( !fileCreated )
				return false;
			printf("file is created. pid %d, %S\n", msg.eventHdr->m_ProcessId, pwchPath);
			evi.eventType = evtCreate;
		}
		
		if( msg.eventHdr->m_FunctionMj == IRP_MJ_WRITE )
		{
			printf("file is modified. pid %d, %S\n", msg.eventHdr->m_ProcessId, pwchPath);
			evi.eventType = evtModify;
		}

		cFile image_path(&m_envhelper, pwchPath, pwchPath);

		evi.objectType = objFile;
		evi.name = tstrdup(image_path.getFull());
		
		return true;
	}

	return false;
}
예제 #23
0
파일: main.c 프로젝트: pwrtelegram/tg
void args_parse (int argc, char **argv) {
  TLS = tgl_state_alloc ();

  static struct option long_options[] = {
    {"debug-allocator", no_argument, 0,  1000 },
    {"phone", required_argument, 0, 'u'}, 
    {"rsa-key", required_argument, 0, 'k'},
    {"verbosity", no_argument, 0, 'v'},
    {"enable-msg-id", no_argument, 0, 'N'},
#ifdef HAVE_LIBCONFIG
    {"config", required_argument, 0, 'c'},
    {"profile", required_argument, 0, 'p'},
#else
    #if 0
    {"enable-binlog", no_argument, 0, 'B'},
    #endif
#endif
    {"log-level", required_argument, 0, 'l'},
    {"sync-from-start", no_argument, 0, 'f'},
    {"disable-auto-accept", no_argument, 0, 'E'},
    {"allow-weak-random", no_argument, 0, 'w'},
#ifdef USE_LUA
    {"lua-script", required_argument, 0, 's'},
    {"lua-param", required_argument, 0, 'K'},
#endif
    {"wait-dialog-list", no_argument, 0, 'W'},
    {"disable-colors", no_argument, 0, 'C'},
    {"disable-readline", no_argument, 0, 'R'},
    {"alert", no_argument, 0, 'A'},
    {"daemonize", no_argument, 0, 'd'},
    {"logname", required_argument, 0, 'L'},
    {"username", required_argument, 0, 'U'},
    {"groupname", required_argument, 0, 'G'},
    {"disable-output", no_argument, 0, 'D'},
    {"reset-authorization", no_argument, 0, 'q'},
    {"tcp-port", required_argument, 0, 'P'},
    {"unix-socket", required_argument, 0, 'S'},
    {"exec", required_argument, 0, 'e'},
    {"disable-names", no_argument, 0, 'I'},
    {"enable-ipv6", no_argument, 0, '6'},
    {"bot", required_argument, 0, 'b'},
    {"help", no_argument, 0, 'h'},
    {"accept-any-tcp", no_argument, 0,  1001},
    {"disable-link-preview", no_argument, 0, 1002},
    {"json", no_argument, 0, 1003},
    {"python-script", required_argument, 0, 'Z'},
    {"permanent-msg-ids", no_argument, 0, 1004},
    {"permanent-peer-ids", no_argument, 0, 1005},
    {0,         0,                 0,  0 }
  };



  int opt = 0;
  while ((opt = getopt_long (argc, argv, "u:hk:vNl:fEwWCRAdL:DU:G:qP:S:e:I6b"
#ifdef HAVE_LIBCONFIG
  "c:p:"
#else
  #if 0
  "B"
  #endif
#endif
#ifdef USE_LUA
  "s:"
#endif
#ifdef USE_PYTHON
  "Z:"
#endif
  , long_options, NULL
  
  )) != -1) {
    switch (opt) {
    case 'b':
      bot_mode ++;
      bot_hash = optarg;
      break;
    case 1000:
      tgl_allocator = &tgl_allocator_debug;
      break;
    case 1001:
      accept_any_tcp = 1;
      break;
    case 'u':
      set_default_username (optarg);
      break;
    case 'k':
      //rsa_public_key_name = tstrdup (optarg);
      tgl_set_rsa_key (TLS, optarg);
      break;
    case 'v':
      tgl_incr_verbosity (TLS);
      verbosity ++;
      break;
    case 'N':
      msg_num_mode ++;
      break;
#ifdef HAVE_LIBCONFIG
    case 'c':
      config_filename = tstrdup (optarg);
      break;
    case 'p':
      prefix = optarg;
      assert (strlen (prefix) <= 100);
      break;
#else
    #if 0
    case 'B':
      binlog_enabled = 1;
      break;
    #endif
#endif
    case 'l':
      log_level = atoi (optarg);
      break;
    case 'f':
      sync_from_start = 1;
      break;
    case 'E':
      disable_auto_accept = 1;
      break;
    case 'w':
      allow_weak_random = 1;
      break;
#ifdef USE_LUA
    case 's':
      lua_file = strdup (optarg);
      break;
    case 'K':
      lua_param = strdup (optarg);
      break;
#endif
    case 'W':
      wait_dialog_list = 1;
      break;
#ifdef USE_PYTHON
    case 'Z':
      python_file = strdup (optarg);
      break;
#endif
    case 'C':
      disable_colors ++;
      break;
    case 'R':
      readline_disabled ++;
      break;
    case 'A':
      alert_sound = 1;
      break;
    case 'd':
      daemonize ++;
      break;
    case 'L':
      logname = optarg;
      break;
    case 'U':
      set_user_name = optarg;
      break;
    case 'G':
      set_group_name = optarg;
      break;
    case 'D':
      disable_output ++;
      break;
    case 'q':
      reset_authorization ++;
      break;
    case 'P':
      port = atoi (optarg);
      break;
    case 'S':
      unix_socket = optarg;
      break;
    case 'e':
      start_command = optarg;
      break;
    case 'I':
      use_ids ++;
      break;
    case '6':
      ipv6_enabled = 1;
      break;
    case 1002:
      disable_link_preview = 2;
      break;
    case 1003:
      enable_json = 1;
      break;
    case 1004:
      permanent_msg_id_mode = 1;
      break;
    case 1005:
      permanent_peer_id_mode = 1;
      break;
    case 'h':
    default:
      usage ();
      break;
    }
  }
}
예제 #24
0
파일: tgl.c 프로젝트: bbgram/bbgram
void tgl_set_binlog_path (struct tgl_state *TLS, const char *path) {
  TLS->binlog_name = tstrdup (path);
}
예제 #25
0
파일: tgl.c 프로젝트: bbgram/bbgram
void tgl_set_auth_file_path (struct tgl_state *TLS, const char *path) {
  TLS->auth_file = tstrdup (path);
}
예제 #26
0
파일: main.c 프로젝트: analani/tg
void args_parse (int argc, char **argv) {
  int opt = 0;
  while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:DU:G:qP:S:e:"
#ifdef HAVE_LIBCONFIG
  "c:p:"
#else
  "B"
#endif
#ifdef USE_LUA
  "s:"
#endif
  
  )) != -1) {
    switch (opt) {
    case 'u':
      set_default_username (optarg);
      break;
    case 'k':
      //rsa_public_key_name = tstrdup (optarg);
      tgl_set_rsa_key (optarg);
      break;
    case 'v':
      tgl_incr_verbosity ();
      verbosity ++;
      break;
    case 'N':
      msg_num_mode ++;
      break;
#ifdef HAVE_LIBCONFIG
    case 'c':
      config_filename = tstrdup (optarg);
      break;
    case 'p':
      prefix = tstrdup (optarg);
      assert (strlen (prefix) <= 100);
      break;
#else
    case 'B':
      binlog_enabled = 1;
      break;
#endif
    case 'l':
      log_level = atoi (optarg);
      break;
    case 'f':
      sync_from_start = 1;
      break;
    case 'E':
      disable_auto_accept = 1;
      break;
    case 'w':
      allow_weak_random = 1;
      break;
#ifdef USE_LUA
    case 's':
      lua_file = strdup (optarg);
      break;
#endif
    case 'W':
      wait_dialog_list = 1;
      break;
    case 'C':
      disable_colors ++;
      break;
    case 'R':
      readline_disabled ++;
      break;
    case 'd':
      daemonize ++;
      break;
    case 'L':
      logname = optarg;
      break;
    case 'U':
      set_user_name = optarg;
      break;
    case 'G':
      set_group_name = optarg;
      break;
    case 'D':
      disable_output ++;
      break;
    case 'q':
      reset_authorization ++;
      break;
    case 'P':
      port = atoi (optarg);
      break;
    case 'S':
      unix_socket = optarg;
      break;
    case 'e':
      start_command = optarg;
      break;
    case 'h':
    default:
      usage ();
      break;
    }
  }
}
예제 #27
0
파일: tgl.c 프로젝트: bbgram/bbgram
void tgl_set_rsa_key (struct tgl_state *TLS, const char *key) {
  assert (TLS->rsa_key_num < TGL_MAX_RSA_KEYS_NUM);
  TLS->rsa_key_list[TLS->rsa_key_num ++] = tstrdup (key);
}
예제 #28
0
파일: main.c 프로젝트: analani/tg
void set_default_username (const char *s) {
  if (default_username) { 
    tfree_str (default_username);
  }
  default_username = tstrdup (s);
}
예제 #29
0
파일: tgl.c 프로젝트: bbgram/bbgram
void tgl_register_app_id (struct tgl_state *TLS, int app_id, char *app_hash) {
  TLS->app_id = app_id;
  TLS->app_hash = tstrdup (app_hash);
}
예제 #30
0
파일: tconfig.c 프로젝트: Estella/trollbot
/* Modifies dst, but never the actual dst pointer */
void tconfig_merge(struct tconfig_block *src, struct tconfig_block *dst)
{
  struct tconfig_block *tmp;
  int depth      = 0;

  /* We want to start at the initial positions and traverse down from 
   * there, copying the keys and values and subkeys maintaining current
   * order if it already exists.
   */
  if (src == NULL || dst == NULL)
    return;

  while (src != NULL)
  {      
    if (src->child != NULL)
    {
      /* Do wildcards recursively, I only figure it will
       * get a few levels in depth
       */
      if ((src->value != NULL) && !strcmp(src->value,"*"))
      {
        /* The trick is to loop through the current depth
         * matching the key to the wildcard's key, if so,
         * and call this function after going to child of each
         * making them both in the toplevel during the merge
         */
        tmp = dst;

        while (tmp->prev != NULL) tmp = tmp->prev;
        
        while (tmp != NULL)
        {
          if (tmp->key != NULL)
          {
            if (!strcmp(src->key,tmp->key))
            {
              if (tmp->child == NULL)
              {
                tmp->child         = tmalloc(sizeof(struct tconfig_block));
                tmp->child->parent = tmp;
                tmp                = tmp->child;
                tmp->key           = NULL;
                tmp->value         = NULL;
                tmp->prev          = NULL;
                tmp->next          = NULL;
                tmp->child         = NULL;
                tmp                = tmp->parent; /* Return back to the parent */
              } 

              tconfig_merge(src->child,tmp->child);

            }

          }
 
          tmp = tmp->next;
        } 

        src = src->next;
        continue;
      }

      tmp = dst;

      /* Make sure it's at the beginning */
      while (tmp->prev != NULL) tmp = tmp->prev;

      while (tmp != NULL)
      {
        if (tmp->key != NULL)
        {
          if (!strcmp(src->key,tmp->key) && !strcmp(src->value,tmp->value))
          {
            /* It's a match, merely attach to it */
            dst = tmp->child;
            break;
          }
        }

        tmp = tmp->next;
      }

      if (tmp == NULL)
      {
        /* No matches, create they key/value parent node */
        while (dst->next != NULL && dst->key != NULL) dst = dst->next;
        
        if (dst->key != NULL)
        {
          dst->next = tmalloc(sizeof(struct tconfig_block));
        
          dst->next->prev    = dst; 
          dst->next->next    = NULL;
          dst                = dst->next;
        }
       
        dst->key           = tstrdup(src->key);
        dst->value         = tstrdup(src->value);
        dst->parent        = NULL;

        dst->child         = tmalloc(sizeof(struct tconfig_block));
        dst->child->parent = dst;
        dst                = dst->child;
        
        dst->key           = NULL;
        dst->value         = NULL;
        dst->child         = NULL;
        dst->prev          = NULL;
        dst->next          = NULL;
      } 

      depth++;

      src = src->child;
      continue;
    }

    tmp = dst;

    /* Make sure it's at the beginning */
    while (tmp->prev != NULL) tmp = tmp->prev;

    while (tmp != NULL)
    {
      if (tmp->key != NULL)
      {
        /* No Duplicate keys on merge unless prepended with @ */
        if (!strcmp(src->key,tmp->key) && src->key[0] != '@')
        {
          /* Ignore dupes */
          break;
        }
      }

      tmp = tmp->next;
    }

    if (tmp == NULL)
    {
      /* go to the end of the list */
      while (dst->next != NULL && dst->key != NULL) dst = dst->next;

      if (dst->key != NULL)
      {
        dst->next       = tmalloc(sizeof(struct tconfig_block));
        dst->next->prev = dst;
        dst             = dst->next;
        dst->next       = NULL;
        dst->parent     = NULL;
        dst->child      = NULL;
      }

      if (src->key[0] == '@')
        dst->key      = tstrdup(&src->key[1]);
      else
        dst->key      = tstrdup(src->key);

      dst->value      = tstrdup(src->value);
      dst->next       = NULL;
    }

    while (src->next == NULL)
    {
      if (depth == 0)
        return;

      while (src->prev != NULL) src = src->prev;
      
      /* Do the same to dst */
      while (dst->prev != NULL) dst = dst->prev;      

      src = src->parent;
      dst = dst->parent;

      depth--; 
    }
     
    src = src->next;
  }

  
}