Lines Matching refs:lr
69 ldap_ldif_record_done( LDIFRecord *lr )
74 if (lr->lr_ctrls != NULL) {
75 ldap_controls_free( lr->lr_ctrls );
77 if ( lr->lr_lm != NULL ) {
78 ber_memfree_x( lr->lr_lm, lr->lr_ctx );
80 if ( lr->lr_mops != NULL ) {
81 ber_memfree_x( lr->lr_mops, lr->lr_ctx );
83 for (i=lr->lr_lines-1; i>=0; i--)
84 if ( lr->lr_freeval[i] ) ber_memfree_x( lr->lr_vals[i].bv_val, lr->lr_ctx );
85 ber_memfree_x( lr->lr_btype, lr->lr_ctx );
87 memset( lr, 0, sizeof(LDIFRecord) );
100 * lr - holds the data to return
109 LDIFRecord *lr,
124 assert( lr != NULL );
126 memset( lr, 0, sizeof(LDIFRecord) );
127 lr->lr_ctx = ctx; /* save memory context for later */
140 lr->lr_lines = ldif_countlines( rbuf->bv_val );
141 lr->lr_btype = ber_memcalloc_x( 1, (lr->lr_lines+1)*2*sizeof(struct berval)+lr->lr_lines, ctx );
142 if ( !lr->lr_btype )
145 lr->lr_vals = lr->lr_btype+lr->lr_lines+1;
146 lr->lr_freeval = (char *)(lr->lr_vals+lr->lr_lines+1);
159 BER_BVZERO( lr->lr_btype+i );
160 lr->lr_freeval[i] = 0;
164 if ( ( rc = ldif_parse_line2( line, lr->lr_btype+i, lr->lr_vals+i, &freev ) ) < 0 ) {
170 lr->lr_freeval[i] = freev;
173 if ( linenum+i == 1 && BV_CASEMATCH( lr->lr_btype+i, &BV_VERSION )) {
179 if( lr->lr_vals[i].bv_len == 0 || lutil_atoi( &v, lr->lr_vals[i].bv_val) != 0 || v != 1 )
182 if ( lr->lr_vals[i].bv_len != version1.bv_len || strncmp( lr->lr_vals[i].bv_val, version1.bv_val, version1.bv_len ) != 0 )
186 errstr, lr->lr_vals[i].bv_val, linenum );
190 } else if ( BV_CASEMATCH( lr->lr_btype+i, &BV_DN )) {
191 lr->lr_dn = lr->lr_vals[i];
192 dn = lr->lr_dn.bv_val; /* primarily for logging */
205 lr->lr_lines = i+1;
207 if( lr->lr_lines == 0 ) {
212 if( version && lr->lr_lines == 1 ) {
222 if ( BV_CASEMATCH( lr->lr_btype+i, &BV_CONTROL )) {
225 rc = parse_ldif_control( lr->lr_vals+i, &pctrls );
233 if ( i>= lr->lr_lines ) {
237 errstr, lr->lr_btype[i-1].bv_val, linenum+i );
246 if ( BV_CASEMATCH( lr->lr_btype+i, &BV_CHANGETYPE )) {
248 for ( icnt = lr->lr_vals[i].bv_len; --icnt > 0; ) {
249 if ( !isspace( (unsigned char) lr->lr_vals[i].bv_val[icnt] ) ) {
254 if ( ++icnt != lr->lr_vals[i].bv_len ) {
259 errstr, BV_CHANGETYPE.bv_val, lr->lr_vals[i].bv_val, linenum+i, dn );
260 lr->lr_vals[i].bv_val[icnt] = '\0';
261 lr->lr_vals[i].bv_len = icnt;
265 errstr, BV_CHANGETYPE.bv_val, lr->lr_vals[i].bv_val, linenum+i, dn );
274 if ( !( BV_CASEMATCH( lr->lr_vals+i, &BV_ADDCT )) ) {
279 (int)lr->lr_vals[i].bv_len,
280 (const char *)lr->lr_vals[i].bv_val );
285 if ( BV_CASEMATCH( lr->lr_vals+i, &BV_MODIFYCT )) {
288 } else if ( BV_CASEMATCH( lr->lr_vals+i, &BV_ADDCT )) {
291 } else if ( BV_CASEMATCH( lr->lr_vals+i, &BV_MODRDNCT )
292 || BV_CASEMATCH( lr->lr_vals+i, &BV_MODDNCT )
293 || BV_CASEMATCH( lr->lr_vals+i, &BV_RENAMECT ))
296 if ( i >= lr->lr_lines )
298 if ( !BV_CASEMATCH( lr->lr_btype+i, &BV_NEWRDN )) {
301 errstr, BV_NEWRDN.bv_val, lr->lr_btype[i].bv_val, linenum+i, dn );
305 lr->lrop_newrdn = lr->lr_vals[i];
307 if ( i >= lr->lr_lines )
309 if ( !BV_CASEMATCH( lr->lr_btype+i, &BV_DELETEOLDRDN )) {
312 errstr, BV_DELETEOLDRDN.bv_val, lr->lr_btype[i].bv_val, linenum+i, dn );
316 lr->lrop_delold = ( lr->lr_vals[i].bv_val[0] == '0' ) ? 0 : 1;
318 if ( i < lr->lr_lines ) {
319 if ( !BV_CASEMATCH( lr->lr_btype+i, &BV_NEWSUP )) {
322 errstr, BV_NEWSUP.bv_val, lr->lr_btype[i].bv_val, linenum+i, dn );
326 lr->lrop_newsup = lr->lr_vals[i];
330 } else if ( BV_CASEMATCH( lr->lr_vals+i, &BV_DELETECT )) {
335 errstr, BV_CHANGETYPE.bv_val, lr->lr_vals[i].bv_val, linenum+i, dn );
358 if ( i < lr->lr_lines ) {
368 nmods = lr->lr_lines - i;
375 for (; i<lr->lr_lines; i++) {
376 for (j=i+1; j<lr->lr_lines; j++) {
377 if ( !lr->lr_btype[j].bv_val ) {
384 if ( BV_CASEMATCH( lr->lr_btype+i, lr->lr_btype+j )) {
388 bv = lr->lr_vals[j];
389 fv = lr->lr_freeval[j];
391 lr->lr_btype[k] = lr->lr_btype[k-1];
392 lr->lr_vals[k] = lr->lr_vals[k-1];
393 lr->lr_freeval[k] = lr->lr_freeval[k-1];
396 lr->lr_btype[k] = lr->lr_btype[i];
397 lr->lr_vals[k] = bv;
398 lr->lr_freeval[k] = fv;
408 lr->lr_lm = ber_memalloc_x( nmods * sizeof(LDAPMod) +
410 (lr->lr_lines + nmods - idn) * sizeof(struct berval *), ctx );
411 if ( lr->lr_lm == NULL ) {
416 pmods = (LDAPMod **)(lr->lr_lm+nmods);
422 for (i=idn; i<lr->lr_lines; i++) {
423 if ( BV_CASEMATCH( lr->lr_btype+i, &BV_DN )) {
427 errstr, lr->lr_btype[i].bv_val, linenum+i - 1, dn );
429 if ( !BV_CASEMATCH( lr->lr_btype+i, &bv )) {
431 bv = lr->lr_btype[i];
432 lr->lr_lm[j].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
433 lr->lr_lm[j].mod_type = bv.bv_val;
434 lr->lr_lm[j].mod_bvalues = bvl+k;
435 pmods[j] = lr->lr_lm+j;
438 bvl[k++] = lr->lr_vals+i;
445 lr->lr_mops = ber_memalloc_x( lr->lr_lines+1, ctx );
446 if ( lr->lr_mops == NULL ) {
451 lr->lr_mops[lr->lr_lines] = M_SEP;
453 lr->lr_mops[i-1] = M_SEP;
455 for ( ; i<lr->lr_lines; i++ ) {
459 for ( icnt = lr->lr_vals[i].bv_len; --icnt > 0; ) {
460 if ( !isspace( (unsigned char) lr->lr_vals[i].bv_val[icnt] ) ) break;
463 if ( ++icnt != lr->lr_vals[i].bv_len ) {
467 errstr, lr->lr_btype[i].bv_val, lr->lr_vals[i].bv_val,
469 lr->lr_vals[i].bv_val[icnt] = '\0';
470 lr->lr_vals[i].bv_len = icnt;
474 errstr, lr->lr_btype[i].bv_val, lr->lr_vals[i].bv_val,
483 if ( BV_CASEMATCH( lr->lr_btype+i, &BV_MODOPADD )) {
485 lr->lr_mops[i] = M_SEP;
487 } else if ( BV_CASEMATCH( lr->lr_btype+i, &BV_MODOPREPLACE )) {
494 lr->lr_mops[i] = modop | LDAP_MOD_BVALUES;
495 lr->lr_btype[i] = lr->lr_vals[i];
496 } else if ( BV_CASEMATCH( lr->lr_btype+i, &BV_MODOPDELETE )) {
498 lr->lr_mops[i] = modop | LDAP_MOD_BVALUES;
499 lr->lr_btype[i] = lr->lr_vals[i];
500 } else if ( BV_CASEMATCH( lr->lr_btype+i, &BV_MODOPINCREMENT )) {
502 lr->lr_mops[i] = M_SEP;
511 bv = lr->lr_vals[i];
512 } else if ( expect_sep && BER_BVISEMPTY( lr->lr_btype+i )) {
513 lr->lr_mops[i] = M_SEP;
518 if ( !BV_CASEMATCH( lr->lr_btype+i, &bv )) {
525 lr->lr_mops[i] = modop;
529 if ( (lr->lr_mops[i-1] & LDAP_MOD_BVALUES)
530 && BV_CASEMATCH( lr->lr_btype+i, lr->lr_btype+i-1 ))
532 lr->lr_mops[i-1] = M_SEP;
542 lr->lr_lm = ber_memalloc_x( nmods * sizeof(LDAPMod) +
544 (lr->lr_lines + nmods - idn) * sizeof(struct berval *), ctx );
545 if ( lr->lr_lm == NULL ) {
550 pmods = (LDAPMod **)(lr->lr_lm+nmods);
557 lr->lr_mops[idn-1] = M_SEP;
558 for (i=idn; i<lr->lr_lines; i++) {
559 if ( lr->lr_mops[i] == M_SEP )
561 if ( lr->lr_mops[i] != lr->lr_mops[i-1] || !BV_CASEMATCH( lr->lr_btype+i, &bv )) {
563 bv = lr->lr_btype[i];
564 lr->lr_lm[j].mod_op = lr->lr_mops[i] | LDAP_MOD_BVALUES;
565 lr->lr_lm[j].mod_type = bv.bv_val;
566 if ( lr->lr_mops[i] & LDAP_MOD_BVALUES ) {
567 lr->lr_lm[j].mod_bvalues = NULL;
569 lr->lr_lm[j].mod_bvalues = bvl+k;
571 pmods[j] = lr->lr_lm+j;
574 bvl[k++] = lr->lr_vals+i;
581 lr->lr_ctrls = pctrls;
584 lr->lr_op = LDAP_REQ_DELETE;
585 } else if ( lr->lrop_newrdn.bv_val != NULL ) {
586 lr->lr_op = LDAP_REQ_MODDN;
589 lr->lrop_mods = pmods;
591 lr->lr_op = LDAP_REQ_ADD;
593 lr->lr_op = LDAP_REQ_MODIFY;
599 ldap_ldif_record_done( lr );
612 LDIFRecord *lr,
616 return ldap_parse_ldif_record_x( rbuf, linenum, lr, errstr, flags, NULL );