oval_component.c | oval_component.c | |||
---|---|---|---|---|
skipping to change at line 28 | skipping to change at line 28 | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | * Lesser General Public License for more details. | |||
* | * | |||
* You should have received a copy of the GNU Lesser General Public | * You should have received a copy of the GNU Lesser General Public | |||
* License along with this library; if not, write to the Free Software | * License along with this library; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US A | |||
* | * | |||
* Authors: | * Authors: | |||
* "David Niemoller" <David.Niemoller@g2-inc.com> | * "David Niemoller" <David.Niemoller@g2-inc.com> | |||
* "Peter Vrabec" <pvabec@redhat.com> | * "Peter Vrabec" <pvrabec@redhat.com> | |||
* "Tomas Heinrich" <theinric@redhat.com> | * "Tomas Heinrich" <theinric@redhat.com> | |||
* "Daniel Kopecek" <dkopecek@redhat.com> | ||||
*/ | */ | |||
#ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H | |||
#include <config.h> | #include <config.h> | |||
#endif | #endif | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <string.h> | #include <string.h> | |||
#include <time.h> | #include <time.h> | |||
skipping to change at line 899 | skipping to change at line 900 | |||
return oval_value_parse_tag(reader, context, oval_value_consume, com ponent); | return oval_value_parse_tag(reader, context, oval_value_consume, com ponent); | |||
} | } | |||
static int _oval_component_parse_OBJECTREF_tag(xmlTextReaderPtr reader, | static int _oval_component_parse_OBJECTREF_tag(xmlTextReaderPtr reader, | |||
struct oval_parser_context *c ontext, struct oval_component *component) | struct oval_parser_context *c ontext, struct oval_component *component) | |||
{ | { | |||
struct oval_definition_model *model = context->definition_model; | struct oval_definition_model *model = context->definition_model; | |||
char *objref = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "o bject_ref"); | char *objref = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "o bject_ref"); | |||
struct oval_object *object = oval_object_get_new(model, objref); | struct oval_object *object = oval_definition_model_get_new_object(mo del, objref); | |||
char *field; | char *field; | |||
oscap_free(objref); | oscap_free(objref); | |||
objref = NULL; | objref = NULL; | |||
oval_component_set_object(component, object); | oval_component_set_object(component, object); | |||
field = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "item_fie ld"); | field = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "item_fie ld"); | |||
oval_component_set_item_field(component, field); | oval_component_set_item_field(component, field); | |||
if (field) | if (field) | |||
oscap_free(field); | oscap_free(field); | |||
skipping to change at line 924 | skipping to change at line 925 | |||
return 0; | return 0; | |||
} | } | |||
static int _oval_component_parse_VARREF_tag(xmlTextReaderPtr reader, | static int _oval_component_parse_VARREF_tag(xmlTextReaderPtr reader, | |||
struct oval_parser_context *cont ext, struct oval_component *component) | struct oval_parser_context *cont ext, struct oval_component *component) | |||
{ | { | |||
struct oval_definition_model *model = context->definition_model; | struct oval_definition_model *model = context->definition_model; | |||
char *varref = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "v ar_ref"); | char *varref = (char *)xmlTextReaderGetAttribute(reader, BAD_CAST "v ar_ref"); | |||
struct oval_variable *variable = oval_variable_get_new(model, varref , OVAL_VARIABLE_UNKNOWN); | struct oval_variable *variable = oval_definition_model_get_new_varia ble(model, varref, OVAL_VARIABLE_UNKNOWN); | |||
if (varref != NULL) { | if (varref != NULL) { | |||
oscap_free(varref); | oscap_free(varref); | |||
varref = NULL; | varref = NULL; | |||
} | } | |||
oval_component_set_variable(component, variable); | oval_component_set_variable(component, variable); | |||
return 0; | return 0; | |||
} | } | |||
static void oval_subcomp_consume(struct oval_component *subcomp, void *func ) | static void oval_subcomp_consume(struct oval_component *subcomp, void *func ) | |||
skipping to change at line 1423 | skipping to change at line 1424 | |||
if (oval_component_iterator_has_more(subcomps)) { /*on ly the first component is processed */ | if (oval_component_iterator_has_more(subcomps)) { /*on ly the first component is processed */ | |||
struct oval_collection *subcoll = oval_collection_ne w(); | struct oval_collection *subcoll = oval_collection_ne w(); | |||
struct oval_component *subcomp = oval_component_iter ator_next(subcomps); | struct oval_component *subcomp = oval_component_iter ator_next(subcomps); | |||
flag = oval_component_eval_common(argu, subcomp, sub coll); | flag = oval_component_eval_common(argu, subcomp, sub coll); | |||
struct oval_value_iterator *values = | struct oval_value_iterator *values = | |||
(struct oval_value_iterator *)oval_collection_it erator(subcoll); | (struct oval_value_iterator *)oval_collection_it erator(subcoll); | |||
while (oval_value_iterator_has_more(values)) { | while (oval_value_iterator_has_more(values)) { | |||
char *key = oval_value_get_text(oval_value_i terator_next(values)); | char *key = oval_value_get_text(oval_value_i terator_next(values)); | |||
int len_key = strlen(key); | int len_key = strlen(key); | |||
char concat[len_suffix + len_key + 1]; | char concat[len_suffix + len_key + 1]; | |||
if ((len_suffix <= len_key) && strncmp(suffi x, key + len_key - len_suffix, len_suffix)) { | if ((len_suffix > len_key) || strncmp(suffix , key + len_key - len_suffix, len_suffix)) { | |||
snprintf(concat, sizeof(concat), "%s %s", key, suffix); | snprintf(concat, sizeof(concat), "%s %s", key, suffix); | |||
} else { | } else { | |||
snprintf(concat, sizeof(concat), "%s ", key); | snprintf(concat, sizeof(concat), "%s ", key); | |||
} | } | |||
struct oval_value *concat_value = oval_value _new(OVAL_DATATYPE_STRING, concat); | struct oval_value *concat_value = oval_value _new(OVAL_DATATYPE_STRING, concat); | |||
oval_collection_add(value_collection, concat _value); | oval_collection_add(value_collection, concat _value); | |||
} | } | |||
oval_value_iterator_free(values); | oval_value_iterator_free(values); | |||
oval_collection_free_items(subcoll, (oscap_destruct_ func) oval_value_free); | oval_collection_free_items(subcoll, (oscap_destruct_ func) oval_value_free); | |||
} | } | |||
skipping to change at line 1619 | skipping to change at line 1620 | |||
flag = SYSCHAR_FLAG_ERROR; | flag = SYSCHAR_FLAG_ERROR; | |||
} | } | |||
} | } | |||
oval_value_iterator_free(values); | oval_value_iterator_free(values); | |||
oval_collection_free_items(subcoll, (oscap_destruct_func) ov al_value_free); | oval_collection_free_items(subcoll, (oscap_destruct_func) ov al_value_free); | |||
} | } | |||
oval_component_iterator_free(subcomps); | oval_component_iterator_free(subcomps); | |||
return flag; | return flag; | |||
} | } | |||
static int _substr2i(char **s, int len) | ||||
{ | ||||
char buf[len + 1]; | ||||
memcpy(buf, *s, len); | ||||
buf[len] = '\0'; | ||||
*s += len; | ||||
return atoi(buf); | ||||
} | ||||
static int _substr2mon(char **sp) | ||||
{ | ||||
int m = 0; | ||||
size_t len; | ||||
char *s = *sp; | ||||
len = strcspn(s, "0123456789,"); | ||||
if (len == 0) | ||||
return -1; | ||||
*sp += len; | ||||
if (!strncasecmp(s, "jan", len) || !strncasecmp(s, "january", len)) | ||||
{ | ||||
m = 1; | ||||
} else if (!strncasecmp(s, "feb", len) || !strncasecmp(s, "february" | ||||
, len)) { | ||||
m = 2; | ||||
} else if (!strncasecmp(s, "mar", len) || !strncasecmp(s, "march", l | ||||
en)) { | ||||
m = 3; | ||||
} else if (!strncasecmp(s, "apr", len) || !strncasecmp(s, "april", l | ||||
en)) { | ||||
m = 4; | ||||
} else if (!strncasecmp(s, "may", len)) { | ||||
m = 5; | ||||
} else if (!strncasecmp(s, "jun", len) || !strncasecmp(s, "june", le | ||||
n)) { | ||||
m = 6; | ||||
} else if (!strncasecmp(s, "jul", len) || !strncasecmp(s, "july", le | ||||
n)) { | ||||
m = 7; | ||||
} else if (!strncasecmp(s, "aug", len) || !strncasecmp(s, "august", | ||||
len)) { | ||||
m = 8; | ||||
} else if (!strncasecmp(s, "sep", len) || !strncasecmp(s, "september | ||||
", len)) { | ||||
m = 9; | ||||
} else if (!strncasecmp(s, "oct", len) || !strncasecmp(s, "october", | ||||
len)) { | ||||
m = 10; | ||||
} else if (!strncasecmp(s, "nov", len) || !strncasecmp(s, "november" | ||||
, len)) { | ||||
m = 11; | ||||
} else if (!strncasecmp(s, "dec", len) || !strncasecmp(s, "december" | ||||
, len)) { | ||||
m = 12; | ||||
} | ||||
return m; | ||||
} | ||||
static long unsigned int _comp_sec(int year, int month, int day, int hour, int minute, int second) | static long unsigned int _comp_sec(int year, int month, int day, int hour, int minute, int second) | |||
{ | { | |||
time_t t; | time_t t; | |||
struct tm *ts; | struct tm *ts; | |||
t = time(NULL); | t = time(NULL); | |||
ts = localtime(&t); | ts = localtime(&t); | |||
ts->tm_year = year - 1900; | ts->tm_year = year - 1900; | |||
ts->tm_mon = month - 1; | ts->tm_mon = month - 1; | |||
skipping to change at line 1696 | skipping to change at line 1645 | |||
t = mktime(ts); | t = mktime(ts); | |||
ts = localtime(&t); | ts = localtime(&t); | |||
if (ts->tm_isdst == 1) | if (ts->tm_isdst == 1) | |||
t -= 3600; | t -= 3600; | |||
return (long unsigned int) t; | return (long unsigned int) t; | |||
} | } | |||
/* | /* | |||
year_month_day | * year_month_day | |||
The year_month_day value specifies date-time strings that follow the format | * The year_month_day value specifies date-time strings that follow the for | |||
s: | mats: | |||
'yyyymmdd', 'yyyymmddThhmmss', 'yyyy/mm/dd hh:mm:ss', 'yyyy/mm/dd', 'yyyy | * | |||
-mm-dd hh:mm:ss', or 'yyyy-mm-dd' | * strptime(3) | |||
*/ | */ | |||
static long unsigned int _parse_fmt_ymd(char *dt) | static const char *_dtfmt_ymd[] = { | |||
{ | "%Y%m%d", /* yyyymmdd */ | |||
int year, month, day, hour, minute, second; | "%Y/%m/%d", /* yyyy/mm/dd */ | |||
"%Y-%m-%d", /* yyyy-mm-dd */ | ||||
year = _substr2i(&dt, 4); | "%Y%m%dT%H%M%S", /* yyyymmddThhmmss */ | |||
if (*dt == '/' || *dt == '-') | "%Y/%m/%d%n%T", /* yyyy/mm/dd hh:mm:ss */ | |||
dt++; | "%Y-%m-%d%n%T" /* yyyy-mm-dd hh:mm:ss */ | |||
month = _substr2i(&dt, 2); | }; | |||
if (*dt == '/' || *dt == '-') | ||||
dt++; | ||||
day = _substr2i(&dt, 2); | ||||
if (*dt == '\0') { | ||||
hour = minute = second = 0; | ||||
} else if (*dt == 'T') { | ||||
dt++; | ||||
hour = _substr2i(&dt, 2); | ||||
minute = _substr2i(&dt, 2); | ||||
second = _substr2i(&dt, 2); | ||||
} else { | ||||
dt++; | ||||
hour = _substr2i(&dt, 2); | ||||
dt++; | ||||
minute = _substr2i(&dt, 2); | ||||
dt++; | ||||
second = _substr2i(&dt, 2); | ||||
} | ||||
return _comp_sec(year, month, day, hour, minute, second); | ||||
} | ||||
/* | /* | |||
month_day_year | * month_day_year | |||
The month_day_year value specifies date-time strings that follow the format | * The month_day_year value specifies date-time strings that follow the for | |||
s: | mats: | |||
'mm/dd/yyyy hh:mm:ss', 'mm/dd/yyyy', 'mm-dd-yyyy hh:mm:ss', 'mm-dd-yyyy', | * | |||
'NameOfMonth, dd yyyy hh:mm:ss' or | * strptime(3) | |||
'NameOfMonth, dd yyyy','AbreviatedNameOfMonth, dd yyyy hh:mm:ss', or 'Abr | */ | |||
eviatedNameOfMonth, dd yyyy' | static const char *_dtfmt_mdy[] = { | |||
*/ | "%m/%d/%Y", /* mm/dd/yyyy */ | |||
static long unsigned int _parse_fmt_mdy(char *dt) | "%m-%d-%Y", /* mm-dd-yyyy */ | |||
{ | "%b,%n%d%n%Y", /* AbreviatedNameOfMonth, dd yyyy */ | |||
int year, month, day, hour, minute, second; | "%m/%d/%Y%n%T", /* mm/dd/yyyy hh:mm:ss */ | |||
"%m-%d-%Y%n%T", /* mm-dd-yyyy hh:mm:ss */ | ||||
if ((month = _substr2mon(&dt)) == -1) { | "%b,%n%d%n%Y%n%T" /* NameOfMonth, dd yyyy hh:mm:ss & AbreviatedName | |||
month = _substr2i(&dt, 2); | OfMonth, dd yyyy hh:mm:ss */ | |||
dt++; | }; | |||
} else { | ||||
dt += 2; | ||||
} | ||||
day = _substr2i(&dt, 2); | ||||
dt++; | ||||
year = _substr2i(&dt, 4); | ||||
if (*dt == '\0') { | ||||
hour = minute = second = 0; | ||||
} else { | ||||
dt++; | ||||
hour = _substr2i(&dt, 2); | ||||
dt++; | ||||
minute = _substr2i(&dt, 2); | ||||
dt++; | ||||
second = _substr2i(&dt, 2); | ||||
} | ||||
return _comp_sec(year, month, day, hour, minute, second); | ||||
} | ||||
/* | /* | |||
day_month_year | * day_month_year | |||
The day_month_year value specifies date-time strings that follow the format | * The day_month_year value specifies date-time strings that follow the for | |||
s: | mats: | |||
'dd/mm/yyyy hh:mm:ss', 'dd/mm/yyyy', 'dd-mm-yyyy hh:mm:ss', or 'dd-mm-yyy | * | |||
y' | * strptime(3) | |||
*/ | */ | |||
static long unsigned int _parse_fmt_dmy(char *dt) | static const char *_dtfmt_dmy[] = { | |||
{ | "%d/%m/%Y", /* dd/mm/yyyy */ | |||
int year, month, day, hour, minute, second; | "%d-%m-%Y", /* dd-mm-yyyy */ | |||
"%d/%m/%Y%n%T", /* dd/mm/yyyy hh:mm:ss */ | ||||
day = _substr2i(&dt, 2); | "%d-%m-%Y%n%T" /* dd-mm-yyyy hh:mm:ss */ | |||
dt++; | }; | |||
month = _substr2i(&dt, 2); | ||||
dt++; | ||||
year = _substr2i(&dt, 4); | ||||
if (*dt == '\0') { | static long unsigned int _parse_datetime(char *datetime, const char *fmt[], | |||
hour = minute = second = 0; | size_t fmtcnt) | |||
} else { | { | |||
dt++; | struct tm t; | |||
hour = _substr2i(&dt, 2); | size_t i; | |||
dt++; | char *r; | |||
minute = _substr2i(&dt, 2); | ||||
dt++; | dI("Parsing datetime string \"%s\"\n", datetime); | |||
second = _substr2i(&dt, 2); | ||||
} | for (i = 0; i < fmtcnt; ++i) { | |||
dI("%s\n", fmt[i]); | ||||
memset(&t, 0, sizeof t); | ||||
r = strptime(datetime, fmt[i], &t); | ||||
if (r != NULL) { | ||||
if (*r == '\0') { | ||||
dI("Success!\n"); | ||||
return _comp_sec(t.tm_year, t.tm_mon, t.tm_ | ||||
mday, | ||||
t.tm_hour, t.tm_min, t.tm_ | ||||
sec); | ||||
} | ||||
} | ||||
} | ||||
dE("Unable to interpret \"%s\" as a datetime string\n"); | ||||
return _comp_sec(year, month, day, hour, minute, second); | return (0); | |||
} | } | |||
static long unsigned int _parse_fmt_win(char *dt) | static long unsigned int _parse_fmt_win(char *dt) | |||
{ | { | |||
// todo | // todo | |||
return 0; | return 0; | |||
} | } | |||
static long unsigned int _parse_fmt_sse(char *dt) | static long unsigned int _parse_fmt_sse(char *dt) | |||
{ | { | |||
skipping to change at line 1823 | skipping to change at line 1742 | |||
static long unsigned int _parse_fmt(struct oval_value *val, oval_datetime_f ormat_t fmt) | static long unsigned int _parse_fmt(struct oval_value *val, oval_datetime_f ormat_t fmt) | |||
{ | { | |||
long unsigned int v = 0; | long unsigned int v = 0; | |||
char *sv; | char *sv; | |||
sv = oval_value_get_text(val); | sv = oval_value_get_text(val); | |||
switch (fmt) { | switch (fmt) { | |||
case OVAL_DATETIME_YEAR_MONTH_DAY: | case OVAL_DATETIME_YEAR_MONTH_DAY: | |||
v = _parse_fmt_ymd(sv); | v = _parse_datetime(sv, _dtfmt_ymd, sizeof _dtfmt_ymd/sizeo f(char *)); | |||
break; | break; | |||
case OVAL_DATETIME_MONTH_DAY_YEAR: | case OVAL_DATETIME_MONTH_DAY_YEAR: | |||
v = _parse_fmt_mdy(sv); | v = _parse_datetime(sv, _dtfmt_mdy, sizeof _dtfmt_mdy/sizeo f(char *)); | |||
break; | break; | |||
case OVAL_DATETIME_DAY_MONTH_YEAR: | case OVAL_DATETIME_DAY_MONTH_YEAR: | |||
v = _parse_fmt_dmy(sv); | v = _parse_datetime(sv, _dtfmt_dmy, sizeof _dtfmt_dmy/sizeo f(char *)); | |||
break; | break; | |||
case OVAL_DATETIME_WIN_FILETIME: | case OVAL_DATETIME_WIN_FILETIME: | |||
v = _parse_fmt_win(sv); | v = _parse_fmt_win(sv); | |||
break; | break; | |||
case OVAL_DATETIME_SECONDS_SINCE_EPOCH: | case OVAL_DATETIME_SECONDS_SINCE_EPOCH: | |||
v = _parse_fmt_sse(sv); | v = _parse_fmt_sse(sv); | |||
break; | break; | |||
default: | default: | |||
break; | break; | |||
} | } | |||
skipping to change at line 2050 | skipping to change at line 1969 | |||
oscap_free(nval); | oscap_free(nval); | |||
} else { | } else { | |||
value = oval_value_new(OVAL_DATATYPE_STRING, ""); | value = oval_value_new(OVAL_DATATYPE_STRING, ""); | |||
} | } | |||
oval_collection_add(value_collection, value); | oval_collection_add(value_collection, value); | |||
} | } | |||
oval_value_iterator_free(values); | oval_value_iterator_free(values); | |||
oval_collection_free_items(subcoll, (oscap_destruct_func) ov al_value_free); | oval_collection_free_items(subcoll, (oscap_destruct_func) ov al_value_free); | |||
} | } | |||
oval_component_iterator_free(subcomps); | oval_component_iterator_free(subcomps); | |||
#if defined USE_REGEX_PCRE | ||||
pcre_free(re); | ||||
#endif | ||||
return flag; | return flag; | |||
} | } | |||
struct val_col_lst_s { | struct val_col_lst_s { | |||
void *val_col; | void *val_col; | |||
struct val_col_lst_s *next; | struct val_col_lst_s *next; | |||
}; | }; | |||
static oval_syschar_collection_flag_t _oval_component_evaluate_ARITHMETIC_r ec(struct val_col_lst_s *val_col_lst, double val, | static oval_syschar_collection_flag_t _oval_component_evaluate_ARITHMETIC_r ec(struct val_col_lst_s *val_col_lst, double val, | |||
oval_datatype_t datatype , oval_arithmetic_operation_t op, | oval_datatype_t datatype , oval_arithmetic_operation_t op, | |||
End of changes. 15 change blocks. | ||||
168 lines changed or deleted | 79 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |