#144 xcap_client fails to store the xcap document in the database

1.5.x
closed-fixed
modules (454)
9
2009-05-21
2009-05-14
genady
No

the xcap document fetched from the non integrated xcap server cannot be saved in the mysql database. The error messages are:

ERROR:db_mysql:db_mysql_val2str: destination buffer too short
ERROR:core:db_print_values: Error while converting value to string

I analysed the source code of xcap_functions.c xcapGetNewDoc and found out that instead of str structure, char* and string_val should be used.
This is due to fact, that in db_mysql/val.c db_mysql_val2str something goes wrong here:
if (*_len < (VAL_STR(_v).len * 2 + 3)) {
LM_ERR("destination buffer too short\n");
return -6;
...

This line caused bug:
query_vals[n_query_cols].val.str_val = user;

This solves the problem:
query_vals[n_query_cols].val.string_val = user.s;

This is also valid for the domain parameter passed to , here is the snippet of the working code, storing the data in the database:

/* insert in xcap table*/
query_cols[n_query_cols] = &str_username_col;
query_vals[n_query_cols].type = DB_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.string_val = user.s;
n_query_cols++;

query_cols[n_query_cols] = &str_domain_col;
query_vals[n_query_cols].type = DB_STR;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.string_val = domain.s;
n_query_cols++;

query_cols[n_query_cols] = &str_doc_col;
query_vals[n_query_cols].type = DB_BLOB;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.string_val= doc;
n_query_cols++;

query_cols[n_query_cols] = &str_doc_type_col;
query_vals[n_query_cols].type = DB_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val= req.doc_sel.doc_type;
n_query_cols++;

query_cols[n_query_cols] = &str_etag_col;
query_vals[n_query_cols].type = DB_STRING;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.string_val= etag;
n_query_cols++;

query_cols[n_query_cols] = &str_source_col;
query_vals[n_query_cols].type = DB_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val= XCAP_CL_MOD;
n_query_cols++;

query_cols[n_query_cols] = &str_doc_uri_col;
query_vals[n_query_cols].type = DB_STRING;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.string_val= path;
n_query_cols++;

query_cols[n_query_cols] = &str_port_col;
query_vals[n_query_cols].type = DB_INT;
query_vals[n_query_cols].nul = 0;
query_vals[n_query_cols].val.int_val= req.port;
n_query_cols++;

The 100% solution is to fix the db_mysql/val.c db_mysql_val2str for str type.

Regards, Genady

Discussion

  • genady

    genady - 2009-05-19
    • priority: 5 --> 9
    • assigned_to: nobody --> anca_vamanu
     
  • genady

    genady - 2009-05-19

    sorry, the BLOB handling should be done like this, since the BLOB value must be str instead of char*:

    query_cols[n_query_cols] = &str_doc_col;
    query_vals[n_query_cols].type = DB_BLOB;
    query_vals[n_query_cols].nul = 0;
    /* change start*/
    str str_doc={doc, strlen(doc)};
    query_vals[n_query_cols].val.str_val= str_doc;
    /* change end */
    n_query_cols++;

     
  • Anca Vamanu

    Anca Vamanu - 2009-05-19

    Hi Genady,

    Thanks for debugging the error and finding the solution. I will test myself and apply the changes to svn.

    regards,
    Anca

     
  • genady

    genady - 2009-05-20

    Anca, after a while I discovered that the existing branch code for query_cols and query_vals is valid except DB_BLOB. See my previous comment to this bug entry.

    Best regards,
    Genady

     
  • Anca Vamanu

    Anca Vamanu - 2009-05-21

    Hi Genady,

    I have fixed the code yesterday.
    The problem was indeed with the blob type, the module used a str structure for fetching and storing the results.
    Thank you for debugging this.

    regards,
    Anca

     
  • Anca Vamanu

    Anca Vamanu - 2009-05-21
    • status: open --> closed-fixed
     

Log in to post a comment.