On 05/17/2012 09:45 AM, Nikola Pajkovsky wrote:
Jiri Moskovcak<jmoskovc(a)redhat.com> writes:
> On 05/16/2012 04:23 PM, Nikola Pajkovsky wrote:
>> Signed-off-by: Nikola Pajkovsky<npajkovs(a)redhat.com>
>> ---
>> src/plugins/reporter-bugzilla.c | 6 ++----
>> src/plugins/rhbz.c | 26 +++++++++++++++++++++-----
>> src/plugins/rhbz.h | 6 ++++--
>> 3 files changed, 27 insertions(+), 11 deletions(-)
>>
>> diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
>> index 3b6d168..9746301 100644
>> --- a/src/plugins/reporter-bugzilla.c
>> +++ b/src/plugins/reporter-bugzilla.c
>> @@ -168,10 +168,9 @@ int main(int argc, char **argv)
>> int all_bugs_size = rhbz_array_size(all_bugs);
>> if (all_bugs_size> 0)
>> {
>> - char *rhbz_ver = rhbz_version(client);
>> + size_t rhbz_ver = rhbz_version(client);
>> int bug_id = rhbz_bug_id(all_bugs, rhbz_ver);
>> printf("%i", bug_id);
>> - free(rhbz_ver);
>> }
>>
>> exit(EXIT_SUCCESS);
>> @@ -359,11 +358,10 @@ int main(int argc, char **argv)
>> }
>> else
>> {
>> - char *rhbz_ver = rhbz_version(client);
>> + size_t rhbz_ver = rhbz_version(client);
>> int bug_id = rhbz_bug_id(all_bugs, rhbz_ver);
>> xmlrpc_DECREF(all_bugs);
>> bz = rhbz_bug_info(client, bug_id);
>> - free(rhbz_ver);
>> }
>> }
>> else
>> diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
>> index df2838f..c685ef2 100644
>> --- a/src/plugins/rhbz.c
>> +++ b/src/plugins/rhbz.c
>> @@ -244,7 +244,7 @@ int rhbz_array_size(xmlrpc_value *xml)
>> }
>>
>>
>> -char *rhbz_version(struct abrt_xmlrpc *ax)
>> +size_t rhbz_version(struct abrt_xmlrpc *ax)
>> {
>> func_entry();
>>
>> @@ -258,11 +258,27 @@ char *rhbz_version(struct abrt_xmlrpc *ax)
>> xmlrpc_DECREF(result);
>> }
>>
>> - return version;
>> + strchrnul(version, '-')[0] = '\0';
>> +
>> + /* format must be x.y.z */
>
> - the code parses only first two numbers, so I guess you mean:
> /* format must be x.y ? */
nope it's parse x.y.z, see the stroul after for cycle
- ah, right, I missed that one call after the cycle
>> + char *vp, *tmp = version;
>> + int i = 0, v[3];
>> + for ( ; i< 2 ; ++i)
>> + {
>> + vp = strchr(tmp, '.');
>> + *vp++ = '\0';
>
> - the code should be more robust, what happens if the the version is
> not in the right format e.g: "5"
> - the rest seems ok
format "5"? I don't get it.
- what happen when you don't get the number in format x.y.z, but only x
? I smell SEGV on the line *vp++ = '\0';
>> + v[i] = strtoul(tmp, NULL, 10);
>> + tmp = vp;
>> + }
>> + v[i] = strtoul(tmp, NULL, 10);
>> +
>> + free(version);
>> +
>> + return BUGZILLA_VERSION(v[0], v[1], v[2]);
>> }
>>
>> /* die or return bug id; each bug must have bug id otherwise xml is corrupted
*/
>> -int rhbz_bug_id(xmlrpc_value* xml, const char *ver)
>> +int rhbz_bug_id(xmlrpc_value* xml, size_t ver)
>> {
>> func_entry();
>>
>> @@ -277,8 +293,8 @@ int rhbz_bug_id(xmlrpc_value* xml, const char *ver)
>> if (env.fault_occurred)
>> abrt_xmlrpc_die(&env);
>>
>> - char *id;
>> - if (!prefixcmp(ver, "4.2"))
>> + const char *id;
>> + if (ver>= BUGZILLA_VERSION(4,2,0))
>> id = "id";
>> else
>> id = "bug_id";
>> diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h
>> index 85bcca1..84e0ba0 100644
>> --- a/src/plugins/rhbz.h
>> +++ b/src/plugins/rhbz.h
>> @@ -30,6 +30,8 @@
>> extern "C" {
>> #endif
>>
>> +#define BUGZILLA_VERSION(a,b,c) (((a)<< 16) + ((b)<< 8) + (c))
>> +
>> enum {
>> RHBZ_MANDATORY_MEMB = (1<< 0),
>> RHBZ_READ_STR = (1<< 1),
>> @@ -97,7 +99,7 @@ xmlrpc_value *rhbz_get_member(const char *member, xmlrpc_value
*xml);
>>
>> int rhbz_array_size(xmlrpc_value *xml);
>>
>> -int rhbz_bug_id(xmlrpc_value *xml, const char *ver);
>> +int rhbz_bug_id(xmlrpc_value *xml, size_t ver);
>>
>> int rhbz_new_bug(struct abrt_xmlrpc *ax, problem_data_t *problem_data,
>> const char *release);
>> @@ -120,7 +122,7 @@ struct bug_info *rhbz_bug_info(struct abrt_xmlrpc *ax, int
bug_id);
>>
>> struct bug_info *rhbz_find_origin_bug_closed_duplicate(struct abrt_xmlrpc
*ax,
>> struct bug_info *bi);
>> -char *rhbz_version(struct abrt_xmlrpc *ax);
>> +size_t rhbz_version(struct abrt_xmlrpc *ax);
>>
>> #ifdef __cplusplus
>> }