Exemple #1
0
/* ARGSUSED */
INTERNAL DBfile *
db_debug_create(char const *name, int mode, int target, int subtype, char const *finfo)
{

    char          *me = "db_debug_create";
    DBfile_debug  *dbfile;

    if (NULL == (dbfile = ALLOC(DBfile_debug))) {
        db_perror(name, E_NOMEM, me);
        return NULL;
    }
    if (STR_EQUAL(name, "stdout")) {
        dbfile->file = stdout;
    }
    else if (STR_EQUAL(name, "stderr")) {
        dbfile->file = stderr;
    }
    else if (NULL == (dbfile->file = fopen(name, "w"))) {
        db_perror(name, E_NOFILE, me);
        FREE(dbfile);
        return NULL;
    }
    fprintf(dbfile->file, "Opened %s: %s\n", name, finfo);

    dbfile->pub.name = STRDUP(name);
    dbfile->pub.type = DB_DEBUG;

    dbfile->pub.close = db_debug_close;
    dbfile->pub.g_ca = db_debug_GetCompoundarray;
    dbfile->pub.p_ca = db_debug_PutCompoundarray;
    dbfile->pub.module = db_debug_Filters;

    return (DBfile *) dbfile;
}
static bool properties_to_info(DBusMessage* properties, SynceInfo* info)
{
  DBusMessageIter iter;
  DBusMessageIter iter_dict;

  dbus_message_iter_init(properties, &iter);

  for (dbus_message_iter_init_dict_iterator(&iter, &iter_dict);
      ;
      dbus_message_iter_next(&iter_dict))
  {
    char* str_value = NULL;
    char* key      = dbus_message_iter_get_dict_key(&iter_dict);
    int   type     = dbus_message_iter_get_arg_type(&iter_dict);
    int   int_value;

    synce_debug("Key = %s", key);

    if (!key)
      continue;

    switch (type)
    {
      case DBUS_TYPE_STRING:
        str_value = dbus_message_iter_get_string(&iter_dict);

        if (STR_EQUAL(key, "address"))
          info->ip = STRDUP(str_value);
        else if (STR_EQUAL(key, "password"))
          info->password = STRDUP(str_value);

        /* TODO: handle more string properties */

        dbus_free(str_value);
        break;

      case DBUS_TYPE_INT32:
        int_value = dbus_message_iter_get_int32(&iter_dict);

        if (STR_EQUAL(key, "key"))
          info->key = int_value;

        /* TODO: handle more int32 properties */

        break;
    }

    dbus_free(key);

    if (!dbus_message_iter_has_next(&iter_dict))
      break;
  }

  /* Fake dccm PID! */
  info->dccm_pid = getpid();

  return info->ip != NULL;
}
Exemple #3
0
/*ARGSUSED*/
static Boolean 
XawCommandSetValues(Widget current, Widget request, Widget cnew,
		    ArgList args, Cardinal *num_args)
{
    CommandWidget oldcbw = (CommandWidget)current;
    CommandWidget cbw = (CommandWidget)cnew;
    Boolean redisplay = False;

    if (oldcbw->core.sensitive != cbw->core.sensitive && !cbw->core.sensitive) {
	cbw->command.highlighted = HighlightNone;
	redisplay = True;
    }

    if (cbw->command.set) {
	unsigned int i;
	Pixel foreground, background;

	foreground = oldcbw->label.foreground;
	background = oldcbw->core.background_pixel;
	for (i = 0; i < *num_args; i++) {
	    if (STR_EQUAL(args[i].name, XtNforeground))
		background = cbw->label.foreground;
	    else if (STR_EQUAL(args[i].name, XtNbackground))
		foreground = cbw->core.background_pixel;
	}
	cbw->label.foreground = foreground;
	cbw->core.background_pixel = background;
    }

    if (oldcbw->label.foreground != cbw->label.foreground
	|| oldcbw->core.background_pixel != cbw->core.background_pixel
	|| oldcbw->command.highlight_thickness
	!= cbw->command.highlight_thickness
	|| oldcbw->label.font != cbw->label.font) {
	XtReleaseGC(cnew, cbw->command.inverse_GC);

	cbw->command.normal_GC = Get_GC(cbw, cbw->label.foreground, 
					cbw->core.background_pixel);
	cbw->command.inverse_GC = Get_GC(cbw, cbw->core.background_pixel, 
					 cbw->label.foreground);
	XtReleaseGC(cnew, cbw->label.normal_GC);
	cbw->label.normal_GC = cbw->command.normal_GC;

	redisplay = True;
    }

    if (XtIsRealized(cnew)
	&& oldcbw->command.shape_style != cbw->command.shape_style
	&& !ShapeButton(cbw, True))
	cbw->command.shape_style = oldcbw->command.shape_style;

    return (redisplay);
}
/* Read parameters --------------------------------------------------------- */
void ProgAngularProjectLibrary::readParams()
{
    input_volume = getParam("-i");
    output_file = getParam("-o");
    output_file_root = output_file.withoutExtension();
    fn_sym = getParam("--sym");
    fn_sym_neigh=checkParam("--sym_neigh")?getParam("--sym_neigh"):fn_sym;
    sampling = getDoubleParam("--sampling_rate");
    psi_sampling = getDoubleParam("--psi_sampling");
    max_tilt_angle = getDoubleParam("--max_tilt_angle");
    min_tilt_angle = getDoubleParam("--min_tilt_angle");
    angular_distance_bool = checkParam("--angular_distance");
    angular_distance=0.;
    if(angular_distance_bool)
    {
        FnexperimentalImages = getParam("--experimental_images");
        angular_distance = getDoubleParam("--angular_distance");
    }
    compute_closer_sampling_point_bool= checkParam("--closer_sampling_points");
    if(compute_closer_sampling_point_bool)
        FnexperimentalImages = getParam("--experimental_images");
    if (STR_EQUAL(getParam("--method"), "real_space"))
        projType = REALSPACE;
    if (STR_EQUAL(getParam("--method"), "shears"))
        projType = SHEARS;
    if (STR_EQUAL(getParam("--method"), "fourier"))
    {
        projType = FOURIER;
        paddFactor = getDoubleParam("--method", 1);
        maxFrequency = getDoubleParam("--method", 2);
        String degree = getParam("--method", 3);
        if (degree == "nearest")
            BSplineDeg = NEAREST;
        else if (degree == "linear")
            BSplineDeg = LINEAR;
        else if (degree == "bspline")
            BSplineDeg = BSPLINE3;
        else
            REPORT_ERROR(ERR_ARG_BADCMDLINE, "The interpolation kernel can be : nearest, linear, bspline");
    }

    //NOTE perturb in computed after the even sampling is computes
    //     and max tilt min tilt applied
    perturb_projection_vector=getDoubleParam("--perturb");
    compute_neighbors_bool=checkParam("--compute_neighbors");
    remove_points_far_away_from_experimental_data_bool=checkParam("--near_exp_data");
    if(remove_points_far_away_from_experimental_data_bool)
        FnexperimentalImages = getParam("--experimental_images");
    fn_groups = getParam("--groups");
    only_winner = checkParam("--only_winner");
}
Exemple #5
0
static void
XawCommandGetValuesHook(Widget w, ArgList args, Cardinal *num_args)
{
    CommandWidget cbw = (CommandWidget)w;
    unsigned int i;

    for (i = 0; i < *num_args; i++) {
	if (STR_EQUAL(args[i].name, XtNforeground))
	    *((String*)args[i].value) = cbw->command.set ?
		(String)cbw->core.background_pixel : (String)cbw->label.foreground;
	else if (STR_EQUAL(args[i].name, XtNbackground))
	    *((String*)args[i].value) = cbw->command.set ?
		(String)cbw->label.foreground : (String)cbw->core.background_pixel;
    }
}
Exemple #6
0
static void recurrence_set_days_of_week_mask(
    RRA_RecurrencePattern* pattern, 
    RRule* rrule)
{
  int i, j;
  char** days = strsplit(rrule->byday, ',');

  if (days)
  {
    for (i = 0; i < 7; i ++)
      for (j = 0; days[j]; j++)
      {
        if (STR_EQUAL(masks_and_names[i].name, days[j]))
          pattern->days_of_week_mask |= masks_and_names[i].mask;
      }

    strv_free(days);
  }

  if (pattern->days_of_week_mask == 0)
  {
    /* get day from start date */
    struct tm start_date = rra_minutes_to_struct(pattern->pattern_start_date);
    synce_warning("BYDAY is missing or empty, assumimg BYDAY=%s", masks_and_names[start_date.tm_wday].name);
    pattern->days_of_week_mask = masks_and_names[start_date.tm_wday].mask;
  }
}
    bool hasName(const char* aName) const
    {
        if (name == 0)
            return false;

        return STR_EQUAL(name, aName);
    }
Exemple #8
0
// Read arguments ==========================================================
void ProgXrayImport::readParams()
{

    if (checkParam("--mistral"))
    {
        fnInput = getParam("--mistral");
        fnFlat = "NXtomo/instrument/bright_field/data@" + fnInput;
        dSource = MISTRAL;
    }
    else if (checkParam("--bessy"))
    {
        fnInput = getParam("--bessy", 0);
        tIni = getIntParam("--bessy", 1);
        tEnd = getIntParam("--bessy", 2);
        fIni = getIntParam("--bessy", 3);
        fEnd = getIntParam("--bessy", 4);
        fnFlat = fnInput;
        dSource = BESSY;
    }
    else
    {
        fnInput = getParam("--input");
        dSource = GENERIC;
    }
    // If --flat is passed it forces the use of this flatfield
    if (checkParam("--flat"))
    {
        fnFlat = getParam("--flat");
        extFlat = true;
    }

    fnRoot    = getParam("--oroot");
    cropSizeX  = getIntParam("--crop");

    if ( STR_EQUAL(getParam("--crop", 1), "sizeX") )
        cropSizeY = cropSizeX;
    else
        cropSizeY = getIntParam("--crop",1);


    thrNum    = getIntParam("--thr");

    String tempString = getParam("--bad_pixels");
    if (tempString == "factor")
        BPFactor = getDoubleParam("--bad_pixels", 1);
    else if (tempString == "mask")
        fnBPMask  = getParam("--bad_pixels",1);
    else
        BPFactor = -1;

    selfAttFix   = checkParam("--correct");
    logFix   = (selfAttFix)? true : checkParam("--log");
}
Exemple #9
0
/*--------------------------------------------------------------------
 *  Routine                                             silo_GetAttEnt
 *
 *  Purpose
 *
 *      Return table entry for requested attribute.
 *--------------------------------------------------------------------
 */
INTERNAL AttEnt *
silo_GetAttEnt(int sid, int dirid, int varid, char *name)
{
    int            i;

    for (i = 0; i < attTable[sid]->num_used; i++) {

        if (attTable[sid]->ent[i]->parent == dirid &&
            attTable[sid]->ent[i]->varid == varid &&
            STR_EQUAL(attTable[sid]->ent[i]->name, name)) {

            return (attTable[sid]->ent[i]);
        }
    }

    return (NULL);
}
Exemple #10
0
/*--------------------------------------------------------------------
 *  Routine                                           silo_GetObjId
 *
 *  Purpose
 *
 *      Return relative ID of object in given directory.
 *--------------------------------------------------------------------*/
INTERNAL int
silo_GetObjId(int sid, int dirid, char const *name)
{
    int            i, relid = -1;

    for (i = 0; i < objTable[sid]->num_used; i++) {

        if (objTable[sid]->ent[i]->parent == dirid &&
            STR_EQUAL(objTable[sid]->ent[i]->name, name)) {

            relid = objTable[sid]->ent[i]->relid;
            break;
        }
    }

    return (relid);
}
Exemple #11
0
/*--------------------------------------------------------------------
 *  Routine                                           silo_GetDirid
 *
 *  Purpose
 *
 *      Return ID of directory in given directory.
 *--------------------------------------------------------------------*/
INTERNAL int
silo_GetDirId(int sid, int dirid, char *name)
{
    int            i, id = -1;

    for (i = 0; i < dirTable[sid]->num_used; i++) {

        if (dirTable[sid]->ent[i]->parent == dirid &&
            STR_EQUAL(dirTable[sid]->ent[i]->name, name)) {

            id = dirTable[sid]->ent[i]->absid;
            break;
        }
    }

    return (id);
}
Exemple #12
0
int main(int argc, char **argv)
{
	char *iname = NULL;

	if (argc == 1)
		return show_help(argv[0]);
	if (STR_EQUAL(argv[1], "--help") || STR_EQUAL(argv[1], "-?"))
		return show_help(argv[0]);
	if (STR_EQUAL(argv[1], "--version") || STR_EQUAL(argv[1], "-V"))
		return show_version();
	if (STR_EQUAL(argv[1], "--usage"))
		return show_usage(argv[0]);
	if (STR_EQUAL(argv[1], "-i")) {
		if (argc == 2) {
			log_err("-i requires a string as argument.");
			return -EINVAL;
		}
		iname = argv[2];
		argc -= 2;
		argv += 2;
	}

	return handle(iname, argc - 1, argv + 1);
}
Exemple #13
0
/*----------------------------------------------------------------------
 *  Routine                                                 SO_GetObject
 *
 *  Purpose
 *
 *      Read the contents of an object, one entity at a time, and store
 *      each entity into the given structure.
 *
 *  Programmer
 *
 *      Jeffery W. Long, NSSD-B
 *
 *  Notes
 *
 *  Modifications
 *      Al Leibee, Thu Oct 21 15:34:21 PDT 1993
 *      Add datatype arg to SO_ReadComponent to coerce variable from
 *      datatype in file to datatype in memory.
 *
 *--------------------------------------------------------------------*/
INTERNAL int
SO_GetObject(int sid, int objid, SO_Object *tobj)
{
    int            i, j;
    int            type, ncomps, error;
    int            compids[50], comptypes[50], comppars[50];
    char          *s, *name, compnames[512];
    char           delim[2];
    int          **ipp;
    long         **lpp;
    float        **fpp;
    double       **dpp;
    char         **cpp;

    /* Determine number of components in object */
    silonetcdf_ncobjinq(sid, objid, NULL, &type, &ncomps);

    /* Read object */
    error = silonetcdf_ncobjget(sid, objid, compnames, compids, comptypes, comppars);
    if (error)
        return (-1);

    delim[0] = compnames[0];
    delim[1] = '\0';

    /* Parse object names and build structure */
    s = &compnames[1];
    name = (char *)strtok(s, delim);

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

        for (j = 0; j < tobj->num; j++) {

            if (tobj->ptr[j] != NULL &&
                    STR_EQUAL(name, tobj->name[j])) {

                switch (tobj->alloced[j]) {

                case TRUE: /* Read directly into space provided */

                    /*-----------------------------------------------------
                     *  Special case for scalar integer: if component
                     *  is of type literal, use component ID as a literal.
                     *----------------------------------------------------*/

                    if (tobj->type[j] == DB_INT &&
                            comptypes[i] == SILO_TYPE_LIT) {

                        *((int *)tobj->ptr[j]) = compids[i];

                    }
                    else {

                        SO_ReadComponent(sid, compids[i], comptypes[i],
                                         comppars[i], tobj->type[j],
                                         tobj->ptr[j]);

                    }
                    break;

                case FALSE:  /* Space not allocated yet, do it. */

                    switch (tobj->type[j]) {
                    case DB_INT:
                        ipp = (int **)tobj->ptr[j];
                        *ipp = (int *)SO_GetComponent(sid, compids[i],
                                                      comptypes[i],
                                                      comppars[i]);
                        break;

                    case DB_LONG:
                        lpp = (long **)tobj->ptr[j];
                        *lpp = (long *)SO_GetComponent(sid, compids[i],
                                                       comptypes[i],
                                                       comppars[i]);
                        break;

                    case DB_FLOAT:
                        fpp = (float **)tobj->ptr[j];
                        *fpp = (float *)SO_GetComponent(sid, compids[i],
                                                        comptypes[i],
                                                        comppars[i]);
                        break;

                    case DB_DOUBLE:
                        dpp = (double **)tobj->ptr[j];
                        *dpp = (double *)SO_GetComponent(sid, compids[i],
                                                         comptypes[i],
                                                         comppars[i]);
                        break;

                    case DB_CHAR:
                    case DB_NOTYPE:
                        cpp = (char **)tobj->ptr[j];
                        *cpp = (char *)SO_GetComponent(sid, compids[i],
                                                       comptypes[i],
                                                       comppars[i]);
                        break;

                    default:
                        break;
                    }
                    break;

                default:
                    break;
                }

                /*
                 *  If force-single is on, must change datatype
                 *  field to 'float'.
                 */
                if (_so_force_single && STR_EQUAL("datatype", name))
                    *((int *)tobj->ptr[j]) = DB_FLOAT;

            }
        }                       /* for-j */

        /*
         * Note - the preferred way of doing the following would
         * be with a call to strtok like: "strtok(NULL, ";")".
         * However, PDBlib also uses strtok, hence messing up
         * my use of it; thus I must provide the string argument
         * for each call.
         */
        name = (char *)strtok(name + strlen(name) + 1, delim);
        if (name == NULL)
            break;

    }                           /* for-i */

    return(0);
}
Exemple #14
0
/* basic testing of all RAW_FILEINFO_* calls 
   for each call we test that it succeeds, and where possible test 
   for consistency between the calls. 
*/
static bool torture_raw_qfileinfo_internals(struct torture_context *torture, 
					    TALLOC_CTX *mem_ctx, 	
					    struct smbcli_tree *tree, 
					    int fnum, const char *fname,
					    bool is_ipc)
{
	int i;
	bool ret = true;
	int count;
	union smb_fileinfo *s1, *s2;	
	NTTIME correct_time;
	uint64_t correct_size;
	uint32_t correct_attrib;
	const char *correct_name;
	bool skip_streams = false;

	/* scan all the fileinfo and pathinfo levels */
	for (i=0; levels[i].name; i++) {
		if (!levels[i].only_paths) {
			levels[i].fnum_finfo.generic.level = levels[i].level;
			levels[i].fnum_finfo.generic.in.file.fnum = fnum;
			levels[i].fnum_status = smb_raw_fileinfo(tree, mem_ctx, 
								 &levels[i].fnum_finfo);
		}

		if (!levels[i].only_handles) {
			levels[i].fname_finfo.generic.level = levels[i].level;
			levels[i].fname_finfo.generic.in.file.path = talloc_strdup(mem_ctx, fname);
			levels[i].fname_status = smb_raw_pathinfo(tree, mem_ctx, 
								  &levels[i].fname_finfo);
		}
	}

	/* check for completely broken levels */
	for (count=i=0; levels[i].name; i++) {
		uint32_t cap = tree->session->transport->negotiate.capabilities;
		/* see if this server claims to support this level */
		if ((cap & levels[i].capability_mask) != levels[i].capability_mask) {
			continue;
		}

		if (is_ipc) {
			if (levels[i].expected_ipc_access_denied && NT_STATUS_EQUAL(NT_STATUS_ACCESS_DENIED, levels[i].fname_status)) {
			} else if (!levels[i].only_handles &&
				   NT_STATUS_EQUAL(levels[i].fname_status,
				   NT_STATUS_NOT_SUPPORTED)) {
				torture_warning(torture, "fname level %s %s",
					levels[i].name,
					nt_errstr(levels[i].fname_status));
				continue;
			} else if (!levels[i].only_handles && !NT_STATUS_EQUAL(NT_STATUS_INVALID_DEVICE_REQUEST, levels[i].fname_status)) {
				printf("ERROR: fname level %s failed, expected NT_STATUS_INVALID_DEVICE_REQUEST - %s\n", 
				       levels[i].name, nt_errstr(levels[i].fname_status));
				count++;
			}
			if (!levels[i].only_paths &&
			   (NT_STATUS_EQUAL(levels[i].fnum_status,
			    NT_STATUS_NOT_SUPPORTED) ||
			    NT_STATUS_EQUAL(levels[i].fnum_status,
			    NT_STATUS_NOT_IMPLEMENTED))) {
				torture_warning(torture, "fnum level %s %s",
					levels[i].name,
					nt_errstr(levels[i].fnum_status));
				continue;
			}
			if (!levels[i].only_paths && !NT_STATUS_EQUAL(levels[i].expected_ipc_fnum_status, levels[i].fnum_status)) {
				printf("ERROR: fnum level %s failed, expected %s - %s\n", 
				       levels[i].name, nt_errstr(levels[i].expected_ipc_fnum_status), 
				       nt_errstr(levels[i].fnum_status));
				count++;
			}
		} else {
			if (!levels[i].only_paths &&
			   (NT_STATUS_EQUAL(levels[i].fnum_status,
			    NT_STATUS_NOT_SUPPORTED) ||
			    NT_STATUS_EQUAL(levels[i].fnum_status,
			    NT_STATUS_NOT_IMPLEMENTED))) {
				torture_warning(torture, "fnum level %s %s",
					levels[i].name,
					nt_errstr(levels[i].fnum_status));
				continue;
			}

			if (!levels[i].only_handles &&
			   (NT_STATUS_EQUAL(levels[i].fname_status,
			    NT_STATUS_NOT_SUPPORTED) ||
			    NT_STATUS_EQUAL(levels[i].fname_status,
			    NT_STATUS_NOT_IMPLEMENTED))) {
                                torture_warning(torture, "fname level %s %s",
					levels[i].name,
					nt_errstr(levels[i].fname_status));
				continue;
			}

			if (!levels[i].only_paths && !NT_STATUS_IS_OK(levels[i].fnum_status)) {
				printf("ERROR: fnum level %s failed - %s\n", 
				       levels[i].name, nt_errstr(levels[i].fnum_status));
				count++;
			}
			if (!levels[i].only_handles && !NT_STATUS_IS_OK(levels[i].fname_status)) {
				printf("ERROR: fname level %s failed - %s\n", 
				       levels[i].name, nt_errstr(levels[i].fname_status));
				count++;
			}
		}
		
	}

	if (count != 0) {
		ret = false;
		printf("%d levels failed\n", count);
		if (count > 35) {
			torture_fail(torture, "too many level failures - giving up");
		}
	}

	/* see if we can do streams */
	s1 = fnum_find("STREAM_INFO");
	if (!s1 || s1->stream_info.out.num_streams == 0) {
		if (!is_ipc) {
			printf("STREAM_INFO broken (%d) - skipping streams checks\n",
			       s1 ? s1->stream_info.out.num_streams : -1);
		}
		skip_streams = true;
	}	


	/* this code is incredibly repititive but doesn't lend itself to loops, so
	   we use lots of macros to make it less painful */

	/* first off we check the levels that are supposed to be aliases. It will be quite rare for 
	   this code to fail, but we need to check it for completeness */



#define ALIAS_CHECK(sname1, sname2) \
	do { \
		s1 = fnum_find(sname1);	 s2 = fnum_find(sname2); \
		if (s1 && s2) { INFO_CHECK } \
		s1 = fname_find(is_ipc, sname1); s2 = fname_find(is_ipc, sname2); \
		if (s1 && s2) { INFO_CHECK } \
		s1 = fnum_find(sname1);	 s2 = fname_find(is_ipc, sname2); \
		if (s1 && s2) { INFO_CHECK } \
	} while (0)

#define INFO_CHECK \
		STRUCT_EQUAL(basic_info,  create_time, basic_info, create_time); \
		STRUCT_EQUAL(basic_info,  access_time, basic_info, access_time); \
		STRUCT_EQUAL(basic_info,  write_time,  basic_info, write_time); \
		STRUCT_EQUAL(basic_info,  change_time, basic_info, change_time); \
		VAL_EQUAL   (basic_info,  attrib,      basic_info, attrib);

	ALIAS_CHECK("BASIC_INFO", "BASIC_INFORMATION");

#undef INFO_CHECK
#define INFO_CHECK \
		VAL_EQUAL(standard_info,  alloc_size,     standard_info, alloc_size); \
		VAL_EQUAL(standard_info,  size,           standard_info, size); \
		VAL_EQUAL(standard_info,  nlink,          standard_info, nlink); \
		VAL_EQUAL(standard_info,  delete_pending, standard_info, delete_pending); \
		VAL_EQUAL(standard_info,  directory,      standard_info, directory);

	ALIAS_CHECK("STANDARD_INFO", "STANDARD_INFORMATION");

#undef INFO_CHECK
#define INFO_CHECK \
		VAL_EQUAL(ea_info,  ea_size,     ea_info, ea_size);

	ALIAS_CHECK("EA_INFO", "EA_INFORMATION");

#undef INFO_CHECK
#define INFO_CHECK \
		STR_EQUAL(name_info,  fname,   name_info, fname);

	ALIAS_CHECK("NAME_INFO", "NAME_INFORMATION");

#undef INFO_CHECK
#define INFO_CHECK \
		STRUCT_EQUAL(all_info,  create_time,           all_info, create_time); \
		STRUCT_EQUAL(all_info,  access_time,           all_info, access_time); \
		STRUCT_EQUAL(all_info,  write_time,            all_info, write_time); \
		STRUCT_EQUAL(all_info,  change_time,           all_info, change_time); \
		   VAL_EQUAL(all_info,  attrib,                all_info, attrib); \
		   VAL_EQUAL(all_info,  alloc_size,            all_info, alloc_size); \
		   VAL_EQUAL(all_info,  size,                  all_info, size); \
		   VAL_EQUAL(all_info,  nlink,                 all_info, nlink); \
		   VAL_EQUAL(all_info,  delete_pending,        all_info, delete_pending); \
		   VAL_EQUAL(all_info,  directory,             all_info, directory); \
		   VAL_EQUAL(all_info,  ea_size,               all_info, ea_size); \
		   STR_EQUAL(all_info,  fname,                 all_info, fname);

	ALIAS_CHECK("ALL_INFO", "ALL_INFORMATION");

#undef INFO_CHECK
#define INFO_CHECK \
		VAL_EQUAL(compression_info, compressed_size,compression_info, compressed_size); \
		VAL_EQUAL(compression_info, format,         compression_info, format); \
		VAL_EQUAL(compression_info, unit_shift,     compression_info, unit_shift); \
		VAL_EQUAL(compression_info, chunk_shift,    compression_info, chunk_shift); \
		VAL_EQUAL(compression_info, cluster_shift,  compression_info, cluster_shift);

	ALIAS_CHECK("COMPRESSION_INFO", "COMPRESSION_INFORMATION");


#undef INFO_CHECK
#define INFO_CHECK \
		STR_EQUAL(alt_name_info,  fname,   alt_name_info, fname);

	ALIAS_CHECK("ALT_NAME_INFO", "ALT_NAME_INFORMATION");


#define TIME_CHECK_NT(sname, stype, tfield) do { \
	s1 = fnum_find(sname); \
	if (s1 && memcmp(&s1->stype.out.tfield, &correct_time, sizeof(correct_time)) != 0) { \
		printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield,  \
		       nt_time_string(mem_ctx, s1->stype.out.tfield), \
		       nt_time_string(mem_ctx, correct_time)); \
		ret = false; \
	} \
	s1 = fname_find(is_ipc, sname); \
	if (s1 && memcmp(&s1->stype.out.tfield, &correct_time, sizeof(correct_time)) != 0) { \
		printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield,  \
		       nt_time_string(mem_ctx, s1->stype.out.tfield), \
		       nt_time_string(mem_ctx, correct_time)); \
		ret = false; \
	}} while (0)

#define TIME_CHECK_DOS(sname, stype, tfield) do { \
	s1 = fnum_find(sname); \
	if (s1 && dos_nt_time_cmp(s1->stype.out.tfield, correct_time) != 0) { \
		printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield,  \
		       timestring(mem_ctx, s1->stype.out.tfield), \
		       nt_time_string(mem_ctx, correct_time)); \
		ret = false; \
	} \
	s1 = fname_find(is_ipc, sname); \
	if (s1 && dos_nt_time_cmp(s1->stype.out.tfield, correct_time) != 0) { \
		printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield,  \
		       timestring(mem_ctx, s1->stype.out.tfield), \
		       nt_time_string(mem_ctx, correct_time)); \
		ret = false; \
	}} while (0)

#if 0 /* unused */
#define TIME_CHECK_UNX(sname, stype, tfield) do { \
	s1 = fnum_find(sname); \
	if (s1 && unx_nt_time_cmp(s1->stype.out.tfield, correct_time) != 0) { \
		printf("(%d) handle %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield,  \
		       timestring(mem_ctx, s1->stype.out.tfield), \
		       nt_time_string(mem_ctx, correct_time)); \
		ret = false; \
	} \
	s1 = fname_find(is_ipc, sname); \
	if (s1 && unx_nt_time_cmp(s1->stype.out.tfield, correct_time) != 0) { \
		printf("(%d) path %s/%s incorrect - %s should be %s\n", __LINE__, #stype, #tfield,  \
		       timestring(mem_ctx, s1->stype.out.tfield), \
		       nt_time_string(mem_ctx, correct_time)); \
		ret = false; \
	}} while (0)
#endif

	/* now check that all the times that are supposed to be equal are correct */
	s1 = fnum_find("BASIC_INFO");
	correct_time = s1->basic_info.out.create_time;
	torture_comment(torture, "create_time: %s\n", nt_time_string(mem_ctx, correct_time));

	TIME_CHECK_NT ("BASIC_INFO",               basic_info, create_time);
	TIME_CHECK_NT ("BASIC_INFORMATION",        basic_info, create_time);
	TIME_CHECK_DOS("GETATTRE",                 getattre,   create_time);
	TIME_CHECK_DOS("STANDARD",                 standard,   create_time);
	TIME_CHECK_DOS("EA_SIZE",                  ea_size,    create_time);
	TIME_CHECK_NT ("ALL_INFO",                 all_info,   create_time);
	TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, create_time);

	s1 = fnum_find("BASIC_INFO");
	correct_time = s1->basic_info.out.access_time;
	torture_comment(torture, "access_time: %s\n", nt_time_string(mem_ctx, correct_time));

	TIME_CHECK_NT ("BASIC_INFO",               basic_info, access_time);
	TIME_CHECK_NT ("BASIC_INFORMATION",        basic_info, access_time);
	TIME_CHECK_DOS("GETATTRE",                 getattre,   access_time);
	TIME_CHECK_DOS("STANDARD",                 standard,   access_time);
	TIME_CHECK_DOS("EA_SIZE",                  ea_size,    access_time);
	TIME_CHECK_NT ("ALL_INFO",                 all_info,   access_time);
	TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, access_time);

	s1 = fnum_find("BASIC_INFO");
	correct_time = s1->basic_info.out.write_time;
	torture_comment(torture, "write_time : %s\n", nt_time_string(mem_ctx, correct_time));

	TIME_CHECK_NT ("BASIC_INFO",               basic_info, write_time);
	TIME_CHECK_NT ("BASIC_INFORMATION",        basic_info, write_time);
	TIME_CHECK_DOS("GETATTR",                  getattr,    write_time);
	TIME_CHECK_DOS("GETATTRE",                 getattre,   write_time);
	TIME_CHECK_DOS("STANDARD",                 standard,   write_time);
	TIME_CHECK_DOS("EA_SIZE",                  ea_size,    write_time);
	TIME_CHECK_NT ("ALL_INFO",                 all_info,   write_time);
	TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, write_time);

	s1 = fnum_find("BASIC_INFO");
	correct_time = s1->basic_info.out.change_time;
	torture_comment(torture, "change_time: %s\n", nt_time_string(mem_ctx, correct_time));

	TIME_CHECK_NT ("BASIC_INFO",               basic_info, change_time);
	TIME_CHECK_NT ("BASIC_INFORMATION",        basic_info, change_time);
	TIME_CHECK_NT ("ALL_INFO",                 all_info,   change_time);
	TIME_CHECK_NT ("NETWORK_OPEN_INFORMATION", network_open_information, change_time);


#define SIZE_CHECK(sname, stype, tfield) do { \
	s1 = fnum_find(sname); \
	if (s1 && s1->stype.out.tfield != correct_size) { \
		printf("(%d) handle %s/%s incorrect - %u should be %u\n", __LINE__, #stype, #tfield,  \
		       (unsigned int)s1->stype.out.tfield, \
		       (unsigned int)correct_size); \
		ret = false; \
	} \
	s1 = fname_find(is_ipc, sname); \
	if (s1 && s1->stype.out.tfield != correct_size) { \
		printf("(%d) path %s/%s incorrect - %u should be %u\n", __LINE__, #stype, #tfield,  \
		       (unsigned int)s1->stype.out.tfield, \
		       (unsigned int)correct_size); \
		ret = false; \
	}} while (0)

	s1 = fnum_find("STANDARD_INFO");
	correct_size = s1->standard_info.out.size;
	torture_comment(torture, "size: %u\n", (unsigned int)correct_size);
	
	SIZE_CHECK("GETATTR",                  getattr,                  size);
	SIZE_CHECK("GETATTRE",                 getattre,                 size);
	SIZE_CHECK("STANDARD",                 standard,                 size);
	SIZE_CHECK("EA_SIZE",                  ea_size,                  size);
	SIZE_CHECK("STANDARD_INFO",            standard_info,            size);
	SIZE_CHECK("STANDARD_INFORMATION",     standard_info,            size);
	SIZE_CHECK("ALL_INFO",                 all_info,                 size);
	SIZE_CHECK("ALL_INFORMATION",          all_info,                 size);
	SIZE_CHECK("COMPRESSION_INFO",         compression_info,         compressed_size);
	SIZE_CHECK("COMPRESSION_INFORMATION",  compression_info,         compressed_size);
	SIZE_CHECK("NETWORK_OPEN_INFORMATION", network_open_information, size);
	if (!skip_streams) {
		SIZE_CHECK("STREAM_INFO",              stream_info,   streams[0].size);
		SIZE_CHECK("STREAM_INFORMATION",       stream_info,   streams[0].size);
	}


	s1 = fnum_find("STANDARD_INFO");
	correct_size = s1->standard_info.out.alloc_size;
	torture_comment(torture, "alloc_size: %u\n", (unsigned int)correct_size);
	
	SIZE_CHECK("GETATTRE",                 getattre,                 alloc_size);
	SIZE_CHECK("STANDARD",                 standard,                 alloc_size);
	SIZE_CHECK("EA_SIZE",                  ea_size,                  alloc_size);
	SIZE_CHECK("STANDARD_INFO",            standard_info,            alloc_size);
	SIZE_CHECK("STANDARD_INFORMATION",     standard_info,            alloc_size);
	SIZE_CHECK("ALL_INFO",                 all_info,                 alloc_size);
	SIZE_CHECK("ALL_INFORMATION",          all_info,                 alloc_size);
	SIZE_CHECK("NETWORK_OPEN_INFORMATION", network_open_information, alloc_size);
	if (!skip_streams) {
		SIZE_CHECK("STREAM_INFO",              stream_info,   streams[0].alloc_size);
		SIZE_CHECK("STREAM_INFORMATION",       stream_info,   streams[0].alloc_size);
	}

#define ATTRIB_CHECK(sname, stype, tfield) do { \
	s1 = fnum_find(sname); \
	if (s1 && s1->stype.out.tfield != correct_attrib) { \
		printf("(%d) handle %s/%s incorrect - 0x%x should be 0x%x\n", __LINE__, #stype, #tfield,  \
		       (unsigned int)s1->stype.out.tfield, \
		       (unsigned int)correct_attrib); \
		ret = false; \
	} \
	s1 = fname_find(is_ipc, sname); \
	if (s1 && s1->stype.out.tfield != correct_attrib) { \
		printf("(%d) path %s/%s incorrect - 0x%x should be 0x%x\n", __LINE__, #stype, #tfield,  \
		       (unsigned int)s1->stype.out.tfield, \
		       (unsigned int)correct_attrib); \
		ret = false; \
	}} while (0)

	s1 = fnum_find("BASIC_INFO");
	correct_attrib = s1->basic_info.out.attrib;
	torture_comment(torture, "attrib: 0x%x\n", (unsigned int)correct_attrib);
	
	ATTRIB_CHECK("GETATTR",                   getattr,                   attrib);
	if (!is_ipc) {
		ATTRIB_CHECK("GETATTRE",                  getattre,                  attrib);
		ATTRIB_CHECK("STANDARD",                  standard,                  attrib);
		ATTRIB_CHECK("EA_SIZE",                   ea_size,                   attrib);
	}
	ATTRIB_CHECK("BASIC_INFO",                basic_info,                attrib);
	ATTRIB_CHECK("BASIC_INFORMATION",         basic_info,                attrib);
	ATTRIB_CHECK("ALL_INFO",                  all_info,                  attrib);
	ATTRIB_CHECK("ALL_INFORMATION",           all_info,                  attrib);
	ATTRIB_CHECK("NETWORK_OPEN_INFORMATION",  network_open_information,  attrib);
	ATTRIB_CHECK("ATTRIBUTE_TAG_INFORMATION", attribute_tag_information, attrib);

	correct_name = fname;
	torture_comment(torture, "name: %s\n", correct_name);

#define NAME_CHECK(sname, stype, tfield, flags) do { \
	s1 = fnum_find(sname); \
	if (s1 && (strcmp_safe(s1->stype.out.tfield.s, correct_name) != 0 || \
	    		wire_bad_flags(&s1->stype.out.tfield, flags, tree->session->transport))) { \
		printf("(%d) handle %s/%s incorrect - '%s/%d'\n", __LINE__, #stype, #tfield,  \
		       s1->stype.out.tfield.s, s1->stype.out.tfield.private_length); \
		ret = false; \
	} \
	s1 = fname_find(is_ipc, sname); \
	if (s1 && (strcmp_safe(s1->stype.out.tfield.s, correct_name) != 0 || \
	    		wire_bad_flags(&s1->stype.out.tfield, flags, tree->session->transport))) { \
		printf("(%d) path %s/%s incorrect - '%s/%d'\n", __LINE__, #stype, #tfield,  \
		       s1->stype.out.tfield.s, s1->stype.out.tfield.private_length); \
		ret = false; \
	}} while (0)

	NAME_CHECK("NAME_INFO",        name_info, fname, STR_UNICODE);
	NAME_CHECK("NAME_INFORMATION", name_info, fname, STR_UNICODE);

	/* the ALL_INFO file name is the full path on the filesystem */
	s1 = fnum_find("ALL_INFO");
	if (s1 && !s1->all_info.out.fname.s) {
		torture_fail(torture, "ALL_INFO didn't give a filename");
	}
	if (s1 && s1->all_info.out.fname.s) {
		char *p = strrchr(s1->all_info.out.fname.s, '\\');
		if (!p) {
			printf("Not a full path in all_info/fname? - '%s'\n", 
			       s1->all_info.out.fname.s);
			ret = false;
		} else {
			if (strcmp_safe(correct_name, p) != 0) {
				printf("incorrect basename in all_info/fname - '%s'\n",
				       s1->all_info.out.fname.s);
				ret = false;
			}
		}
		if (wire_bad_flags(&s1->all_info.out.fname, STR_UNICODE, tree->session->transport)) {
			printf("Should not null terminate all_info/fname\n");
			ret = false;
		}
	}

	s1 = fnum_find("ALT_NAME_INFO");
	if (s1) {
		correct_name = s1->alt_name_info.out.fname.s;
	}

	if (!correct_name) {
		torture_comment(torture, "no alternate name information\n");
	} else {
		torture_comment(torture, "alt_name: %s\n", correct_name);
		
		NAME_CHECK("ALT_NAME_INFO",        alt_name_info, fname, STR_UNICODE);
		NAME_CHECK("ALT_NAME_INFORMATION", alt_name_info, fname, STR_UNICODE);
		
		/* and make sure we can open by alternate name */
		smbcli_close(tree, fnum);
		fnum = smbcli_nt_create_full(tree, correct_name, 0, 
					     SEC_RIGHTS_FILE_ALL,
					     FILE_ATTRIBUTE_NORMAL,
					     NTCREATEX_SHARE_ACCESS_DELETE|
					     NTCREATEX_SHARE_ACCESS_READ|
					     NTCREATEX_SHARE_ACCESS_WRITE, 
					     NTCREATEX_DISP_OVERWRITE_IF, 
					     0, 0);
		if (fnum == -1) {
			printf("Unable to open by alt_name - %s\n", smbcli_errstr(tree));
			ret = false;
		}
		
		if (!skip_streams) {
			correct_name = "::$DATA";
			torture_comment(torture, "stream_name: %s\n", correct_name);
			
			NAME_CHECK("STREAM_INFO",        stream_info, streams[0].stream_name, STR_UNICODE);
			NAME_CHECK("STREAM_INFORMATION", stream_info, streams[0].stream_name, STR_UNICODE);
		}
	}
		
	/* make sure the EAs look right */
	s1 = fnum_find("ALL_EAS");
	s2 = fnum_find("ALL_INFO");
	if (s1) {
		for (i=0;i<s1->all_eas.out.num_eas;i++) {
			printf("  flags=%d %s=%*.*s\n", 
			       s1->all_eas.out.eas[i].flags,
			       s1->all_eas.out.eas[i].name.s,
			       (int)s1->all_eas.out.eas[i].value.length,
			       (int)s1->all_eas.out.eas[i].value.length,
			       s1->all_eas.out.eas[i].value.data);
		}
	}
	if (s1 && s2) {
		if (s1->all_eas.out.num_eas == 0) {
			if (s2->all_info.out.ea_size != 0) {
				printf("ERROR: num_eas==0 but fnum all_info.out.ea_size == %d\n",
				       s2->all_info.out.ea_size);
			}
		} else {
			if (s2->all_info.out.ea_size != 
			    ea_list_size(s1->all_eas.out.num_eas, s1->all_eas.out.eas)) {
				printf("ERROR: ea_list_size=%d != fnum all_info.out.ea_size=%d\n",
				       (int)ea_list_size(s1->all_eas.out.num_eas, s1->all_eas.out.eas),
				       (int)s2->all_info.out.ea_size);
			}
		}
	}
	s2 = fname_find(is_ipc, "ALL_EAS");
	if (s2) {
		VAL_EQUAL(all_eas, num_eas, all_eas, num_eas);
		for (i=0;i<s1->all_eas.out.num_eas;i++) {
			VAL_EQUAL(all_eas, eas[i].flags, all_eas, eas[i].flags);
			STR_EQUAL(all_eas, eas[i].name, all_eas, eas[i].name);
			VAL_EQUAL(all_eas, eas[i].value.length, all_eas, eas[i].value.length);
		}
	}

#define VAL_CHECK(sname1, stype1, tfield1, sname2, stype2, tfield2) do { \
	s1 = fnum_find(sname1); s2 = fnum_find(sname2); \
	if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \
		printf("(%d) handle %s/%s != %s/%s - 0x%x vs 0x%x\n", __LINE__, \
                       #stype1, #tfield1, #stype2, #tfield2,  \
		       s1->stype1.out.tfield1, s2->stype2.out.tfield2); \
		ret = false; \
	} \
	s1 = fname_find(is_ipc, sname1); s2 = fname_find(is_ipc, sname2); \
	if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \
		printf("(%d) path %s/%s != %s/%s - 0x%x vs 0x%x\n", __LINE__, \
                       #stype1, #tfield1, #stype2, #tfield2,  \
		       s1->stype1.out.tfield1, s2->stype2.out.tfield2); \
		ret = false; \
	} \
	s1 = fnum_find(sname1); s2 = fname_find(is_ipc, sname2); \
	if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \
		printf("(%d) handle %s/%s != path %s/%s - 0x%x vs 0x%x\n", __LINE__, \
                       #stype1, #tfield1, #stype2, #tfield2,  \
		       s1->stype1.out.tfield1, s2->stype2.out.tfield2); \
		ret = false; \
	} \
	s1 = fname_find(is_ipc, sname1); s2 = fnum_find(sname2); \
	if (s1 && s2 && s1->stype1.out.tfield1 != s2->stype2.out.tfield2) { \
		printf("(%d) path %s/%s != handle %s/%s - 0x%x vs 0x%x\n", __LINE__, \
                       #stype1, #tfield1, #stype2, #tfield2,  \
		       s1->stype1.out.tfield1, s2->stype2.out.tfield2); \
		ret = false; \
	}} while (0)

	VAL_CHECK("STANDARD_INFO", standard_info, delete_pending, 
		  "ALL_INFO",      all_info,      delete_pending);
	VAL_CHECK("STANDARD_INFO", standard_info, directory, 
		  "ALL_INFO",      all_info,      directory);
	VAL_CHECK("STANDARD_INFO", standard_info, nlink, 
		  "ALL_INFO",      all_info,      nlink);
	s1 = fnum_find("BASIC_INFO");
	if (s1 && is_ipc) {
		if (s1->basic_info.out.attrib != FILE_ATTRIBUTE_NORMAL) {
			printf("(%d) attrib basic_info/nlink incorrect - %d should be %d\n", __LINE__, s1->basic_info.out.attrib, (int)FILE_ATTRIBUTE_NORMAL);
			ret = false;
		}
	}
	s1 = fnum_find("STANDARD_INFO");
	if (s1 && is_ipc) {
		if (s1->standard_info.out.nlink != 1) {
			printf("(%d) nlinks standard_info/nlink incorrect - %d should be 1\n", __LINE__, s1->standard_info.out.nlink);
			ret = false;
		}
		if (s1->standard_info.out.delete_pending != 1) {
			printf("(%d) nlinks standard_info/delete_pending incorrect - %d should be 1\n", __LINE__, s1->standard_info.out.delete_pending);
			ret = false;
		}
	}
	VAL_CHECK("EA_INFO",       ea_info,       ea_size, 
		  "ALL_INFO",      all_info,      ea_size);
	if (!is_ipc) {
		VAL_CHECK("EA_SIZE",       ea_size,       ea_size, 
			  "ALL_INFO",      all_info,      ea_size);
	}

#define NAME_PATH_CHECK(sname, stype, field) do { \
	s1 = fname_find(is_ipc, sname); s2 = fnum_find(sname); \
        if (s1 && s2) { \
		VAL_EQUAL(stype, field, stype, field); \
	} \
} while (0)


	s1 = fnum_find("INTERNAL_INFORMATION");
	if (s1) {
		torture_comment(torture, "file_id=%.0f\n", (double)s1->internal_information.out.file_id);
	}

	NAME_PATH_CHECK("INTERNAL_INFORMATION", internal_information, file_id);
	NAME_PATH_CHECK("POSITION_INFORMATION", position_information, position);
	if (s1 && s2) {
		printf("fnum pos = %.0f, fname pos = %.0f\n",
		       (double)s2->position_information.out.position,
		       (double)s1->position_information.out.position );
	}
	NAME_PATH_CHECK("MODE_INFORMATION", mode_information, mode);
	NAME_PATH_CHECK("ALIGNMENT_INFORMATION", alignment_information, alignment_requirement);
	NAME_PATH_CHECK("ATTRIBUTE_TAG_INFORMATION", attribute_tag_information, attrib);
	NAME_PATH_CHECK("ATTRIBUTE_TAG_INFORMATION", attribute_tag_information, reparse_tag);

#if 0
	/* these are expected to differ */
	NAME_PATH_CHECK("ACCESS_INFORMATION", access_information, access_flags);
#endif

#if 0 /* unused */
#define UNKNOWN_CHECK(sname, stype, tfield) do { \
	s1 = fnum_find(sname); \
	if (s1 && s1->stype.out.tfield != 0) { \
		printf("(%d) handle %s/%s unknown != 0 (0x%x)\n", __LINE__, \
                       #stype, #tfield, \
		       (unsigned int)s1->stype.out.tfield); \
	} \
	s1 = fname_find(is_ipc, sname); \
	if (s1 && s1->stype.out.tfield != 0) { \
		printf("(%d) path %s/%s unknown != 0 (0x%x)\n", __LINE__, \
                       #stype, #tfield, \
		       (unsigned int)s1->stype.out.tfield); \
	}} while (0)
#endif
	/* now get a bit fancier .... */
	
	/* when we set the delete disposition then the link count should drop
	   to 0 and delete_pending should be 1 */
	
	return ret;
}
Exemple #15
0
#include <string.h>
#include <stdio.h>
#include "UnitTest.h"

#define CCHARP(str)           ((const char*)str)
#define STR_EQUAL(str1, str2) (strcmp(CCHARP(str1), CCHARP(str2)) == 0)

EDELIB_NS_USE

UT_FUNC(ThemeTestReader, "Test Theme reader")
{
	Theme t;
	UT_VERIFY( t.load("theme.et") == true );
	UT_VERIFY( t.loaded() == true );

	UT_VERIFY( t.author() && STR_EQUAL(t.author(), "John Foo <*****@*****.**>") );
	UT_VERIFY( t.name() && STR_EQUAL(t.name(), "Demo") );
	UT_VERIFY( t.sample_image() && STR_EQUAL(t.sample_image(), "img.jpg") );

	char buf[64];
	long lval;

	UT_VERIFY( t.get_item("test style", "item1", buf, sizeof(buf)) );
	UT_VERIFY( STR_EQUAL(buf, "value 1") );

	UT_VERIFY( t.get_item("test style", "item2", buf, sizeof(buf)) );
	UT_VERIFY( STR_EQUAL(buf, "value 2") );

	UT_VERIFY( t.get_item("test style", "item3", lval, 0) );
	UT_VERIFY( lval == 123 );
Exemple #16
0
static bool recurrence_initialize_rrule_vcal(const char* str, RRule* rrule)
{
  int i;

  /** TODO - check for other whitespace, and multiple whitespace */
  char** strv = strsplit(str, ' ');

  rrule->interval = 1;

  if (strv[0][0] == 'D')
  {
    rrule->freq = RRuleDaily;
    rrule->interval = atoi(strv[0]+1);
    if (strv[1])
    {
      if (strv[1][0] == '#')
	rrule->count = atoi(strv[1]+1);
      else
	replace_string_with_copy(&rrule->until, strv[1]);
    }
  }
  else if (strv[0][0] == 'W')
  {
    rrule->freq = RRuleWeekly;
    rrule->interval = atoi(strv[0]+1);

    StrBuf *days_list = strbuf_new(NULL);
    for (i = 1; strv[i]; i++)
    {
      if (strv[i][0] == '#')
      {
	rrule->count = atoi(strv[i]+1);
	break;
      }
      else if (isdigit(strv[i][0]))
      {
	replace_string_with_copy(&rrule->until, strv[i]);
	break;
      }
      else
      {
	if (days_list->length > 0)
	  days_list = strbuf_append(days_list,",");
	days_list = strbuf_append(days_list,strv[i]);
      }
    }
    if (days_list->length > 0)
      replace_string_with_copy(&rrule->byday, days_list->buffer);
    strbuf_destroy(days_list,1);
  }
  else if (strv[0][0] == 'M')
  {
    rrule->freq = RRuleMonthly;
    if (strv[0][1] == 'D') /* by day in month, ie date */
    {
      rrule->interval = atoi(strv[0]+2);

      int days_found = 0;
      for (i = 1; strv[i]; i++)
      {
	if (strv[i][0] == '#')
	{
	  rrule->count = atoi(strv[i]+1);
	  break;
	}
	else if (isdigit(strv[i][0]) || STR_EQUAL(strv[i],"LD"))
	{
	  if (strlen(strv[i]) > 2)
	  {
	    replace_string_with_copy(&rrule->until, strv[i]);
	    break;
	  }

	  if (days_found == 0)
	  {
	    if (STR_EQUAL(strv[i],"LD"))
	      rrule->bymonthday = -1;
	    else
	      rrule->bymonthday = atoi(strv[i]);
	  }
	  days_found++;
	}
      }

      if (days_found > 1)
	synce_warning("Monthly by Day (MD) can only handle one day in RRA format, in RRULE '%s'", str);
    }
    else if (strv[0][1] == 'P') /* by position, ie the complicated one */
    {
      rrule->interval = atoi(strv[0]+2);

      StrBuf *days_list = strbuf_new(NULL);
      int occurence = 0;
      for (i = 1; strv[i]; i++)
      {
	if (strv[i][0] == '#')
	{
	  rrule->count = atoi(strv[i]+1);
	  break;
	}
	else if (isdigit(strv[i][0]) && strlen(strv[i]) > 2)
	{
	  replace_string_with_copy(&rrule->until, strv[i]);
	  break;
	}
	else if (isdigit(strv[i][0]))
	{
	  if (occurence != 0)
	    /* Any days following this shoukd be bound by this subsequent
	       occurence modifier, but cant be. We'll allow them to go with
	       the first occurrence modifier for now, but maybe we should
	       drop them entirely */
	    synce_info("Multiple occurence values cannot be represented by RRA in Monthly by Position recurrence");
	  else
	    occurence = atoi(strv[i]);
	}
	else
	{
	  if (days_list->length > 0)
	    days_list = strbuf_append(days_list,",");
	  days_list = strbuf_append(days_list,strv[i]);
	}
      }
      rrule->bysetpos = occurence;

      if (days_list->length > 0)
	replace_string_with_copy(&rrule->byday, days_list->buffer);
      strbuf_destroy(days_list,1);
    }
    else
      synce_error("Unexpected frequency in RRULE '%s'", str);
  }
  else if (strv[0][0] == 'Y')
  {
    rrule->freq = RRuleYearly;
    rrule->interval = atoi(strv[0]+2);

    if (strv[0][1] == 'M') /* by month number */
    {
      int months_found = 0;
      for (i = 1; strv[i]; i++)
      {
	if (strv[i][0] == '#')
	{
	  rrule->count = atoi(strv[i]+1);
	  break;
	}
	else if (isdigit(strv[i][0]))
	{
	  if (strlen(strv[i]) > 2)
	  {
	    replace_string_with_copy(&rrule->until, strv[i]);
	    break;
	  }

	  if (months_found == 0)
	  {
	    rrule->bymonth = atoi(strv[i]);
	  }
	  months_found++;
	}
      }

    }
    else if (strv[0][1] == 'D') /* by day in year */
    {
      int days_found = 0;
      for (i = 1; strv[i]; i++)
      {
	if (strv[i][0] == '#')
	{
	  rrule->count = atoi(strv[i]+1);
	  break;
	}
	else if (isdigit(strv[i][0]))
	{
	  if (strlen(strv[i]) > 2)
	  {
	    replace_string_with_copy(&rrule->until, strv[i]);
	    break;
	  }

	  if (days_found == 0)
	  {
	    rrule->bymonthday = atoi(strv[i]);
	  }
	  days_found++;
	}
      }

      if (days_found > 1)
	synce_warning("Yearly by Day (YD) (converted to monthly) can only handle one day in RRA format, in RRULE '%s'", str);

    }
    else
      synce_error("Unexpected frequency in RRULE '%s'", str);
  }
  else
  {
    synce_error("Unexpected frequency in RRULE '%s'", str);
  }
  
  strv_free(strv);
  return true;
}
void process_cmd_line_parameters(server_info *sinfo, char **argv)
{
    parameters_parser_state state = PARAM_P_ST_START;
    int request_for_next_arg = 0;

    /* Defaults */
    sinfo->max_clients = -1; /* without limitation */
    sinfo->server_ip = NULL; /* "127.0.0.1", see after while */
    sinfo->time_between_time_events = 10; /* 10 seconds */

    while (*argv != NULL) {
        switch (state) {
        case PARAM_P_ST_START:
            if (STR_EQUAL(*argv, "--port")
                || STR_EQUAL(*argv, "-p"))
            {
                state = PARAM_P_ST_PORT;
                request_for_next_arg = 1;
            } else if (STR_EQUAL(*argv, "--max")
                || STR_EQUAL(*argv, "-m"))
            {
                state = PARAM_P_ST_MAX;
                request_for_next_arg = 1;
            } else if (STR_EQUAL(*argv, "--time")
                || STR_EQUAL(*argv, "-t"))
            {
                state = PARAM_P_ST_TIME;
                request_for_next_arg = 1;
            } else {
                state = PARAM_P_ST_IP;
            }
            break;
        case PARAM_P_ST_IP:
            if (sinfo->server_ip == NULL) {
                sinfo->server_ip = *argv;
                request_for_next_arg = 1;
            } else {
                state = PARAM_P_ST_ERROR;
            }
            break;
        case PARAM_P_ST_PORT:
            sinfo->listening_port = atoi(*argv);
            if (sinfo->listening_port == 0) {
                state = PARAM_P_ST_ERROR;
            } else {
                state = PARAM_P_ST_START;
                request_for_next_arg = 1;
            }
            break;
        case PARAM_P_ST_MAX:
            sinfo->max_clients = atoi(*argv);
            if (sinfo->max_clients == 0) {
                state = PARAM_P_ST_ERROR;
            } else {
                state = PARAM_P_ST_START;
                request_for_next_arg = 1;
            }
            break;
        case PARAM_P_ST_TIME:
            sinfo->time_between_time_events = atoi(*argv);
            if (sinfo->time_between_time_events == 0
                && !STR_EQUAL(*argv, "0"))
            {
                state = PARAM_P_ST_ERROR;
            } else {
                state = PARAM_P_ST_START;
                request_for_next_arg = 1;
            }
            break;
        case PARAM_P_ST_ERROR:
            fprintf(stderr, "Wrong parameters!\n");
            exit(ES_WRONG_PARAM);
            break;
        }

        if (request_for_next_arg) {
            ++argv;
            request_for_next_arg = 0;
        }
    } /* while */

    if (sinfo->server_ip == NULL) {
        sinfo->server_ip = "127.0.0.1";
    }
}
Exemple #18
0
	data = EdbusData::from_int64(11);
	UT_VERIFY( data.is_int64() == true );
	UT_VERIFY( data.to_int64() == 11 );

	data = EdbusData::from_uint64(11);
	UT_VERIFY( data.is_uint64() == true );
	UT_VERIFY( data.to_uint64() == 11 );

	data = EdbusData::from_double(0.1);
	UT_VERIFY( data.is_double() == true );
	UT_VERIFY( data.to_double() == 0.1 );

	data = EdbusData::from_string("foo");
	UT_VERIFY( data.is_string() == true );
	UT_VERIFY( STR_EQUAL(data.to_string(), "foo") );

	EdbusData data2 = data;
	UT_VERIFY( data == data2 );

	data2 = EdbusData::from_int32(10);
	UT_VERIFY( data.is_string() == true );
	UT_VERIFY( data2.is_int32() == true );
	UT_VERIFY( data != data2 );

	EdbusObjectPath op;
	op << "org" << "example" << "foo";
	data = EdbusData::from_object_path(op);
	UT_VERIFY( data.is_object_path() == true );
	UT_VERIFY( STR_EQUAL(data.to_object_path().path(), "/org/example/foo") );
Exemple #19
0
/* basic testing of all RAW_QFS_* calls 
   for each call we test that it succeeds, and where possible test 
   for consistency between the calls. 

   Some of the consistency tests assume that the target filesystem is
   quiescent, which is sometimes hard to achieve
*/
bool torture_raw_qfsinfo(struct torture_context *torture, 
			 struct smbcli_state *cli)
{
	int i;
	bool ret = true;
	int count;
	union smb_fsinfo *s1, *s2;	

	/* scan all the levels, pulling the results */
	for (i=0; levels[i].name; i++) {
		torture_comment(torture, "Running level %s\n", levels[i].name);
		levels[i].fsinfo.generic.level = levels[i].level;
		levels[i].status = smb_raw_fsinfo(cli->tree, torture, &levels[i].fsinfo);
	}

	/* check for completely broken levels */
	for (count=i=0; levels[i].name; i++) {
		uint32_t cap = cli->transport->negotiate.capabilities;
		/* see if this server claims to support this level */
		if ((cap & levels[i].capability_mask) != levels[i].capability_mask) {
			continue;
		}
		
		if (!NT_STATUS_IS_OK(levels[i].status)) {
			printf("ERROR: level %s failed - %s\n", 
			       levels[i].name, nt_errstr(levels[i].status));
			count++;
		}
	}

	if (count != 0) {
		torture_comment(torture, "%d levels failed\n", count);
		torture_assert(torture, count > 13, "too many level failures - giving up");
	}

	torture_comment(torture, "check for correct aliases\n");
	s1 = find("SIZE_INFO");
	s2 = find("SIZE_INFORMATION");
	if (s1 && s2) {
		VAL_EQUAL(size_info, total_alloc_units, size_info, total_alloc_units);
		VAL_APPROX_EQUAL(size_info, avail_alloc_units, size_info, avail_alloc_units);
		VAL_EQUAL(size_info, sectors_per_unit,  size_info, sectors_per_unit);
		VAL_EQUAL(size_info, bytes_per_sector,  size_info, bytes_per_sector);
	}	

	s1 = find("DEVICE_INFO");
	s2 = find("DEVICE_INFORMATION");
	if (s1 && s2) {
		VAL_EQUAL(device_info, device_type,     device_info, device_type);
		VAL_EQUAL(device_info, characteristics, device_info, characteristics);
	}	

	s1 = find("VOLUME_INFO");
	s2 = find("VOLUME_INFORMATION");
	if (s1 && s2) {
		STRUCT_EQUAL(volume_info, create_time,    volume_info, create_time);
		VAL_EQUAL   (volume_info, serial_number,  volume_info, serial_number);
		STR_EQUAL   (volume_info, volume_name.s,    volume_info, volume_name.s);
		torture_comment(torture, "volume_info.volume_name = '%s'\n", s1->volume_info.out.volume_name.s);
	}	

	s1 = find("ATTRIBUTE_INFO");
	s2 = find("ATTRIBUTE_INFORMATION");
	if (s1 && s2) {
		VAL_EQUAL(attribute_info, fs_attr,    
			  attribute_info, fs_attr);
		VAL_EQUAL(attribute_info, max_file_component_length, 
			  attribute_info, max_file_component_length);
		STR_EQUAL(attribute_info, fs_type.s, attribute_info, fs_type.s);
		torture_comment(torture, "attribute_info.fs_type = '%s'\n", s1->attribute_info.out.fs_type.s);
	}	

	torture_comment(torture, "check for consistent disk sizes\n");
	s1 = find("DSKATTR");
	s2 = find("ALLOCATION");
	if (s1 && s2) {
		double size1, size2;
		double scale = s1->dskattr.out.blocks_per_unit * s1->dskattr.out.block_size;
		size1 = 1.0 * 
			s1->dskattr.out.units_total * 
			s1->dskattr.out.blocks_per_unit * 
			s1->dskattr.out.block_size / scale;
		size2 = 1.0 *
			s2->allocation.out.sectors_per_unit *
			s2->allocation.out.total_alloc_units *
			s2->allocation.out.bytes_per_sector / scale;
		if (abs(size1 - size2) > 1) {
			printf("Inconsistent total size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", 
			       size1, size2);
			ret = false;
		}
		torture_comment(torture, "total disk = %.0f MB\n", size1*scale/1.0e6);
	}

	torture_comment(torture, "check consistent free disk space\n");
	s1 = find("DSKATTR");
	s2 = find("ALLOCATION");
	if (s1 && s2) {
		double size1, size2;
		double scale = s1->dskattr.out.blocks_per_unit * s1->dskattr.out.block_size;
		size1 = 1.0 * 
			s1->dskattr.out.units_free * 
			s1->dskattr.out.blocks_per_unit * 
			s1->dskattr.out.block_size / scale;
		size2 = 1.0 *
			s2->allocation.out.sectors_per_unit *
			s2->allocation.out.avail_alloc_units *
			s2->allocation.out.bytes_per_sector / scale;
		if (abs(size1 - size2) > 1) {
			printf("Inconsistent avail size in DSKATTR and ALLOCATION - size1=%.0f size2=%.0f\n", 
			       size1, size2);
			ret = false;
		}
		torture_comment(torture, "free disk = %.0f MB\n", size1*scale/1.0e6);
	}
	
	torture_comment(torture, "volume info consistency\n");
	s1 = find("VOLUME");
	s2 = find("VOLUME_INFO");
	if (s1 && s2) {
		VAL_EQUAL(volume, serial_number,  volume_info, serial_number);
		STR_EQUAL(volume, volume_name.s,  volume_info, volume_name.s);
	}	

	/* disk size consistency - notice that 'avail_alloc_units' maps to the caller
	   available allocation units, not the total */
	s1 = find("SIZE_INFO");
	s2 = find("FULL_SIZE_INFORMATION");
	if (s1 && s2) {
		VAL_EQUAL(size_info, total_alloc_units, full_size_information, total_alloc_units);
		VAL_APPROX_EQUAL(size_info, avail_alloc_units, full_size_information, call_avail_alloc_units);
		VAL_EQUAL(size_info, sectors_per_unit,  full_size_information, sectors_per_unit);
		VAL_EQUAL(size_info, bytes_per_sector,  full_size_information, bytes_per_sector);
	}	

	printf("check for non-zero unknown fields\n");
	s1 = find("QUOTA_INFORMATION");
	if (s1) {
		VAL_UNKNOWN(quota_information, unknown[0]);
		VAL_UNKNOWN(quota_information, unknown[1]);
		VAL_UNKNOWN(quota_information, unknown[2]);
	}

	s1 = find("OBJECTID_INFORMATION");
	if (s1) {
		VAL_UNKNOWN(objectid_information, unknown[0]);
		VAL_UNKNOWN(objectid_information, unknown[1]);
		VAL_UNKNOWN(objectid_information, unknown[2]);
		VAL_UNKNOWN(objectid_information, unknown[3]);
		VAL_UNKNOWN(objectid_information, unknown[4]);
		VAL_UNKNOWN(objectid_information, unknown[5]);
	}


#define STR_CHECK(sname, stype, field, flags) do { \
	s1 = find(sname); \
	if (s1) { \
		if (s1->stype.out.field.s && wire_bad_flags(&s1->stype.out.field, flags, cli->transport)) { \
			printf("(%d) incorrect string termination in %s/%s\n", \
			       __LINE__, #stype, #field); \
			ret = false; \
		} \
	}} while (0)

	torture_comment(torture, "check for correct termination\n");
	
	STR_CHECK("VOLUME",                volume,         volume_name, 0);
	STR_CHECK("VOLUME_INFO",           volume_info,    volume_name, STR_UNICODE);
	STR_CHECK("VOLUME_INFORMATION",    volume_info,    volume_name, STR_UNICODE);
	STR_CHECK("ATTRIBUTE_INFO",        attribute_info, fs_type, STR_UNICODE);
	STR_CHECK("ATTRIBUTE_INFORMATION", attribute_info, fs_type, STR_UNICODE);

	return ret;
}
Exemple #20
0
} while(0)

UT_FUNC(XDGPathTest, "Test XDG paths")
{
	// save previous values
	char* p;
	String config_home, data_home, cache_home, data_dirs, config_dirs;

	STORE_ENV("XDG_CONFIG_HOME", config_home, p);
	STORE_ENV("XDG_DATA_HOME", data_home, p);
	STORE_ENV("XDG_CACHE_HOME", cache_home, p);
	STORE_ENV("XDG_DATA_DIRS", data_dirs, p);
	STORE_ENV("XDG_CONFIG_DIRS", config_dirs, p);

	edelib_setenv("XDG_CONFIG_HOME", "/dummy/place", 1);
	UT_VERIFY( STR_EQUAL(user_config_dir(), "/dummy/place") );
	edelib_unsetenv("XDG_CONFIG_HOME");

	edelib_setenv("XDG_DATA_HOME", "/", 1);
	UT_VERIFY( STR_EQUAL(user_data_dir(), "/") );

	edelib_setenv("XDG_DATA_HOME", "/baz", 1);
	UT_VERIFY( STR_EQUAL(user_data_dir(), "/baz") );
	edelib_unsetenv("XDG_DATA_HOME");

	edelib_setenv("XDG_CACHE_HOME", "/", 1);
	UT_VERIFY( STR_EQUAL(user_cache_dir(), "/") );

	edelib_setenv("XDG_CACHE_HOME", "/home/foo", 1);
	UT_VERIFY( STR_EQUAL(user_cache_dir(), "/home/foo") );
	edelib_unsetenv("XDG_CACHE_HOME");
Exemple #21
0
static bool recurrence_initialize_rrule_ical(const char* str, RRule* rrule)
{
  int i;
  char** strv = strsplit(str, ';');

  rrule->interval = 1;

  for (i = 0; strv[i]; i++)
  {
    char** pair = strsplit(strv[i], '=');
    if (!pair[0] || !pair[1])
    {
      synce_warning("Invalid rrule part: '%s'", strv[i]);
      continue;
    }

    synce_trace("RRULE part: key=%s, value=%s", 
        pair[0], pair[1]);

    if (STR_EQUAL(pair[0], "BYDAY"))
      replace_string_with_copy(&rrule->byday, pair[1]);
    else if (STR_EQUAL(pair[0], "BYMONTH"))
      rrule->bymonth = atoi(pair[1]);
    else if (STR_EQUAL(pair[0], "BYMONTHDAY"))
      rrule->bymonthday = atoi(pair[1]);
    else if (STR_EQUAL(pair[0], "BYSETPOS"))
      rrule->bysetpos = atoi(pair[1]);
    else if (STR_EQUAL(pair[0], "COUNT"))
      rrule->count = atoi(pair[1]);
    else if (STR_EQUAL(pair[0], "FREQ"))
      {
	if (STR_EQUAL(pair[1], "DAILY"))
	  rrule->freq = RRuleDaily;
	else if (STR_EQUAL(pair[1], "WEEKLY"))
	  rrule->freq = RRuleWeekly;
	else if (STR_EQUAL(pair[1], "MONTHLY"))
	  rrule->freq = RRuleMonthly;
	else if (STR_EQUAL(pair[1], "YEARLY"))
	  rrule->freq = RRuleYearly;
	else
	  synce_error("Unexpected frequencey in RRULE '%s'", str);
      }
    else if (STR_EQUAL(pair[0], "INTERVAL"))
      rrule->interval = atoi(pair[1]);
    else if (STR_EQUAL(pair[0], "UNTIL"))
      replace_string_with_copy(&rrule->until, pair[1]);
    else
      synce_warning("Unhandled part of RRULE: '%s'", strv[i]);

    strv_free(pair);
  }
  
  strv_free(strv);
  return true;
}
Exemple #22
0
#include <edelib/StrUtil.h>
#include <edelib/List.h>
#include <string.h>
#include "UnitTest.h"

EDELIB_NS_USE

#define CCHARP(str)           ((const char*)str)
#define STR_EQUAL(str1, str2) (strcmp(CCHARP(str1), CCHARP(str2)) == 0)

UT_FUNC(strtest, "Test strutil")
{
	unsigned char s1[] = "StRiNG1";
	UT_VERIFY( STR_EQUAL("string1", str_tolower(s1)) );

	unsigned char s2[] = "some Sample Of sTrinG";
	UT_VERIFY( STR_EQUAL("some sample of string", str_tolower(s2)) );

	unsigned char s3[] = "sTRinG2";
	UT_VERIFY( STR_EQUAL("STRING2", str_toupper(s3)) );

	unsigned char s4[] = "xxx AbA BbCCbBc xxx !@# . Abb";
	UT_VERIFY( STR_EQUAL("XXX ABA BBCCBBC XXX !@# . ABB", str_toupper(s4)) );

	char s5[] = "  some with spaces";
	UT_VERIFY( STR_EQUAL("some with spaces", str_trimleft(s5)) );

	char s6[] = "				  some with spaces";
	UT_VERIFY( STR_EQUAL("some with spaces", str_trimleft(s6)) );

	char s6a[] = "|				some with spaces";