예제 #1
0
GdkPixbuf* getPixBuf(char* name)
{
	GFile*				file=g_file_new_for_path(name);
	GFileInfo*			file_info=g_file_query_info(file,"standard::*",G_FILE_QUERY_INFO_NONE,NULL,NULL);
	GIcon*				icon=g_file_info_get_icon(file_info);
	GdkPixbuf*			pix=NULL;
	gchar*				path;
	gchar const* const*	names;
	GFile*				icon_file;
	char*				newname;

	if(G_IS_THEMED_ICON(icon))
		{
			names=g_themed_icon_get_names(G_THEMED_ICON(icon));
			pix=gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),*names,16,(GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SVG|GTK_ICON_LOOKUP_GENERIC_FALLBACK|GTK_ICON_LOOKUP_FORCE_SIZE),NULL);
			if(pix==NULL)
				{
					asprintf(&newname,"gnome-mime-%s",*names);
					pix=gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),(const gchar*)newname,16,(GtkIconLookupFlags)(GTK_ICON_LOOKUP_USE_BUILTIN|GTK_ICON_LOOKUP_FORCE_SVG|GTK_ICON_LOOKUP_GENERIC_FALLBACK|GTK_ICON_LOOKUP_FORCE_SIZE),NULL);
					debugFree(&newname);
				}
		}
	else if(G_IS_FILE_ICON(icon))
		{
			icon_file=g_file_icon_get_file(G_FILE_ICON(icon));
			path=g_file_get_path(icon_file);
			pix=gdk_pixbuf_new_from_file_at_size(path,16,16,NULL);
			debugFree(&path);
			g_object_unref(G_OBJECT(icon_file));
		}
	g_object_unref(G_OBJECT(file));
	g_object_unref(G_OBJECT(file_info));

   return(pix);
}
예제 #2
0
gboolean getNode(GtkTreeModel *model,GtkTreePath *path,GtkTreeIter *iter,gpointer data)
{
	char*	name=NULL;
	char*	thispath=NULL;
	bool	retval=false;

	thispath=gtk_tree_path_to_string(path);
	if(node!=NULL && thispath!=NULL)
		{
			if((strlen(thispath)<strlen(node)) || (strcmp(thispath,node)==0))
				{
					debugFree(&thispath);
					return(false);
				}
		}

	gtk_tree_model_get(model,iter,COLUMN_FILENAME,&name,-1);
	if(name!=NULL)
		{
			if(strcmp(name,(char*)data)==0)
				{
					debugFree(&node);
					node=gtk_tree_path_to_string(path);
					gtk_tree_view_expand_row((GtkTreeView*)treeview,path,false);
					retval=true;
				}
			debugFree(&name);
		}
	debugFree(&thispath);
	return(retval);
}
예제 #3
0
파일: sms.c 프로젝트: agustim/bmx6
static void sms_cleanup( void )
{


        if (extensions_fd > -1) {

                if( extensions_wd > -1) {
                        inotify_rm_watch(extensions_fd, extensions_wd);
                        extensions_wd = -1;
                }

                set_fd_hook(extensions_fd, json_inotify_event_hook, DEL);

                close(extensions_fd);
                extensions_fd = -1;
        } else {
                task_remove(check_for_changed_sms, NULL);
        }

        while (json_sms_tree.items) {
                struct json_sms *sms = avl_first_item(&json_sms_tree);
                avl_remove(&json_sms_tree, sms->name, -300381);
                debugFree(sms, -300382);
        }

}
예제 #4
0
extern "C" void doTabMenu(GtkWidget *widget,gpointer data)
{
	plugData*		plugdata=(plugData*)data;
	pageStruct*		page=plugdata->page;

	char*			ptr=strdup(page->filePath);
	GtkTreeModel*	model=NULL;
	GtkTreePath*	scrollpath;

	gtk_tree_view_collapse_all((GtkTreeView *)treeview);

	ptr=strtok(ptr,"/");

	model=GTK_TREE_MODEL(store);
	gtk_tree_model_foreach(model,getNode,(gpointer)"/");

	while(ptr!=NULL)
		{
			gtk_tree_model_foreach(model,getNode,ptr);
			ptr=strtok(NULL,"/");
		}

	scrollpath=gtk_tree_path_new_from_string(node);
	gtk_tree_view_set_cursor((GtkTreeView *)treeview,scrollpath,NULL,false);
	gtk_tree_view_scroll_to_cell((GtkTreeView *)treeview,scrollpath,NULL,true,0.5,0.5);
	debugFree(&node);
	node=NULL;

	showing=false;
	toggleBrowser(NULL,plugdata);
}
예제 #5
0
void showHideBrowser(plugData* pdata,bool startup)
{
	char*	filepath;

	setTextDomain(true,pdata);
	asprintf(&filepath,"%s/filebrowser.rc",pdata->lPlugFolder);
	if(showing==true)
		{
			gtk_widget_show_all(scrollbox);
			if(pdata->leftShow==0 && startup==false)
				showSide(true);
			touch(filepath);
			gtk_menu_item_set_label((GtkMenuItem*)hideMenu,gettext("Hide Browser"));
		}
	else
		{
			gtk_widget_hide(scrollbox);
			unlink(filepath);
			if(pdata->leftShow==1 && startup==false)
				hideSide(true);
			gtk_menu_item_set_label((GtkMenuItem*)hideMenu,gettext("Show Browser"));
		}
	debugFree(&filepath);
	setTextDomain(false,pdata);
}
예제 #6
0
void collapseRow(GtkTreeView* treeview,GtkTreeIter* iter,GtkTreePath* path,gpointer user_data)
{
	char*	pathstring=gtk_tree_path_to_string(path);

	if(strcmp(pathstring,"0")==0)
		flag=false;
	debugFree(&pathstring);
}
예제 #7
0
파일: topology.c 프로젝트: axn/bmx6
STATIC_FUNC
void destroy_local_topology_cache(void)
{

	struct local_topology_node *ltn;

	while ((ltn = avl_remove_first_item(&local_topology_tree, -300000)))
		debugFree(ltn, -300000);

}
예제 #8
0
void doStartUpCheck(plugData* pdata)
{
	char*	filepath;

	asprintf(&filepath,"%s/filebrowser.rc",pdata->lPlugFolder);
	if(g_file_test(filepath,G_FILE_TEST_EXISTS))
		showing=true;
	else
		showing=false;

	debugFree(&filepath);

	asprintf(&filepath,"%s/filebrowser.inv",pdata->lPlugFolder);
	if(g_file_test(filepath,G_FILE_TEST_EXISTS))
		showInvisible=true;
	else
		showInvisible=false;

	debugFree(&filepath);
}
예제 #9
0
void showHideInvisibles(plugData* pdata)
{
	char*	filepath;

	asprintf(&filepath,"%s/filebrowser.inv",pdata->lPlugFolder);
	if(showInvisible==true)
		touch(filepath);
	else
		unlink(filepath);
	debugFree(&filepath);
}
예제 #10
0
VOID idfrDone(PIDFREQ pIDFreq)
{
  if ( pIDFreq->hmtxList != NULLHANDLE )
  {
    xplMutexDestroy( pIDFreq->hmtxList );
    pIDFreq->hmtxList = NULLHANDLE;
  }

  if ( pIDFreq->paList != NULL )
  {
    debugFree( pIDFreq->paList );
    pIDFreq->paList = NULL;
  }
}
예제 #11
0
void onRowActivated(GtkTreeView* treeview, GtkTreePath* path,GtkTreeViewColumn* col,gpointer userdata)
{
	GtkTreeModel		*model;
	GtkTreeIter			iter;
	gchar				*name;
	char				*command;
	GdkModifierType		mask;
	const char			*app;

#ifdef _USEGTK3_
	GdkDeviceManager	*device_manager=gdk_display_get_device_manager(gdk_display_get_default());
	GdkDevice			*device=gdk_device_manager_get_client_pointer(device_manager);
	GdkWindow			*window;

	window=gdk_screen_get_active_window (gdk_screen_get_default());
	gdk_window_get_device_position(window,device,NULL,NULL,&mask);
#else
	gdk_window_get_pointer(NULL,NULL,NULL,&mask);
#endif

	model=gtk_tree_view_get_model(treeview);

	if(gtk_tree_model_get_iter(model,&iter,path))
		{
			gtk_tree_model_get(model,&iter,COLUMN_PATHNAME,&name,-1);
			app=getApp(name);
			asprintf(&command,"%s '%s'",app,name);
			
			if (GDK_CONTROL_MASK & mask )
				runCommand(command,NULL,false,TOOL_ASYNC,true,NULL);
			else
				runCommand(command,NULL,false,TOOL_ASYNC,false,NULL);
				
			debugFree(&command);
			debugFree(&name);
		}
}
예제 #12
0
extern "C" int doAbout(gpointer data)
{
	plugData*		plugdata=(plugData*)data;
	char*			licencepath;
	const char		copyright[] ="Copyright \xc2\xa9 2014 K.D.Hedger";
	char*			licence;
	GtkAboutDialog*	about;
	char*			translators;

	setTextDomain(true,plugdata);

	const char*		aboutboxstring=gettext("File Browser - Add's a simple file browser to the left pane");

	asprintf(&licencepath,"%s/docs/gpl-3.0.txt",plugdata->dataDir);
	asprintf(&translators,"%s:\nNguyen Thanh Tung <*****@*****.**>",gettext("French Translation"));

	g_file_get_contents(licencepath,&licence,NULL,NULL);
	about=(GtkAboutDialog*)gtk_about_dialog_new();
	gtk_about_dialog_set_program_name(about,gettext("FileBrowser"));
	gtk_about_dialog_set_authors(about,authors);
	gtk_about_dialog_set_comments(about,aboutboxstring);
	gtk_about_dialog_set_copyright(about,copyright);
	gtk_about_dialog_set_version(about,VERSION);
	gtk_about_dialog_set_website(about,MYWEBSITE);
	gtk_about_dialog_set_logo_icon_name(about,"KKEditPlug");
	gtk_about_dialog_set_license(about,licence);
	gtk_about_dialog_set_translator_credits(about,(const gchar*)translators);

	gtk_dialog_run(GTK_DIALOG(about));
	gtk_widget_destroy((GtkWidget*)about);
	debugFree(&licence);
	debugFree(&licencepath);
	free(translators);

	setTextDomain(false,plugdata);
	return(0);
}
예제 #13
0
/* remove bucket (this might be used in hash_iterate() if you already found
 * the bucket you want to delete and don't need the overhead to find it again
 * with hash_remove(). But usually, you don't want to use this function, as it
 * fiddles with hash-internals. */
void *hash_remove_bucket(struct hashtable_t *hash, struct hash_it_t *hash_it_t)
{
	void *data_save;

	/* save the pointer to the data */
	data_save = hash_it_t->bucket->data;

	if (hash_it_t->prev_bucket)
		hash_it_t->prev_bucket->next = hash_it_t->bucket->next;
	else if (hash_it_t->first_bucket)
		(*hash_it_t->first_bucket) = hash_it_t->bucket->next;

	debugFree(hash_it_t->bucket, 1306);

	hash->elements--;
	return data_save;
}
예제 #14
0
/* adds data to the hashtable. returns 0 on success, -1 on error */
int hash_add(struct hashtable_t *hash, void *data)
{
	int ret;
	struct element_t *bucket;

	/* found the tail of the list, add new element */
	bucket = debugMalloc(sizeof(struct element_t), 304);

	if (!bucket)
		return -1;

	ret = hash_add_bucket(hash, data, bucket, 1);
	if (ret < 0)
		debugFree(bucket, 1307);

	return ret;
}
예제 #15
0
VOID cfgDone()
{
  if ( pConfig == NULL )
  {
    debug( "Was not initialized" );
    return;
  }

  rwmtxDone( &rwmtxConfig );

  _cfgFree( pConfig );
  if ( pszCfgFile != NULL )
  {
    debugFree( pszCfgFile );
    pszCfgFile = NULL;
  }
}
예제 #16
0
void *_debugRealloc(void *memoryParameter, uint32_t length, int32_t tag)
{
	
	unsigned char *memory;
	struct chunkHeader *chunkHeader=NULL;
	struct chunkTrailer *chunkTrailer;
	unsigned char *result;
	uint32_t copyLength;

	if (memoryParameter) { /* if memoryParameter==NULL, realloc() should work like malloc() !! */
		memory = memoryParameter;
		chunkHeader = (struct chunkHeader *)(memory - sizeof(struct chunkHeader));

		if (chunkHeader->magicNumber != MAGIC_NUMBER)
		{
			dbgf( DBGL_SYS, DBGT_ERR, 
			     "invalid magic number in header: %08x, malloc tag = %d", 
			     chunkHeader->magicNumber, chunkHeader->tag );
			cleanup_all( -500078 );
		}

		chunkTrailer = (struct chunkTrailer *)(memory + chunkHeader->length);

		if (chunkTrailer->magicNumber != MAGIC_NUMBER)
		{
			dbgf( DBGL_SYS, DBGT_ERR, 
			     "invalid magic number in trailer: %08x, malloc tag = %d", 
			     chunkTrailer->magicNumber, chunkHeader->tag );
			cleanup_all( -500079 );
		}
	}


	result = _debugMalloc(length, tag);
	if (memoryParameter) {
		copyLength = length;

		if (copyLength > chunkHeader->length)
			copyLength = chunkHeader->length;

		memcpy(result, memoryParameter, copyLength);
		debugFree(memoryParameter, -300280);
	}

	return result;
}
예제 #17
0
파일: allocate.c 프로젝트: asriadi/batmand
void *debugRealloc(void *memoryParameter, uint32_t length, int32_t tag)
{
	unsigned char *memory;
	struct chunkHeader *chunkHeader;
	struct chunkTrailer *chunkTrailer;
	unsigned char *result;
	uint32_t copyLength;

	if (memoryParameter) { /* if memoryParameter==NULL, realloc() should work like malloc() !! */
		memory = memoryParameter;
		chunkHeader = (struct chunkHeader *)(memory - sizeof(struct chunkHeader));

		if (chunkHeader->magicNumber != MAGIC_NUMBER)
		{
			fprintf(stderr, "debugRealloc - invalid magic number in header: %08x, malloc tag = %d\n", chunkHeader->magicNumber, chunkHeader->tag);
			exit(1);
		}

		chunkTrailer = (struct chunkTrailer *)(memory + chunkHeader->length);

		if (chunkTrailer->magicNumber != MAGIC_NUMBER)
		{
			fprintf(stderr, "debugRealloc - invalid magic number in trailer: %08x, malloc tag = %d\n", chunkTrailer->magicNumber, chunkHeader->tag);
			exit(1);
		}
	}


	result = debugMalloc(length, tag);
	if (memoryParameter) {
		copyLength = length;

		if (copyLength > chunkHeader->length)
			copyLength = chunkHeader->length;

		memcpy(result, memoryParameter, copyLength);
		debugFree(memoryParameter, 9999);
	}


	return result;
}
예제 #18
0
파일: sms.c 프로젝트: agustim/bmx6
STATIC_FUNC
void json_inotify_event_hook(int fd)
{
        TRACE_FUNCTION_CALL;

        dbgf_track(DBGT_INFO, "detected changes in directory: %s", smsTx_dir);

        assertion(-501278, (fd > -1 && fd == extensions_fd));

        int ilen = 1024;
        char *ibuff = debugMalloc(ilen, -300375);
        int rcvd;
        int processed = 0;

        while ((rcvd = read(fd, ibuff, ilen)) == 0 || rcvd == EINVAL) {

                ibuff = debugRealloc(ibuff, (ilen = ilen * 2), -300376);
                assertion(-501279, (ilen <= (1024 * 16)));
        }

        if (rcvd > 0) {

                while (processed < rcvd) {

                        struct inotify_event *ievent = (struct inotify_event *) &ibuff[processed];

                        processed += (sizeof (struct inotify_event) +ievent->len);

                        if (ievent->mask & (IN_DELETE_SELF)) {
                                dbgf_sys(DBGT_ERR, "directory %s has been removed \n", smsTx_dir);
                                cleanup_all(-501290);
                        }
                }

        } else {
                dbgf_sys(DBGT_ERR, "read()=%d: %s \n", rcvd, strerror(errno));
        }

        debugFree(ibuff, -300377);

        check_for_changed_sms(NULL);
}
예제 #19
0
/* remove the hash structure. if hashdata_free_cb != NULL,
 * this function will be called to remove the elements inside of the hash.
 * if you don't remove the elements, memory might be leaked. */
void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb)
{
	struct element_t *bucket, *last_bucket;
	int i;

	for (i = 0; i < hash->size; i++) {
		bucket = hash->table[i];

		while (bucket) {
			if (free_cb)
				free_cb(bucket->data);

			last_bucket = bucket;
			bucket = bucket->next;
			debugFree(last_bucket, 1301);
		}
	}

	hash_destroy(hash);
}
예제 #20
0
/* allocates and clears the hash */
struct hashtable_t *hash_new(int size, hashdata_compare_cb compare, hashdata_choose_cb choose)
{
	struct hashtable_t *hash;

	hash = debugMalloc(sizeof(struct hashtable_t), 302);
	if (!hash)
		return NULL;

	hash->size= size;
	hash->table= debugMalloc(sizeof(struct element_t *) * size, 303);

	if (!hash->table) {
		debugFree(hash, 1305);
		return NULL;
	}

	hash_init(hash);
	hash->compare = compare;
	hash->choose = choose;
	return hash;
}
예제 #21
0
/* free hash_it_t pointer when stopping hash_iterate early */
void hash_iterate_free(struct hash_it_t *iter_in)
{
	debugFree(iter_in, 1304);
}
예제 #22
0
/* iterate though the hash. first element is selected with iter_in NULL.
 * use the returned iterator to access the elements until hash_it_t returns NULL. */
struct hash_it_t *hash_iterate(struct hashtable_t *hash, struct hash_it_t *iter_in)
{
	struct hash_it_t *iter;

	if (iter_in == NULL) {
		iter = debugMalloc(sizeof(struct hash_it_t), 301);
		iter->index =  -1;
		iter->bucket = NULL;
		iter->prev_bucket = NULL;
	} else
		iter= iter_in;

	/* sanity checks first (if our bucket got deleted in the last iteration): */
	if (iter->bucket != NULL) {
		if (iter->first_bucket != NULL) {

			/* we're on the first element and it got removed after the last iteration. */
			if ((*iter->first_bucket) != iter->bucket) {

				/* there are still other elements in the list */
				if ((*iter->first_bucket) != NULL) {
					iter->prev_bucket = NULL;
					iter->bucket = (*iter->first_bucket);
					iter->first_bucket = &hash->table[iter->index];
					return iter;
				} else {
					iter->bucket = NULL;
				}

			}

		} else if (iter->prev_bucket != NULL) {

			/* we're not on the first element, and the bucket got removed after the last iteration.
			* the last bucket's next pointer is not pointing to our actual bucket anymore.
			* select the next. */
			if (iter->prev_bucket->next != iter->bucket)
				iter->bucket = iter->prev_bucket;

		}

	}

	/* now as we are sane, select the next one if there is some */
	if (iter->bucket != NULL) {
		if (iter->bucket->next != NULL) {
			iter->prev_bucket = iter->bucket;
			iter->bucket = iter->bucket->next;
			iter->first_bucket = NULL;
			return iter;
		}
	}
	/* if not returned yet, we've reached the last one on the index and have to search forward */

	iter->index++;
	/* go through the entries of the hash table */
	while (iter->index < hash->size) {

		if ((hash->table[iter->index]) == NULL) {
			iter->index++;
			continue;
		}

		iter->prev_bucket = NULL;
		iter->bucket = hash->table[iter->index];
		iter->first_bucket = &hash->table[iter->index];
		return iter;	/* if this table entry is not null, return it */
	}

	/* nothing to iterate over anymore */
	debugFree(iter, 1304);
	return NULL;
}
예제 #23
0
void operator delete (void* p) throw()
{
    debugFree(p);
}
예제 #24
0
static PCONFIG _cfgNew(PSZ pszFile)
{
  PCONFIG              pConfig = debugCAlloc( 1, sizeof(CONFIG) );
  xmlDocPtr            pDoc;
  xmlNodePtr           pNode;
  PXMLUSCAN            pScan;
  LONG                 lRC;
  BOOL                 fNoError = TRUE;
  PSZ                  pszAttr;
  ULONG                ulIdx;

  if ( pConfig == NULL )
  {
    debug( "Not enough memory" );
    return NULL;
  }

  // Load XML tree from the file.

  pDoc = xmlReadFile( pszFile, "UTF-8", XML_PARSE_NOERROR+XML_PARSE_NOWARNING );
  if ( pDoc == NULL )
  {
    CHAR               acBuf[512];
    PCHAR              pcBuf =
          &acBuf[ sprintf( &acBuf, "Configuration read error: %s", pszFile ) ];
    xmlErrorPtr        pError = xmlGetLastError();

    if ( pError != NULL )
    {
      if ( pError->line != 0 )
        pcBuf += sprintf( pcBuf, ":%d", pError->line );

      acBuf[sizeof(acBuf) - 1] = '\0';
      pcBuf += _snprintf( pcBuf, sizeof(acBuf) - (pcBuf - &acBuf) - 1, ", %s",
                          pError->message );
      
      while( (pcBuf > &acBuf) && isspace( *(pcBuf - 1) ) ) pcBuf--;
      *pcBuf = '\0';
    }

    logWrite( &acBuf );
    debugFree( pConfig );
    return NULL;
  }

  // Read configuration.

  pNode = xmlDocGetRootElement( pDoc );
  if ( pNode == NULL || ( xmlStrcmp( pNode->name, "config" ) != 0 ) )
  {
    logWrite( "Unknown root node <%s>", pNode->name );
    xmlFreeDoc( pDoc );
    debugFree( pConfig );
    return FALSE;
  }

  pConfig->ulThreads = _CFG_DEF_THREADS;
  pConfig->ulURIBLHits = 1;
  pConfig->ulPipes = _CFG_DEF_PIPES;
  pConfig->ulCommandTimeout = _CFG_DEF_COMMAND_TIMEOUT;
  pConfig->stGreylistMask.s_addr = _CFG_DEF_GLMASK;
  pConfig->ulGreylistCfNum = _CFG_DEF_CFNUM;
  pConfig->ulGreylistCfDen = _CFG_DEF_CFDEN;
  pConfig->ulGreylistCfTTL = _CFG_DEF_CFTTL;
  pConfig->ulMaxMessage    = _CFG_DEF_MAX_MESSAGE;
  pConfig->ulMaxBodyPart   = _CFG_DEF_MAX_BODY_PART;
  lnkseqInit( &pConfig->lsHostListRelays );
  lnkseqInit( &pConfig->lsHostListLocal );
  lnkseqInit( &pConfig->lsHostListIPFreqIgnore );
  lnkseqInit( &pConfig->lsHostListScore );
  lnkseqInit( &pConfig->lsHostListRWLIgnore );
  lnkseqInit( &pConfig->lsHostListMailFrom );
  lnkseqInit( &pConfig->lsHostListEHLO );
  lnkseqInit( &pConfig->lsHostListEHLOURIBLIgnore );
  lnkseqInit( &pConfig->lsHostListGreylistIgnore );
  lnkseqInit( &pConfig->lsHostListDNSBLIgnore );
  lnkseqInit( &pConfig->lsHostListMailFromURIBLIgnore );
  lnkseqInit( &pConfig->lsMailBoxCheckIgnore );
  lnkseqInit( &pConfig->lsHostListSPFIgnore );
  lnkseqInit( &pConfig->lsHostListMsgIdIgnore );
  lnkseqInit( &pConfig->lsHostListMsgId );

  lRC = xmluBeginScan( pNode, &pScan,
          "path-data:pr path-log:pr log-level log-size log-history socket:r "
          "pipe threads weasel-log-pipe name-server:r mail-server-name:r "
          "local-domain:rm spam-store update-header command-timeout uribl:e "
          "command-ataccept:re command-ehlo:re command-rset:re command-mail:re "
          "command-rcpt:re command-data:re command-atcontent:re "
          "command-quit:re" );
  while( lRC >= 0 )
  {
    switch( lRC )
    {
      case 0: // path-data
      case 1: // path-log
        *(lRC == 0 ? &pConfig->pszDataPath : &pConfig->pszLogPath) =
           utilStrNewSZ( pScan->cbValue, pScan->pcValue );
        break;

      case 2: // log-level
        fNoError = utilStrToULong( pScan->cbValue, pScan->pcValue, 0, 5,
                                   &pConfig->ulLogLevel );
        break;

      case 3: // log-size
        fNoError = utilStrToBytes( pScan->cbValue, pScan->pcValue,
                                   &pConfig->ulLogSize );
        break;

      case 4: // log-history
        fNoError = utilStrToULong( pScan->cbValue, pScan->pcValue, 0, 365,
                                   &pConfig->ulLogHistory );
        break;

      case 5: // socket
        if ( pScan->cbValue > 99 )
        {
          fNoError = FALSE;
          break;
        }

        pConfig->pszSocket = utilStrNewSZ( pScan->cbValue, pScan->pcValue );
        break;

      case 6: // pipe
        if ( pScan->cbValue > (_MAX_PATH - 7 /* \PIPE\ and ZERO */) )
        {
          fNoError = FALSE;
          break;
        }

        pConfig->pszPipe = utilStrNewSZ( pScan->cbValue, pScan->pcValue );
        pszAttr = xmlGetNoNsProp( pScan->xmlNode, "number" );
        if ( pszAttr != NULL )
          fNoError = utilStrToULong( strlen( pszAttr ), pszAttr, 1,
                                     _CFG_MAX_PIPES, &pConfig->ulPipes );
        break;

      case 7: // threads
        fNoError = utilStrToULong( pScan->cbValue, pScan->pcValue, 1,
                                   _CFG_MAX_THREADS, &pConfig->ulThreads );
        break;

      case 8: // weasel-log-pipe
        pConfig->fWeaselLogPipe = utilStrWordIndex( _CFG_SW_ON, pScan->cbValue,
                                                    pScan->pcValue ) != -1;
        pConfig->fWeaselLogToScreen = __cfgAttrSwitch( pScan->xmlNode,
                                                       "screen" );
        break;

      case 9: // name-server
        fNoError = utilStrToInAddrPort( pScan->cbValue, pScan->pcValue,
                     &pConfig->stNSAddr, &pConfig->usNSPort, FALSE, 53 );
        break;

      case 10: // mail-server-name
        fNoError = utilVerifyDomainName( pScan->cbValue, pScan->pcValue );
        if ( fNoError )
          pConfig->pszMailServerName = utilStrNewSZ( pScan->cbValue,
                                                     pScan->pcValue );
        break;

      case 11: // local-domain
        fNoError = utilStrAddWords( &pConfig->cbLocalDomains,
                                    &pConfig->pcLocalDomains,
                                    pScan->cbValue, pScan->pcValue,
                                    NULL );
        break;

      case 12: // spam-store
        pConfig->pszSpamStore = utilStrNewSZ( pScan->cbValue, pScan->pcValue );
        pConfig->fSpamTrapStore = __cfgAttrSwitch( pScan->xmlNode, "to-trap" );
        break;

      case 13: // update-header
        pConfig->fUpdateHeader = utilStrWordIndex( _CFG_SW_ON, pScan->cbValue,
                                                   pScan->pcValue ) != -1;
        pszAttr = xmlGetNoNsProp( pScan->xmlNode, "from-local" );
        pConfig->fUpdateHeaderLocal = ( pszAttr != NULL ) &&
          ( utilStrWordIndex( _CFG_SW_ON, strlen( pszAttr ), pszAttr ) != -1 );
        break;

      case 14: // command-timeout
        fNoError = utilStrTimeToSec( pScan->cbValue, pScan->pcValue,
                                     &pConfig->ulCommandTimeout ) &&
                   ( pConfig->ulCommandTimeout >= _CFG_MIN_COMMAND_TIMEOUT ) &&
                   ( pConfig->ulCommandTimeout <= _CFG_MAX_COMMAND_TIMEOUT );
        break;

      case 15: // uribl
        fNoError = __cfgReadURIBL( pConfig, pScan->xmlNode );
        break;

      case 16: // command-ataccept
        fNoError = __cfgReadCmdAtAccept( pConfig, pScan->xmlNode );
        break;

      case 17: // command-ehlo
        fNoError = __cfgReadCmdEHLO( pConfig, pScan->xmlNode );
        break;

      case 18: // command-rset
        fNoError = __cfgReadCmdRSET( pConfig, pScan->xmlNode );
        break;

      case 19: // command-mail
        fNoError = __cfgReadCmdMAIL( pConfig, pScan->xmlNode );
        break;

      case 20: // command-rcpt
        fNoError = __cfgReadCmdRCPT( pConfig, pScan->xmlNode );
        break;

      case 21: // command-data
        fNoError = __cfgReadCmdDATA( pConfig, pScan->xmlNode );
        break;

      case 22: // command-atcontent
        fNoError = __cfgReadCmdAtContent( pConfig, pScan->xmlNode );
        break;

      case 23: // command-quit
        fNoError = __cfgReadCmdQUIT( pConfig, pScan->xmlNode );
        break;
    }

    if ( !fNoError )
    {
      if ( lRC <= 14 )
        xmluScanLog( pScan, "Invalid value." );
      break;
    }

    lRC = xmluScan( pScan );
  }

  xmluEndScan( pScan );
  xmlFreeDoc( pDoc );

  if ( lRC != XMLU_SCAN_END )
  {
    _cfgFree( pConfig );
    return NULL;
  }

  // Check score limmits and TTLs for commands. The score limmit value should
  // not be less than previous one.

  for( ulIdx = 1; ulIdx < ARRAY_SIZE( pConfig->aCmdParam ); ulIdx++ )
  {
    // Default TTL.
    if ( pConfig->aCmdParam[ulIdx].ulTTL == 0 )
      pConfig->aCmdParam[ulIdx].ulTTL = ( 24 * 60 * 60 * 1000 );

    if ( pConfig->aCmdParam[ulIdx].lScoreLimit <
         pConfig->aCmdParam[ulIdx-1].lScoreLimit )
    {
      pConfig->aCmdParam[ulIdx].lScoreLimit =
        pConfig->aCmdParam[ulIdx-1].lScoreLimit;
/*      log( 1, "[WARNING] Set score limit for stage %u to %u",
           ulIdx, pConfig->lStageScoringLimit[ulIdx] );*/
    }
  }

  return pConfig;
}
예제 #25
0
static VOID _cfgFree(PCONFIG pConfig)
{
  ULONG    ulIdx;

  if ( pConfig->pszDataPath != NULL )
    debugFree( pConfig->pszDataPath );

  if ( pConfig->pszLogPath != NULL )
    debugFree( pConfig->pszLogPath );

  if ( pConfig->pszSocket != NULL )
    debugFree( pConfig->pszSocket );

  if ( pConfig->pszPipe != NULL )
    debugFree( pConfig->pszPipe );

  if ( pConfig->pszMailServerName != NULL )
    debugFree( pConfig->pszMailServerName );

  if ( pConfig->pcLocalDomains != NULL )
    debugFree( pConfig->pcLocalDomains );

  if ( pConfig->pszSpamStore != NULL )
    debugFree( pConfig->pszSpamStore );

  if ( pConfig->pcURIBLProviders != NULL )
    debugFree( pConfig->pcURIBLProviders );

  if ( pConfig->pcURIBLNotSpam != NULL )
    debugFree( pConfig->pcURIBLNotSpam );

  lnkseqFree( &pConfig->lsHostListLocal, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListRelays, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListIPFreqIgnore, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListScore, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListRWLIgnore, PHOSTREC, debugFree );

  if ( pConfig->pcRWLProviders != NULL )
    debugFree( pConfig->pcRWLProviders );

  lnkseqFree( &pConfig->lsHostListMailFrom, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListEHLO, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListEHLOURIBLIgnore, PHOSTREC, debugFree );

  if ( pConfig->pcAutoWhitelistIgnoreSenders != NULL )
    debugFree( pConfig->pcAutoWhitelistIgnoreSenders );

  if ( pConfig->pcSpamTrap != NULL )
    debugFree( pConfig->pcSpamTrap );

  if ( pConfig->pcGreylistIgnoreSenders != NULL )
    debugFree( pConfig->pcGreylistIgnoreSenders );

  lnkseqFree( &pConfig->lsHostListGreylistIgnore, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListDNSBLIgnore, PHOSTREC, debugFree );

  if ( pConfig->paDNSBL != NULL )
  {
    PDNSBL   pDNSBL = pConfig->paDNSBL;

    for( ulIdx = 0; ulIdx < pConfig->cDNSBL; ulIdx++, pDNSBL++ )
    {
      if ( pDNSBL->pszName != NULL )
        debugFree( pDNSBL->pszName );

      lnkseqFree( &pDNSBL->lsHostListAnswers, PHOSTREC, debugFree );
    }

    debugFree( pConfig->paDNSBL );
  }

  lnkseqFree( &pConfig->lsHostListMailFromURIBLIgnore, PHOSTREC, debugFree );

  if ( pConfig->pcMailBoxCheckIgnoreSenders != NULL )
    debugFree( pConfig->pcMailBoxCheckIgnoreSenders );

  lnkseqFree( &pConfig->lsMailBoxCheckIgnore, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListSPFIgnore, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListMsgId, PHOSTREC, debugFree );
  lnkseqFree( &pConfig->lsHostListMsgIdIgnore, PHOSTREC, debugFree );

  debugFree( pConfig );
}
예제 #26
0
파일: sms.c 프로젝트: agustim/bmx6
STATIC_FUNC
void check_for_changed_sms(void *unused)
{
        uint16_t found_sms = 0;
        uint16_t matching_sms = 0;

        struct opt_type *opt = get_option( 0, 0, ARG_SMS );
        struct opt_parent *p = NULL;
        struct json_sms * sms = NULL;
        struct avl_node *an = NULL;

        char name[MAX_JSON_SMS_NAME_LEN];
        char data[MAX_JSON_SMS_DATA_LEN + 1];

        dbgf_all(DBGT_INFO, "checking...");

        if (extensions_fd == -1) {
                task_remove(check_for_changed_sms, NULL);
                task_register(SMS_POLLING_INTERVAL, check_for_changed_sms, NULL, 300000);
        }


        while ((sms = avl_iterate_item(&json_sms_tree, &an))) {
                sms->stale = 1;
        }

        while ((p = list_iterate(&opt->d.parents_instance_list, p))) {

                int len = 0;

                memset(name, 0, sizeof (name));
                strcpy(name, p->val);

                int fd = -1;
                char path_name[MAX_PATH_SIZE + 20] = "";
                sprintf(path_name, "%s/%s", smsTx_dir, p->val);



                if ((fd = open(path_name, O_RDONLY, 0)) < 0) {

                        dbgf_all(DBGT_INFO, "could not open %s - %s", path_name, strerror(errno));
                        continue;

                } else if ((len = read(fd, data, sizeof (data))) < 0 || len > MAX_JSON_SMS_DATA_LEN) {

                        dbgf_sys(DBGT_ERR, "sms=%s data_len>=%d MUST BE <=%d bytes! errno: %s",
                                path_name, len, MAX_JSON_SMS_DATA_LEN, strerror(errno));
                        close(fd);
                        continue;

                } else if ((sms = avl_find_item(&json_sms_tree, name)) && sms->text_len == len && !memcmp(sms->text, data, len)) {

                        matching_sms++;
                        sms->stale = 0;
                        close(fd);

                } else {

                        if (sms) {
                                avl_remove(&json_sms_tree, sms->name, -300378);
                                debugFree(sms, -300369);
                        }

                        sms = debugMalloc(sizeof (struct json_sms) +len, -300370);
                        memset(sms, 0, sizeof (struct json_sms) +len);
                        strcpy(sms->name, name);
                        sms->text_len = len;
                        sms->stale = 0;
                        memcpy(sms->text, data, len);
                        avl_insert(&json_sms_tree, sms, -300371);
                        close(fd);

                        dbgf_track(DBGT_INFO, "new sms=%s size=%d! updating description..-", path_name, sms->text_len);
                }

                found_sms++;
        }


        if (found_sms != matching_sms || found_sms != json_sms_tree.items) {

                dbgf_all(DBGT_INFO, "sms found=%d matching=%d items=%d", found_sms, matching_sms, json_sms_tree.items);

                memset(name, 0, sizeof (name));
                while ((sms = avl_next_item(&json_sms_tree, name))) {
                        memcpy(name, sms->name, sizeof (sms->name));
                        if (sms->stale) {
                                dbgf_track(DBGT_INFO, "removed sms=%s/%s size=%d! updating description...",
                                        smsTx_dir, sms->name, sms->text_len);

                                avl_remove(&json_sms_tree, sms->name, -300373);
                                debugFree(sms, -300374);
                        }
                }

                my_description_changed = YES;
        }
}
예제 #27
0
/* free only the hashtable and the hash itself. */
void hash_destroy(struct hashtable_t *hash)
{
	debugFree(hash->table, 1302);
	debugFree(hash, 1303);
}
예제 #28
0
VISIBLE void toggleBookmark(GtkWidget *widget,GtkTextIter *titer)
{
	ERRDATA
	pageStruct		*page=getPageStructByIDFromPage(-1);
	GtkWidget		*menuitem;
	GtkTextMark		*mark;
	GtkTextIter		*iter;
	GtkTextIter		siter;
	int				line;
	GtkTextIter		startprev,endprev;
	char			*previewtext;
	GSList			*mark_list=NULL;
	const gchar		*mark_type;
	GList			*ptr=NULL;
	bookMarksNew	*bookmarkdata;
	char			*correctedpreview;

	if(page==NULL)
		return;
	mark_type=MARK_TYPE_1;
	if(titer==NULL)
		{
			mark=gtk_text_buffer_get_insert((GtkTextBuffer*)page->buffer);
			gtk_text_buffer_get_iter_at_mark((GtkTextBuffer*)page->buffer,&siter,mark);
			gtk_text_iter_set_line_offset(&siter,0);
			iter=(GtkTextIter*)(&siter);
		}
	else
		iter=titer;

	mark_list=gtk_source_buffer_get_source_marks_at_line(page->buffer,gtk_text_iter_get_line(iter),mark_type);
	if(mark_list!=NULL)
		{
			//remove entry from bookmark list
			ptr=newBookMarksList;
			while(ptr!=NULL)
				{
					if((gpointer)((bookMarksNew*)ptr->data)->mark==(gpointer)GTK_TEXT_MARK(mark_list->data))
						{
							ERRDATA debugFree(&((bookMarksNew*)ptr->data)->markName);
							newBookMarksList=g_list_remove(newBookMarksList,ptr->data);
							gtk_text_buffer_delete_mark(GTK_TEXT_BUFFER(page->buffer),GTK_TEXT_MARK(mark_list->data));
							break;
						}
					ptr=g_list_next(ptr);
				}

			/* just take the first and delete it */
//rebuild bookmark menu
			rebuildBookMarkMenu();

			ptr=newBookMarksList;
			while(ptr!=NULL)
				{
					menuitem=gtk_menu_item_new_with_label(((bookMarksNew*)ptr->data)->label);
					gtk_menu_shell_append(GTK_MENU_SHELL(bookMarkSubMenu),menuitem);
					g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(jumpToMark),ptr->data);

					ptr=g_list_next(ptr);
				}
			gtk_widget_show_all(bookMarkMenu);
			g_slist_free(mark_list);
		}
	else
		{
			/* no mark found: create one */
			bookmarkdata=(bookMarksNew*)malloc(sizeof(bookMarksNew));
			newBookMarksList=g_list_append(newBookMarksList,(gpointer)bookmarkdata);
			bookmarkdata->page=page;
			sinkReturn=asprintf(&bookmarkdata->markName,"%s-%i",BOOKMARK_LABEL,bmMarkNumber++);
			bookmarkdata->mark=gtk_source_buffer_create_source_mark(page->buffer,bookmarkdata->markName,mark_type,iter);
			bookmarkdata->pageID=page->pageID;
//preview text for menu
			line=gtk_text_iter_get_line(iter);
			gtk_text_buffer_get_iter_at_line((GtkTextBuffer*)page->buffer,&startprev,line);
			gtk_text_buffer_get_iter_at_line((GtkTextBuffer*)page->buffer,&endprev,line+1);
			previewtext=gtk_text_iter_get_text(&startprev,&endprev);

			previewtext[strlen(previewtext)-1]=0;
			g_strchug(previewtext);
			g_strchomp(previewtext);

			correctedpreview=truncateWithElipses(previewtext,maxBMChars);
			ERRDATA debugFree(&previewtext);
			previewtext=correctedpreview;

			bookmarkdata->label=previewtext;
			bookmarkdata->line=line;
			menuitem=gtk_menu_item_new_with_label(bookmarkdata->label);
			gtk_menu_shell_append(GTK_MENU_SHELL(bookMarkSubMenu),menuitem);
			g_signal_connect(G_OBJECT(menuitem),"activate",G_CALLBACK(jumpToMark),(void*)bookmarkdata);
			gtk_widget_show_all(bookMarkMenu);
		}
}
예제 #29
0
BOOL utilStrAddWords(PULONG pcbText, PCHAR *ppcText,
                     ULONG cbWords, PCHAR pcWords,
                     ULONG (*fnFilter)(ULONG cbWord, PCHAR pcWord) )
{
  ULONG      cbText;
  PCHAR      pcText;
  ULONG      cbWord;
  PCHAR      pcWord;
  ULONG      ulSize = 0;
  BOOL       fSpace;
  ULONG      ulRC;

  // Calculate additional space for the result text.

  cbText = cbWords;
  pcText = pcWords;
  while( TRUE )
  {
    utilStrCutWord( &cbText, &pcText, &cbWord, &pcWord );
    if ( cbWord == 0 )
      break;

    ulSize += cbWord + 1; // +1 - SPACE
  }
  if ( ulSize == 0 )
    return TRUE;
  fSpace = *pcbText != 0;
  if ( !fSpace )
    ulSize--;

  // Allocate memory for the result text.

  ulSize += *pcbText;
  pcText = debugReAlloc( *ppcText, ulSize );
  if ( pcText == NULL )
  {
    debug( "Not enough memory" );
    return FALSE;
  }
  *ppcText = pcText;
  pcText += *pcbText;
  *pcbText = ulSize;
  
  // Adding words to the end of text.

  while( TRUE )
  {
    utilStrCutWord( &cbWords, &pcWords, &cbWord, &pcWord );
    if ( cbWord == 0 )
      break;

    ulRC = ( fnFilter == NULL ) ? 1 : fnFilter( cbWord, pcWord );

    if ( ulRC == 1 )
    {
      if ( fSpace )
      {
        *pcText = ' ';
        pcText++;
      }
      else
        fSpace = TRUE;

      memcpy( pcText, pcWord, cbWord );
      pcText += cbWord;
    }
    else if ( ulRC != 0 )
    {
      if ( ulSize == cbWord )
      {
        fSpace = FALSE;
        ulSize = 0;
      }
      else
        ulSize -= ( cbWord + 1 );
    }
    else
    {
      debugFree( *ppcText );
      *ppcText = NULL;
      *pcbText = 0;
      return FALSE;
    }
  }

  if ( *pcbText != ulSize )
  {
    if ( ulSize == 0 )
    {
      debugFree( *ppcText );
      *ppcText = NULL;
    }
    else
      *ppcText = debugReAlloc( *ppcText, ulSize );
    *pcbText = ulSize;
  }

  return TRUE;
}
예제 #30
0
void destroyBMData(gpointer data)
{
	ERRDATA debugFree(&((bookMarksNew*)data)->markName);
}