char* icalreqstattype_as_string_r(struct icalreqstattype stat) { char *temp; icalerror_check_arg_rz((stat.code != ICAL_UNKNOWN_STATUS),"Status"); temp = (char*)icalmemory_new_buffer(TEMP_MAX); if (stat.desc == 0){ stat.desc = icalenum_reqstat_desc(stat.code); } if(stat.debug != 0){ snprintf(temp,TEMP_MAX,"%d.%d;%s;%s", icalenum_reqstat_major(stat.code), icalenum_reqstat_minor(stat.code), stat.desc, stat.debug); } else { snprintf(temp,TEMP_MAX,"%d.%d;%s", icalenum_reqstat_major(stat.code), icalenum_reqstat_minor(stat.code), stat.desc); } return temp; }
char* icalperiodtype_as_ical_string_r(struct icalperiodtype p) { const char* start; const char* end; char *buf; size_t buf_size = 40; char* buf_ptr = 0; buf = (char*)icalmemory_new_buffer(buf_size); buf_ptr = buf; start = icaltime_as_ical_string_r(p.start); icalmemory_append_string(&buf, &buf_ptr, &buf_size, start); icalmemory_free_buffer(start); if(!icaltime_is_null_time(p.end)) { end = icaltime_as_ical_string_r(p.end); } else { end = icaldurationtype_as_ical_string_r(p.duration); } icalmemory_append_char(&buf, &buf_ptr, &buf_size, '/'); icalmemory_append_string(&buf, &buf_ptr, &buf_size, end); icalmemory_free_buffer(end); return buf; }
char* icaldurationtype_as_ical_string(struct icaldurationtype d) { char *buf, *output_line; size_t buf_size = 256; char* buf_ptr = 0; int seconds; buf = (char*)icalmemory_new_buffer(buf_size); buf_ptr = buf; seconds = icaldurationtype_as_int(d); if(seconds !=0){ if(d.is_neg == 1){ icalmemory_append_char(&buf, &buf_ptr, &buf_size, '-'); } icalmemory_append_char(&buf, &buf_ptr, &buf_size, 'P'); if (d.weeks != 0 ) { append_duration_segment(&buf, &buf_ptr, &buf_size, "W", d.weeks); } if (d.days != 0 ) { append_duration_segment(&buf, &buf_ptr, &buf_size, "D", d.days); } if (d.hours != 0 || d.minutes != 0 || d.seconds != 0) { icalmemory_append_string(&buf, &buf_ptr, &buf_size, "T"); if (d.hours != 0 ) { append_duration_segment(&buf, &buf_ptr, &buf_size, "H", d.hours); } if (d.minutes != 0 ) { append_duration_segment(&buf, &buf_ptr, &buf_size, "M", d.minutes); } if (d.seconds != 0 ) { append_duration_segment(&buf, &buf_ptr, &buf_size, "S", d.seconds); } } } else { icalmemory_append_string(&buf, &buf_ptr, &buf_size, "PT0S"); } output_line = icalmemory_tmp_copy(buf); icalmemory_free_buffer(buf); return output_line; }
char *icallangbind_quote_as_ical_r(const char *str) { size_t buf_size = 2 * strlen(str); /* assume every char could be quoted */ char *buf = icalmemory_new_buffer(buf_size); (void)icalvalue_encode_ical_string(str, buf, (int)buf_size); return buf; }
const char* icallangbind_quote_as_ical(const char* str) { size_t buf_size = 2 * strlen(str); /* assume every char could be quoted */ char* buf = icalmemory_new_buffer(buf_size); int result; result = icalvalue_encode_ical_string(str, buf, buf_size); icalmemory_add_tmp_buffer(buf); return buf; }
/** make a new tmp buffer out of a substring */ static char *make_segment(char *start, char *end) { char *buf, *tmp; ptrdiff_t size = (ptrdiff_t)(end - start); buf = icalmemory_new_buffer((size_t)(size + 1)); strncpy(buf, start, size); *(buf + size) = 0; tmp = (buf + size); while ((tmp >= buf) && ((*tmp == '\0') || iswspace((wint_t)*tmp))) { *tmp = 0; tmp--; } return buf; }
void* icalmime_text_new_part(void) { #define BUF_SIZE 2048 struct text_part* impl; if ( ( impl = (struct text_part*) malloc(sizeof(struct text_part))) == 0) { return 0; } impl->buf = icalmemory_new_buffer(BUF_SIZE); impl->buf_pos = impl->buf; impl->buf_size = BUF_SIZE; return impl; }
/** make a new tmp buffer out of a substring */ static char* make_segment(char* start, char* end) { char *buf, *tmp; size_t size = (size_t)end - (size_t)start; buf = icalmemory_new_buffer(size+1); strncpy(buf,start,size); *(buf+size) = 0; tmp = (buf+size); while ((tmp >= buf) && ((*tmp == '\0') || iswspace(*tmp))) { *tmp = 0; tmp--; } return buf; }
/** * Return a string represention of the time, in RFC5545 format. The * string is owned by libical */ char *icaltime_as_ical_string_r(const struct icaltimetype tt) { size_t size = 17; char *buf = icalmemory_new_buffer(size); if (tt.is_date) { snprintf(buf, size, "%04d%02d%02d", tt.year, tt.month, tt.day); } else { const char *fmt; if (tt.is_utc) { fmt = "%04d%02d%02dT%02d%02d%02dZ"; } else { fmt = "%04d%02d%02dT%02d%02d%02d"; } snprintf(buf, size, fmt, tt.year, tt.month, tt.day, tt.hour, tt.minute, tt.second); } return buf; }
char *icallangbind_property_eval_string_r(icalproperty *prop, char *sep) { char tmp[25]; size_t buf_size = 1024; char *buf; char *buf_ptr; icalparameter *param; icalvalue *value; if (prop == 0) { return 0; } buf = icalmemory_new_buffer(buf_size); buf_ptr = buf; APPENDS("{ "); value = icalproperty_get_value(prop); APPENDS(" 'name' "); APPENDS(sep); APPENDC('\''); APPENDS(icalproperty_kind_to_string(icalproperty_isa(prop))); APPENDC('\''); if (value) { APPENDS(", 'value_type' "); APPENDS(sep); APPENDC('\''); APPENDS(icalvalue_kind_to_string(icalvalue_isa(value))); APPENDC('\''); } APPENDS(", 'pid' "); APPENDS(sep); APPENDC('\''); snprintf(tmp, 25, "%p", prop); APPENDS(tmp); APPENDC('\''); if (value) { switch (icalvalue_isa(value)) { case ICAL_ATTACH_VALUE: case ICAL_BINARY_VALUE: case ICAL_NO_VALUE:{ icalerror_set_errno(ICAL_INTERNAL_ERROR); break; } default: { char *str = icalvalue_as_ical_string_r(value); char *copy = (char *)malloc(strlen(str) + 1); const char *i; char *j; if (copy == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); break; } /* Remove any newlines */ for (j = copy, i = str; *i != 0; j++, i++) { if (*i == '\n') { i++; } *j = *i; } *j = 0; APPENDS(", 'value'"); APPENDS(sep); APPENDC('\''); APPENDS(copy); APPENDC('\''); free(copy); free(str); break; } } } /* Add Parameters */ for (param = icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER); param != 0; param = icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER)) { char *copy = icalparameter_as_ical_string_r(param); char *v; if (copy == 0) { icalerror_set_errno(ICAL_NEWFAILED_ERROR); continue; } v = strchr(copy, '='); if (v == 0) { free(copy); continue; } *v = 0; v++; APPENDS(", "); APPENDC('\''); APPENDS(copy); APPENDC('\''); APPENDS(sep); APPENDC('\''); APPENDS(v); APPENDC('\''); free(copy); } APPENDC('}'); return buf; }
/** * Get a single property line, from the property name through the * final new line, and include any continuation lines */ char *icalparser_get_line(icalparser *parser, icalparser_line_gen_func line_gen_func) { char *line; char *line_p; size_t buf_size = parser->tmp_buf_size; line_p = line = icalmemory_new_buffer(buf_size); line[0] = '\0'; /* Read lines by calling line_gen_func and putting the data into parser->temp. If the line is a continuation line ( begins with a space after a newline ) then append the data onto line and read again. Otherwise, exit the loop. */ while (1) { /* The first part of the loop deals with the temp buffer, which was read on he last pass through the loop. The routine is split like this because it has to read lone line ahead to determine if a line is a continuation line. */ /* The tmp buffer is not clear, so transfer the data in it to the output. This may be left over from a previous call */ if (parser->temp[0] != '\0') { /* If the last position in the temp buffer is occupied, mark the buffer as full. The means we will do another read later, because the line is not finished */ if (parser->temp[parser->tmp_buf_size - 1] == 0 && parser->temp[parser->tmp_buf_size - 2] != '\n' && parser->temp[parser->tmp_buf_size - 2] != 0) { parser->buffer_full = 1; } else { parser->buffer_full = 0; } /* Copy the temp to the output and clear the temp buffer. */ if (parser->continuation_line == 1) { /* back up the pointer to erase the continuation characters */ parser->continuation_line = 0; line_p--; if (*(line_p - 1) == '\r') { line_p--; } /* copy one space up to eliminate the leading space */ icalmemory_append_string(&line, &line_p, &buf_size, parser->temp + 1); } else { icalmemory_append_string(&line, &line_p, &buf_size, parser->temp); } parser->temp[0] = '\0'; } parser->temp[parser->tmp_buf_size - 1] = 1; /* Mark end of buffer */ /****** Here is where the routine gets string data ******************/ if ((*line_gen_func) (parser->temp, parser->tmp_buf_size, parser->line_gen_data) == 0) { /* Get more data */ /* If the first position is clear, it means we didn't get any more data from the last call to line_ge_func */ if (parser->temp[0] == '\0') { if (line[0] != '\0') { /* There is data in the output, so fall trhough and process it */ break; } else { /* No data in output; return and signal that there is no more input */ free(line); return 0; } } } /* If the output line ends in a '\n' and the temp buffer begins with a ' ' or tab, then the buffer holds a continuation line, so keep reading. RFC 5545, section 3.1 */ if (line_p > line + 1 && *(line_p - 1) == '\n' && (parser->temp[0] == ' ' || parser->temp[0] == '\t')) { parser->continuation_line = 1; } else if (parser->buffer_full == 1) { /* The buffer was filled on the last read, so read again */ } else { /* Looks like the end of this content line, so break */ break; } } /* Erase the final newline and/or carriage return */ if (line_p > line + 1 && *(line_p - 1) == '\n') { *(line_p - 1) = '\0'; if (*(line_p - 2) == '\r') { *(line_p - 2) = '\0'; } } else { *(line_p) = '\0'; } while ((*line_p == '\0' || iswspace((wint_t) * line_p)) && line_p > line) { *line_p = '\0'; line_p--; } return line; }